vc MFC串口通信接收到的字符串中提起字符为什么无效
bool CCommDlg::biaozhi=0;int Str2Hex(CString str,CByteArray &data);
char HexChar();
void CCommDlg::OnComm()
{
if(stop)return;
VARIANT m_input1;
COleSafeArray m_input2;
long length,i;
BYTE data[1024];
CString str;
if(m_Comm.GetCommEvent()==2) //接收缓冲区内有字符
{
m_input1=m_Comm.GetInput(); //读取缓冲区内的数据
m_input2=m_input1; //将VARIANT型变量转换为ColeSafeArray型变量
length=m_input2.GetOneDimSize();//确定数据长度
for(i=0;i<length;i++)
m_input2.GetElement(&i,data+i); //将数据转换为BYTE型数组
for(i=0;i<length;i++) //将数组转换为Cstring型变量
{
BYTE a=* (char *)(data+i);
if(m_hex.GetCheck())
str.Format("%X ",a);
else str.Format("%c",a);
m_ReceiveData+=str;
}
if(m_ReceiveData[0]=='7')//&&m_ReceiveData[length-1]==0xE
biaozhi=1;
else biaozhi=0;
}
UpdateData(FALSE);//更新编辑框内容
m_SendData="eb 90 eb 90 eb 90";
if(biaozhi)
{
if(m_hexsend.GetCheck())
{
CByteArray data;
int len=Str2Hex(m_SendData,data);
m_Comm.SetOutput(COleVariant(data));//发送数据
}
else m_Comm.SetOutput(COleVariant(m_SendData));//发送数据
biaozhi=0;
}
}
在次补充一下,就是当发现接收到的字符串中第一个字符如果为“7”,则自动回复"eb 90 eb 90 eb 90";
实际运行结果发现没有回复,请大侠指点!!!!!!!!!!!我对m_ReceiveData不是很熟悉!!!!!!
[ 本帖最后由 kxywnljz 于 2011-1-18 15:14 编辑 ]