Home > Software engineering >  MFC serial interface, reference jian-wei gong teacher to rewrite, accept the kernel development boar
MFC serial interface, reference jian-wei gong teacher to rewrite, accept the kernel development boar

Time:10-14

Dear BBS friends, everybody is good, sincerely seek help!
My side is needed for the project, reference jian-wei gong teacher SCOMMV2.3 serial debugging assistant, rewrite a serial debugging, need to development board, baud rate set 115200; Rewrite the serial interface, and accept data delay; Even to the development board, when the power is still a period of time to stop accepting data, rather than stop immediately, such delay phenomenon, I do not easily through the design of serial interface, press any key to enter uboot system for further development of operation,
This software is combined with the project design, the delay phenomenon for 1 week, website useful thread processing, but not familiar with, please help to give directions,
Serial port receive data core code is as follows, using CSerialPort class to write a serial port, help to analysis the where there is a problem, thank you:

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);//comment, the window does not accept the data
NLen +=STR. GetLength ();
M_ReceiveData +=STR;//store temporary variable STR characters, join the receiving box

return 0;

}

CodePudding user response:

Data suggest not words news, the efficiency is very low, batch reading and processing as far as possible; If use message mechanism, and also recommend block transmission way
Such as OnComm (BYTE * pDataBuff, int iBuffBytesLen, int iPort)

CodePudding user response:

Well, 115200 baud rate, receiving 4418 motherboard kernel information output, some of the large amount of data; Analysis found that the MFC window display of serial interface data delay, slower than the received data, cannot achieve data display and receiving synchronization, so it's not convenient to operate a serial port interface into the uboot for further development, such as secureCRT serial port, there is no delay, easy to operate; But my serial interface for the project, need to add other additional functions, kernel information display is just one part of a need to design,
Separate serial data reception and display processing, using a thread on how to handle, can give some reference code or any hints, thank you!
A serial port initialization code is as follows:

BOOL CSCOMMDlg: : OnInitDialog ()//initializes the Settings
{
//CDialog: : OnInitDialog ();
//BOOL b=CDialog: : OnInitDialog (0, fdAll, true);
BOOL b=CDialog: : OnInitDialog ();
//Add "About... "Menu item to system menu.

//IDM_ABOUTBOX must be in the system command range.
ASSERT ((IDM_ABOUTBOX & amp; 0==IDM_ABOUTBOX xfff0));
ASSERT (IDM_ABOUTBOX & lt; 0 xf000);

CMenu * pSysMenu=GetSystemMenu (FALSE);
If (pSysMenu!=NULL)
{
Cstrings strAboutMenu;
StrAboutMenu. LoadString (IDS_ABOUTBOX);
if (! StrAboutMenu. IsEmpty ())
{
PSysMenu - & gt; The AppendMenu (MF_SEPARATOR);
PSysMenu - & gt; AppendMenu (MF_STRING IDM_ABOUTBOX, strAboutMenu);
}
}

//Set the icon for this dialog. The framework does this automatically
//when the application 's main window is not a dialog
SetIcon (m_hIcon, TRUE);//Set the big icon
SetIcon (m_hIcon, FALSE);//Set the small icon

//TODO: Add extra initialization here

//CurSel, namely the current selection, the current options
M_Com. SetCurSel (0);//a serial port to choose the first, is the com1
M_Speed. SetCurSel (11);//baud rate case for 11 corresponds to 115200
M_Parity. SetCurSel (0);//check digit choose
M_DataBits. SetCurSel (0);//data bits select
M_StopBits. SetCurSel (0);//stop bit choose

M_hIconRed=AfxGetApp () - & gt; LoadIcon (IDI_ICON_RED);
M_hIconOff=AfxGetApp () - & gt; LoadIcon (IDI_ICON_OFF);
M_hIconGreen=AfxGetApp () - & gt; LoadIcon (IDI_ICON_GREEN);

//m_ctrlIconDatareceive SetIcon (m_hIconOff);

//to the serial port variable initialization
M_nBaud=115200;//set the baud rate
M_nCom=1;//set port
M_cParity='N'.
M_nDatabits=8;
M_nStopbits=1;
M_dwCommEvents=EV_RXFLAG | EV_RXCHAR;//serial events
//if (m_Port. InitPort (this, 1, 9600, 'N', 8, 1, dwCommEvents, 512))
Cstrings strStatus;
//if (), if a serial port success
If (m_Port. InitPort (this, m_nCom, m_nBaud, m_cParity, m_nDatabits, m_nStopbits, m_dwCommEvents, 1024))
{
M_Port. StartMonitoring ();//start monitoring auxiliary thread
//print a serial port state and the parameter
StrStatus. The Format (" the OPENED COM % d, % d, % c, % d, % d ", m_nCom, m_nBaud, m_cParity, m_nDatabits, m_nStopbits);
M_ctrlIconOpenoff. SetIcon (m_hIconRed);

//m_ctrlIconOpenoff SetIcon (m_hIconOff);
//"current status: a serial port is opened, and white parity, 8 data bits, 1 stop bit");
}
If the else//boot failure
{
AfxMessageBox (" didn't find the serial port ");
M_ctrlIconOpenoff. SetIcon (m_hIconOff);
}
M_ctrlPortStatus. SetWindowText (strStatus);//display strStatus characters: COM % d the OPENED,

CEdit * pEdit=(CEdit *) GetDlgItem (IDC_EDIT_CYCLETIME);//IDC_EDIT_CYCLETIME to automatically send cycle control
Cstrings strText;
StrText. The Format (" % d ", m_nCycleTime);//m_nCycleTime for 1000 ms
PEdit - & gt; SetWindowText (strText);//Display cycle time

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related