Home > Software engineering >  MFC how real time serial data to the TXT
MFC how real time serial data to the TXT

Time:09-19

Want to design a program to open the serial port to display a serial port receives the data, and then set a button, point, after the button to create a TXT file, and then to save the data in, need to use the timer?

CodePudding user response:

//read serial data can use timer, or the other threads,
//press the button to save, to write the contents of display TXT can,

CodePudding user response:

Just single left click the button to save, you are more simple, direct TXT file, written,

If the data is kept, that is similar to writing log, have data to save!!

CodePudding user response:

I now, click on the button, create a TXT, then open the timer data save, baud rate, 9600 timer set 10 ms, ten data repeat, so, to achieve the basic purpose, but every time when GPS positioning to wait out the data for a long time, on the second floor of the mean, let me add an EDIT TAB, and then to display the data in the label, click on the button, the label data in a read out, so that I can do that, but the label later to cancel

CodePudding user response:

Example
 
//use ON_MESSAGE (a, b)
Void CUload: : OnCommNotify (WPARAM WPARAM, LPARAM LPARAM)
{
//TODO: Add your specialized code here and/or call the base class
Int nLength;
BYTE abIn [6000].//for 4096 and 115200 needs more
DWORD totalrecv;
Cstrings TXT.
The switch (wParam)
{
Case 0://the from CommWatchCTS ()
SetCTSIcon ();
SetEvent (m_hPostEventRead);//tell watcher that CommNotify has had done
break;
Case 1://the from CommWatchRead ()
//append on each entry
CFile uldFile (UpLoadFileName CFile: : modeCreate | CFile: : modeNoTruncate | CFile: : modeWrite);
UldFile. SeekToEnd ();
If (m_bConnected)
{
If (nLength=ReadCommBlock (abIn, BUFLEN))//38400 needs 1024
{//save into the file
if (! M_bStart)
{//only 1 st
M_bStart=1;
InforOut (" identifiers "+ UpLoadFileName);
}
UldFile. Write (abIn, nLength);
}
}
UldFile. Close ();
//get the total bytes received
M_uldINs. GetText (0, TXT);
Totalrecv=atol (. TXT GetBuffer (40));
Totalrecv +=nLength;
TXT Format (" % d ", totalrecv);
M_uldINs. ResetContent ();
M_uldINs. AddString (TXT);
If (nLength> 128)
{
The Animate ();
//reset time "waiting"
M_Elapse. ResetContent ();
M_Elapse. AddString (" 0 s ");
}
//tell watcher that CommNotify has had done
SetEvent (m_hPostEventRead);
break;
}
}

CodePudding user response:

https://blog.csdn.net/cvbtvbwu/article/details/24694739, you can have a look at this article,

Why there are data to write directly to timers, file
  • Related