Home > Back-end >  A serial port communication mscomm control data frame drop
A serial port communication mscomm control data frame drop

Time:09-18

Hello, I recently made a serial port communication mscomm control, but can appear in the process of sending and receiving data frame drop phenomenon, from PC to a machine data, a data frame in receive a less than, my data is written in the modbus protocol, do you have any good advice?
Stick the sending data code
Void CGKtDlg: : OnReadregister (void)
{
BYTE buff [256].
Cstrings temp.
CByteArray arraySend;
Memset (buff, 0 x00, 255);
Sleep (100);
Buff [0]=0 x01;
Buff [1]=0 x03;
Buff [2]=0 x00;
Buff [3]=0 x0a;
Buff [4]=0 x00;
Buff [5]=0 x02;
USHORT CRC=MBCRC16 (buff (UCHAR *), 6);//CRC check
Buff [6]=(CHAR) (CRC & amp; 0 XFF);
Buff [7]=(CHAR) ((CRC & amp; 0 xff00) & gt;> 8);

ArraySend. RemoveAll ();
ArraySend. SetSize (8);
M_txd="";
for(int i=0; I<8; I++)
{
ArraySend. SetAt (I, buff [I]);
}
M_Comm. Put_Output (COleVariant (arraySend));
for(int i=0; I<8; I++)
{
BYTE bt=* (char *) (buff + I);
Temp. The Format (_T (" % 02 x "), bt);
M_txd +=temp;
}
M_txd +="\ r \ n";
Int LineNum=TXD. GetLineCount ();
If (LineNum<=14)
{
TXD. SetSel (1, 1);
TXD. ReplaceSel (m_txd);
}
The else
{
TXD. SetSel (0, 1);
TXD. The Clear ();
TXD. SetSel (1, 1);
TXD. ReplaceSel (m_txd);
}
}

CodePudding user response:

Install a CommMonitor, monitor it and see is not sent or received under a machine,

CodePudding user response:

Do you want a timeout value, more than this time, just think communication timeout,
It will receive points after a few times to receive, so, must be read in the stipulated time length, less than, you still have to continue to read,


CodePudding user response:

Mobus is a master-slave protocol to ensure that the bus only a node to send data at the same time,
  • Related