To send data correlation function is as follows:
CommSendCnt=0;
PParent - & gt; M_comm. BSendBuff [commSendCnt + +]=(BYTE) (0 x01);
PParent - & gt; M_comm. BSendBuff [commSendCnt + +]=(BYTE) (0 x04);
PParent - & gt; M_comm. BSendBuff [commSendCnt + +]=(BYTE) (0 x00);
PParent - & gt; M_comm. BSendBuff [commSendCnt + +]=(BYTE) (0 x00);
PParent - & gt; M_comm. BSendBuff [commSendCnt + +]=(BYTE) (0 x00);
PParent - & gt; M_comm. BSendBuff [commSendCnt + +]=(BYTE) (0 x16);
PParent - & gt; M_comm. BSendBuff [commSendCnt + 0]=(BYTE) (check. CRC16 (BYTE (*) (& amp; PParent - & gt; M_comm. BSendBuff [0]), commSendCnt) & gt;> 8);
PParent - & gt; M_comm. BSendBuff [commSendCnt + 1)=(BYTE) (check. CRC16 (BYTE (*) (& amp; PParent - & gt; M_comm. BSendBuff [0]), commSendCnt));
PParent - & gt; M_comm. WriteComm (commSendCnt + 2);
Sleep (150);
Int commReadCnt=pParent - & gt; M_comm. ReadComm ();
If (commReadCnt==0)
{
MessageBox (_T (" no return data! "), _T (" communication tips "), MB_OK);
return 0;
}
Int CSComm: : WriteComm (int sendCnt)
{
DWORD dwErrorFlags ReaSendCnt;
The COMSTAT COMSTAT;
BOOL sendSta;
PurgeComm (m_hCom PURGE_TXCLEAR);
PurgeComm (m_hCom PURGE_RXCLEAR);
ClearCommError (m_hCom, & amp; DwErrorFlags, & amp; The ComStat);
SendSta=WriteFile (m_hCom, bSendBuff sendCnt, & amp; ReaSendCnt, NULL);
if(! SendSta)
{
return FALSE;
}
return TRUE;
}
CodePudding user response:
There is an open source MFC serial debugging tools, you can consult,https://gitee.com/kerndev/SerialTool
CodePudding user response:
The serial port spontaneous from closed to test your feet together and see what baud rate is the sameCodePudding user response:
SetCommState how to do?CodePudding user response:
Data contains 0 way using hexadecimal view so the receiving end