15,980
社区成员




LONG CgroundcontrolstationView::OnCommunication(WPARAM ch, LPARAM port)
{
if(m_strReceive.IsEmpty ())
{
if(ch != ReceiveDataHead)
return 0;
}
int iLengthPos = 36;//长度在接收字节中的位置
int imultiple = 2;//取数据的倍数
UINT iAddSpace =2;//取余
CString str =_T("");
str.Format("%02X",ch);//str这个变量数据以十六进制的格式输出
if(m_strReceive.GetLength () == 0)
iEffectiveLen=0;
if(iEffectiveLen == 0)
m_strReceive+=str;
else
{
m_strReceive+=str;
iEffectiveLen--;
}
if(iEffectiveLen==0 && m_strReceive.GetLength ()> (iLengthPos + imultiple))
{//待一行数据(20字节)接收完毕后在处理
CString str =m_strReceive;
m_strReceive.Empty();
for(int i=0;i<str.GetLength();i++)
{
CString strTemp;
strTemp.Format("%c",str.GetAt(i));//CString 对象里的第i字符串,把它的ASCII 值送返回来
if((i+1)%iAddSpace==0)
strTemp+=" ";
m_strReceive+=strTemp;
}
ParseReceiveData(m_strReceive);//自定义函数检验头部和校验码
}
return 0;
}