想設計一個程式,打開串口的時候能顯示串口收到的資料,然后設定一個按鈕,點下按鈕后,創建一個TXT檔案,然后將資料保存進去。需要用的定時器嗎?
uj5u.com熱心網友回復:
// 讀取串口資料可以用定時器,或者另開執行緒。// 按下按鈕保存,把顯示的內容寫入txt就可。
uj5u.com熱心網友回復:
只是單存的單擊按鈕保存,那就更簡單,直接寫txt檔案。。如果是一直保存資料的話,那就類似寫日志那樣。。有資料就保存!!
uj5u.com熱心網友回復:
我現在的做法是,點擊按鈕,創建一個TXT,然后打開定時器進行資料保存,波特率9600,定時器設定10ms,每十個資料重復,這樣的話,基本目的達到了,可是每次定位GPS的時候都要等好久出資料,二樓的意思是讓我加一個EDIT標簽,然后把資料顯示在標簽里,點擊按鈕,就把標簽里的資料讀出來,這樣可以是可以,可是標簽以后要取消啊uj5u.com熱心網友回復:
例子
// 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 115200 needs 4096 and more
DWORD totalrecv;
CString txt;
switch(wParam)
{
case 0:// from CommWatchCTS()
SetCTSIcon();
SetEvent(m_hPostEventRead);// tell watcher that CommNotify has been done
break;
case 1:// 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 file
if (!m_bStart)
{ // only 1st
m_bStart=1;
InforOut("Receiving "+UpLoadFileName);
}
uldFile.Write(abIn,nLength);
}
}
uldFile.Close();
// get 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)
{
Animate();
// reset "time waiting"
m_Elapse.ResetContent();
m_Elapse.AddString("0 s");
}
// tell watcher that CommNotify has been done
SetEvent(m_hPostEventRead);
break;
}
}
uj5u.com熱心網友回復:
https://blog.csdn.net/cvbtvbwu/article/details/24694739,可以看一下這文章。為什么要定時器,有資料來直接寫檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/52895.html
標籤:基礎類
