LONG CSifuDlg::OnComm(WPARAM ch, LPARAM port) //接收数据
{ int count=0; //设置计数
if(m_bConnect) //串口是否连接
{
m_RecBuff[1000] +=(BYTE)ch; //接收数据暂存
count++;
if(count=11)
{
if(m_RecBuff[0] = 0xAA) //判断是否为帧头
{
sifu1.m_bDistance=(UINT)(m_RecBuff[2]<<8)+(UINT)(m_RecBuff[1]);
sifu1.m_bAziUnderShoot=(UINT)(m_RecBuff[4]<<8)+(UINT)(m_RecBuff[3]);
sifu1.m_bHiloUnderShoot=(UINT)(m_RecBuff[6]<<8)+(UINT)(m_RecBuff[5]);
sifu1.m_bAziWatchAngel=(UINT)(m_RecBuff[8]<<8)+(UINT)(m_RecBuff[7]);
sifu1.m_bHiloWatchAngel=(UINT)(m_RecBuff[10]<<8)+(UINT)(m_RecBuff[9]); CString stra; //显示接收到的目标数据
stra.Format("%d",sifu1.m_bDistance);
m_cDistance.SetWindowText(stra);
CString strb;
strb.Format("%d",sifu1.m_bAziUnderShoot);
m_cAziUnderShoot.SetWindowText(strb);
CString strc;
strc.Format("%d",sifu1.m_bHiloUnderShoot);
m_cHiloUnderShoot.SetWindowText(strc);
CString strd;
strd.Format("%d",sifu1.m_bAziWatchAngel);
m_cAziWatchAngel.SetWindowText(strd);
CString stre;
stre.Format("%d",sifu1.m_bHiloWatchAngel);
m_cHiloWatchAngel.SetWindowText(stre);
}
}
}
UpdateData(FALSE);
return 0;
}
vc串口通信,这样做接收串口发过来的目标数据,目标数据是用双字节表示,先传低位后传高位;最后用十进制从界面显示出来.不知道能否实现,希望指点!BYTE str1,str2,str3;
void CSifuDlg::OnLocked() //锁定
{
// TODO: Add your control notification handler code here
if(m_cLocked)
{ str2=0x04;}
else
{ str2=0x00;}
}void CSifuDlg::OnManualfoci() //(手动调焦/自动)
{
// TODO: Add your control notification handler code here
if(m_cManualfoci)
{ str1=0x00;}
else
{ str1=0x03;}
}void CSifuDlg::OnAugment() //手动调焦增大焦距
{
// TODO: Add your control notification handler code here
if(m_cAugment)
{
str1=0x01;
m_SerialPort.SendBlock(&str1,1);
}
}void CSifuDlg::OnMinish() //手动调焦减小焦距
{
// TODO: Add your control notification handler code here
if(m_cMinish)
{
str1=0x10;
m_SerialPort.SendBlock(&str1,1);
}
}void CSifuDlg::OnTelemete() //测距
{
// TODO: Add your control notification handler code here
if(m_cTelemete)
{ str3=0x08;}
else
{ str3=0x00;}
}void CSifuDlg::OnSend() //发送数据
{
// TODO: Add your control notification handler code here
BYTE strdata;
strdata=str1|str2|str3;
if(!m_bConnect) return;
UpdateData(TRUE);
m_SerialPort.SendBlock(&strdata,1);
}
用串口类SerialPort做串口通讯,用一个字节发送数据,这样做以后,点发送按钮就假死机,等半天会弹出一个对话框,显示"某某指令引用的内存,不能为写"的应用程序错误。不知道怎么办,希望指点。还有如何实现调焦按钮连续增大焦距和减小焦距。
{ int count=0; //设置计数
if(m_bConnect) //串口是否连接
{
m_RecBuff[1000] +=(BYTE)ch; //接收数据暂存
count++;
if(count=11)
{
if(m_RecBuff[0] = 0xAA) //判断是否为帧头
{
sifu1.m_bDistance=(UINT)(m_RecBuff[2]<<8)+(UINT)(m_RecBuff[1]);
sifu1.m_bAziUnderShoot=(UINT)(m_RecBuff[4]<<8)+(UINT)(m_RecBuff[3]);
sifu1.m_bHiloUnderShoot=(UINT)(m_RecBuff[6]<<8)+(UINT)(m_RecBuff[5]);
sifu1.m_bAziWatchAngel=(UINT)(m_RecBuff[8]<<8)+(UINT)(m_RecBuff[7]);
sifu1.m_bHiloWatchAngel=(UINT)(m_RecBuff[10]<<8)+(UINT)(m_RecBuff[9]); CString stra; //显示接收到的目标数据
stra.Format("%d",sifu1.m_bDistance);
m_cDistance.SetWindowText(stra);
CString strb;
strb.Format("%d",sifu1.m_bAziUnderShoot);
m_cAziUnderShoot.SetWindowText(strb);
CString strc;
strc.Format("%d",sifu1.m_bHiloUnderShoot);
m_cHiloUnderShoot.SetWindowText(strc);
CString strd;
strd.Format("%d",sifu1.m_bAziWatchAngel);
m_cAziWatchAngel.SetWindowText(strd);
CString stre;
stre.Format("%d",sifu1.m_bHiloWatchAngel);
m_cHiloWatchAngel.SetWindowText(stre);
}
}
}
UpdateData(FALSE);
return 0;
}
vc串口通信,这样做接收串口发过来的目标数据,目标数据是用双字节表示,先传低位后传高位;最后用十进制从界面显示出来.不知道能否实现,希望指点!BYTE str1,str2,str3;
void CSifuDlg::OnLocked() //锁定
{
// TODO: Add your control notification handler code here
if(m_cLocked)
{ str2=0x04;}
else
{ str2=0x00;}
}void CSifuDlg::OnManualfoci() //(手动调焦/自动)
{
// TODO: Add your control notification handler code here
if(m_cManualfoci)
{ str1=0x00;}
else
{ str1=0x03;}
}void CSifuDlg::OnAugment() //手动调焦增大焦距
{
// TODO: Add your control notification handler code here
if(m_cAugment)
{
str1=0x01;
m_SerialPort.SendBlock(&str1,1);
}
}void CSifuDlg::OnMinish() //手动调焦减小焦距
{
// TODO: Add your control notification handler code here
if(m_cMinish)
{
str1=0x10;
m_SerialPort.SendBlock(&str1,1);
}
}void CSifuDlg::OnTelemete() //测距
{
// TODO: Add your control notification handler code here
if(m_cTelemete)
{ str3=0x08;}
else
{ str3=0x00;}
}void CSifuDlg::OnSend() //发送数据
{
// TODO: Add your control notification handler code here
BYTE strdata;
strdata=str1|str2|str3;
if(!m_bConnect) return;
UpdateData(TRUE);
m_SerialPort.SendBlock(&strdata,1);
}
用串口类SerialPort做串口通讯,用一个字节发送数据,这样做以后,点发送按钮就假死机,等半天会弹出一个对话框,显示"某某指令引用的内存,不能为写"的应用程序错误。不知道怎么办,希望指点。还有如何实现调焦按钮连续增大焦距和减小焦距。
我感觉还是直接用 WIN32 API 简单。
是不是少了个等号?