Home > Software engineering >  MFC programming, serial port reference jian-wei gong teacher, a serial port to accept for kernel dev
MFC programming, serial port reference jian-wei gong teacher, a serial port to accept for kernel dev

Time:10-14

Good BBS prawn, due to the project need, my side reference jian-wei gong teacher: SCOMMV2.3 serial debugging assistant, rewrite the serial debugging software; Baud rate is 115200, can receive normal development board of the kernel information, but there are time delay; After I give power development board, MFC serial interface in the kernel messages, didn't stop in a minute; Using CSerialPort class, write a serial port,
Masters help you see, some said to the calling thread processing, not familiar with this aspect knowledge, give some advice, thank you!
Receive serial data core code is as follows:

The static long rxdatacount=0;//this variable is used to receive the character count
LONG CSCOMMDlg: : OnCommunication (WPARAM ch, LPARAM port)//communication, message response
{//define variables: accept character ch and port port
If (port & lt;=0 | | port & gt; 11)//port on behalf of the serial number, value of 1 to 10
return -1;
Rxdatacount++;//receiving byte count
Cstrings strTemp;
StrTemp. The Format (" % ld, "rxdatacount);//output long integer receiving data count rxdatacount
StrTemp="RX:" + strTemp;
//m_ctrlRXCOUNT SetWindowText (strTemp);//reception counter

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))//open the program, choose the default automatic emptying
{
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 ();//data more than 400 lines, clear interface
M_ReceiveData="HTTP://https://bbs.csdn.net/topics/* * * The Length of The Text is too long, Emptied Automaticly!!! * * */r/n ";
The UpdateData (FALSE);
}

Cstrings STR.//the character into temporary variable STR store
STR. The Format (" % c ", ch);//character format for display

//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 ();//returns the length of the specified window title text characters
M_ctrlReceiveData. SetSel (nLen nLen);//in the edit control to select a range of characters
M_ctrlReceiveData. ReplaceSel (STR);
NLen +=STR. GetLength ();
M_ReceiveData +=STR;//store temporary variable STR characters, join the receiving box
return 0;

}

CodePudding user response:

Pay attention to clean up the receive buffer
  • Related