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,