static long rxdatacount=0;//this variable is used to receive the character countthen I through OnCommunication, from a serial port receives a hexadecimal data (data exist m_ReceiveData)
LONG CSCOMMDlg: : OnCommunication (WPARAM ch, LPARAM port)
{
If (port & lt;=0 | | port & gt; 16)
return -1;
Rxdatacount++;//receiving byte count
Cstrings strTemp;
StrTemp. The Format (" % ld, "rxdatacount);
StrTemp="RX:" + strTemp;
//byte RecevieData [1000].
//unsigned short int I;
If (m_bStopDispRXData)//if you select the "stop showing" receiving data, it returns
return -1;//note that in this case, the count continues, just don't show
//set up a "empty" automatically, if, after reaching 50 lines, automatic emptying the receive in the edit box shows the data
If ((m_ctrlAutoClear GetCheck ()) & amp; & (m_ctrlReceiveData GetLineCount () & gt;=50))
{
M_ReceiveData. Empty ();
The UpdateData (FALSE);
}
//if there is no "automatic emptying", after data line 400, also automatic emptying
//because of too much data, impact speed, display is the most CPU time consuming operation
If (m_ctrlReceiveData GetLineCount () & gt; 400)
{
M_ReceiveData. Empty ();
M_ReceiveData="HTTP://https://bbs.csdn.net/topics/* * * The Length of The Text is too long, Emptied Automaticly!!! * * */r/n ";
The UpdateData (FALSE);
}
//if you choose the "hexadecimal display", displays hexadecimal values
Cstrings STR.
If (m_ctrlHexReceieve GetCheck ())
STR. The Format (" % 02 x ", ch);
The else
STR. The Format (" % c ", ch);
//here is will receive added at the end of the string of characters, it takes a lot of
//but considering the data needs to be saved into a file, so did not use the List Control
Int nLen=m_ctrlReceiveData. GetWindowTextLength ();
M_ctrlReceiveData. SetSel (nLen nLen);
M_ctrlReceiveData. ReplaceSel (STR);
NLen +=STR. GetLength ();
M_ReceiveData +=STR;
return0;
03 01 0 c 1 a E0 09 C4 03 E8 01 00 00 00 32 90 E7 A6
Then I will take out one of the four 1 ae0 converted to decimal ph, 09 c4 converted to decimal represent temperature values, I want to how to implement
CodePudding user response:
The model byte array can be used to save the received data;Such as byte RecvData [512]; Then remove the corresponding data
CodePudding user response:
Can be directly mids, then strol, can be converted directly, if consider decimal plus or minus, also need to judge the high!CodePudding user response:
The building Lord your problem solved? To ask!CodePudding user response:
The building Lord, won't receive Chinese characters! Such as in the receiving port to send "hello" on the other side is like this:Ch=196
STR=?