Receiving part of the program source program in
LONG CSCOMMDlg: : OnCommunication (WPARAM ch, LPARAM port)
{
Rxdatacount++;//receiving byte count
StrTemp. The Format (" % ld, "rxdatacount);///the character into temporary variables strTemp store
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))
{
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;
return 0;
}
Save the data part of the function of
Void CSCOMMDlg: : OnButtonSavedata ()
{
//TODO: Add your the control notification handler code here
The UpdateData (TRUE);
Int nLength;
NLength=m_strCurPath. GetLength ();//////m_strCurPath is a data file path
For (int nCount=0; NCount & lt; NLength; NCount++)
{
If (m_strCurPath GetAt (nCount)=='\ \')
CreateDirectory (m_strCurPath. Left (nCount + 1), NULL);
}
CreateDirectory (m_strCurPath, NULL);
CFile m_rFile;
LPCSTR lpszPath=m_strCurPath;//"c: \ \ comdata";
SetCurrentDirectory (lpszPath);
//file named Rec * *. TXT, the following code automatically detect file exists, if present, indicates that the serial number behind auto-increment
//such as Rec00. TXT Rec01. TXT, the program automatically to was about to save the file named Rec02. TXT.
Char buf [20].
for(int j=0; j<100; J++)
{
Sprintf (buf, "Rec % 02 d. TXT", j);
If ((access (buf, 0))==1)
break;
}
if(! M_rFile. Open (buf, CFile: : modeCreate | CFile: : modeWrite))
{
AfxMessageBox (" failed to create log files!" );
return;
}
If ((access (buf, 0))==1)
{
AfxMessageBox (" failed ");
return;
}
CTime t=CTime: : GetCurrentTime ();
Cstrings STR=t.F ormat (" % d % % m Y year month day when H % m % % S second \ r \ n ");
M_rFile. Write (LPCTSTR STR, STR., GetLength ());
M_rFile. Write ((LPCTSTR) m_ReceiveData, m_ReceiveData GetLength ());////////the m_ReceiveData
M_rFile. Flush ();
M_rFile. Close ();
STR="OK,";
for(int i=0; i<5; I++)
STR +=buf [I];
STR +=". TXT saved ";
M_ctrlSavePath. SetWindowText (STR);
The SetTimer (2500, NULL);//save the file in timer state
}
CodePudding user response:
A serial port is very simple, write a serial port communication tools, receiving data preservationCodePudding user response:
Strcpy (buf, "recv. TXT",);if(! M_rFile. Open (buf, CFile: : modeCreate | CFile: : modeWrite | CFile: : modeNoTruncate))
{
AfxMessageBox (" failed to create log files!" );
return;
}
CodePudding user response:
http://blog.csdn.net/cvbtvbwu/article/details/24694739Look at the examples, can change had not
CodePudding user response:
I also encountered this problem, the original poster is how to solve???????CodePudding user response:
You said friends, are also in the BBS?CodePudding user response:
Must be in memory cache, receiving and display is not the same level, could you receive the 500 k, just shows the 200 k,