MFC串口调试工具无法发送数据,欢迎大神指点。
自己写的串口工具,使用虚拟串口调试时是可以接受和发送的。但是实际使用两个真实的COM口调试时能接受不能发送。发送出来的只有两三个字节。程序如下
发送数据相关函数如下:
commSendCnt = 0;
pParent->m_comm.bSendBuff[commSendCnt ++] = (BYTE)(0x01);
pParent->m_comm.bSendBuff[commSendCnt ++] = (BYTE)(0x04);
pParent->m_comm.bSendBuff[commSendCnt ++] = (BYTE)(0x00);
pParent->m_comm.bSendBuff[commSendCnt ++] = (BYTE)(0x00);
pParent->m_comm.bSendBuff[commSendCnt ++] = (BYTE)(0x00);
pParent->m_comm.bSendBuff[commSendCnt ++] = (BYTE)(0x16);
pParent->m_comm.bSendBuff[commSendCnt + 0] = (BYTE)(check.CRC16((BYTE *)(&pParent->m_comm.bSendBuff[0]),commSendCnt) >> 8);
pParent->m_comm.bSendBuff[commSendCnt + 1] = (BYTE)(check.CRC16((BYTE *)(&pParent->m_comm.bSendBuff[0]),commSendCnt));
pParent->m_comm.WriteComm(commSendCnt + 2);
Sleep(150);
int commReadCnt = pParent->m_comm.readComm();
if(commReadCnt == 0)
{
MessageBox(_T("无返回数据! "),_T("通讯提示"),MB_OK);
return 0;
}
int CSComm::WriteComm(int sendCnt)
{
DWORD dwErrorFlags,ReaSendCnt;
COMSTAT ComStat;
BOOL sendSta;
PurgeComm(m_hCom,PURGE_TXCLEAR);
PurgeComm(m_hCom,PURGE_RXCLEAR);
ClearCommError(m_hCom,&dwErrorFlags,&ComStat);
sendSta = WriteFile(m_hCom,bSendBuff,sendCnt,&ReaSendCnt,NULL);
if(!sendSta)
{
return FALSE;
}
return TRUE;
}