Home > Software engineering >  Turn the MFC storage serial data in real time
Turn the MFC storage serial data in real time

Time:09-20

A serial port is responsible for one dimensional data, think taken every once in a while, and saved to the real time. TXT file, I myself to write the program in a tutorial, but found that can build files, but only a set of data, a great god help

CodePudding user response:

Do you want any time save time it is? So every point, you can create a new file, delete the original, so only a pack of, you should determine whether you file exists, the first is created, any appended at the end of the file,

Not point time save time should use the circular manner, or open a timer, every once in a while to save time,

CodePudding user response:

CFile: : modeWrite means writing files, CFile: : modeCreate mean to create a new file,

CodePudding user response:

CFile: : modeCreate | CFile: : modeNoTruncate
don't reset the lengthSeekToEnd to write again at the end of the

CodePudding user response:

3/f truth!!!!!!

CodePudding user response:

The
reference 3 floor zgl7903 response:
CFile: : modeCreate | CFile: : modeNoTruncate
don't reset the lengthSeekToEnd to the end and then write
thank you, newbie on the road, or old driver??

CodePudding user response:

refer to the second floor tiger bobo response:
CFile: : modeWrite mean writing files, CFile: : modeCreate mean to create a new file,
hello, problems have been solved, can be saved, but now I like call subroutine calls a serial port, collect data, and save, did not know how to write, ask Daniel for help??????

CodePudding user response:

Reference:
 
//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);//CListBox m_uldINs;
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);//volatile HANDLE m_hPostEventRead;
break;
}
}

///////////////////////////////////////////////////////
Int CUload: : ReadCommBlock (BYTE * pBlock, int nBlockLen)
{//return 0 if the error
Int WaitErr;
BOOL fReadStart;
The COMSTAT COMSTAT;
DWORD dwErrorFlags, dwLength;

if (! M_bConnected) return 0;

If (ClearCommError (m_idComDev, & amp; DwErrorFlags, & amp; ComStat))
{//ComStat filled
If (dwErrorFlags)
{
If (dwErrorFlags & amp; CE_RXOVER) AfxMessageBox (" the Receive Queue overflow ");
Else if (dwErrorFlags & amp; CE_OVERRUN) AfxMessageBox (" the Receive Overrun Error ");
Else if (dwErrorFlags & amp; CE_RXPARITY) AfxMessageBox (" the Receive Parity Error ");
Else if (dwErrorFlags & amp; CE_FRAME) AfxMessageBox (" the Receive Framing error ");
Else if (dwErrorFlags & amp; CE_BREAK) AfxMessageBox (" Break Detected ");
The else AfxMessageBox (" CE_OTHERS ");
}
}
//nBlockLen may & gt; ,=, & lt; ComStat cbInQue!
DwLength=min ((DWORD) nBlockLen, ComStat. CbInQue);
If (dwLength> 0)
{//read the required
FReadStart=ReadFile (m_idComDev pBlock, dwLength, & amp; DwLength, & amp; M_osRead);
if(! FReadStart)
{//if there was a problem, or the async. The operation 's still pending...
If (GetLastError ()==ERROR_IO_PENDING)
{//asynchronous I/o is still in progress
If (WaitErr=WaitForSingleObject (m_osRead hEvent, 60000))//1 minute
{//time over
If (WaitErr==WAIT_TIMEOUT)
{//time out
DwLength=0;
AfxMessageBox (" Time out!" );
}//end time out
}//end waiterr
}//end io_pending
The else
{//WaitErr=0. An SetEvent (m_osRead. HEvent) anywhere else
The GetOverlappedResult (m_idComDev, & amp; M_osRead, & amp; DwLength, FALSE);
M_osRead. Offset +=dwLength;
}
}
}//end if dwLength> 0
Return dwLength;
}

  • Related