我在程序中是一旦缓冲区里面有数据,马上读取数据,并立即显示数据。而我的真实目的是大概1秒读取并显示一次,这样可以编辑框中对数据看的比较清楚。
如何解决啊?
一下是我读取并显示数据的函数,希望指点!!
LONG CMeasureDlg::OnRecvSerialData(WPARAM wParam,LPARAM lParam)
{
CString strOldRecv = L"";
CString strRecv = L"";
//串口接收到的BUF
CHAR *pBuf = (CHAR*)wParam;
//串口接收到的BUF长度
DWORD dwBufLen = lParam;
//接收框
CEdit *pEdtRecvMsg = (CEdit*)GetDlgItem(IDC_EDT_RECV);
ASSERT(pEdtRecvMsg != NULL); //得到接收框中的历史文本
//pEdtRecvMsg->GetWindowTextW(strOldRecv);
strRecv = CString(pBuf);
//将新接收到的文本添加到接收框中
//strOldRecv = strOldRecv +L"\r\n"+ strRecv;
//strOldRecv = strRecv;
pEdtRecvMsg->SetWindowTextW(strRecv); ////////////////////////////////////
char * buf =NULL; //定义发送缓冲区 buf = new char[strOldRecv.GetLength()*2+1];
ZeroMemory(buf,strOldRecv.GetLength()*2+1);
WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,strOldRecv.GetBuffer(strOldRecv.GetLength())
,strOldRecv.GetLength(),buf,strOldRecv.GetLength()*2,NULL,NULL); char* stopstring;
char* string=NULL;
string=buf;
double x;
x= strtod(string, &stopstring ); //释放内存
delete[] pBuf;
pBuf = NULL;
delete[] buf;
buf = NULL;
return 0;
}
如何解决啊?
一下是我读取并显示数据的函数,希望指点!!
LONG CMeasureDlg::OnRecvSerialData(WPARAM wParam,LPARAM lParam)
{
CString strOldRecv = L"";
CString strRecv = L"";
//串口接收到的BUF
CHAR *pBuf = (CHAR*)wParam;
//串口接收到的BUF长度
DWORD dwBufLen = lParam;
//接收框
CEdit *pEdtRecvMsg = (CEdit*)GetDlgItem(IDC_EDT_RECV);
ASSERT(pEdtRecvMsg != NULL); //得到接收框中的历史文本
//pEdtRecvMsg->GetWindowTextW(strOldRecv);
strRecv = CString(pBuf);
//将新接收到的文本添加到接收框中
//strOldRecv = strOldRecv +L"\r\n"+ strRecv;
//strOldRecv = strRecv;
pEdtRecvMsg->SetWindowTextW(strRecv); ////////////////////////////////////
char * buf =NULL; //定义发送缓冲区 buf = new char[strOldRecv.GetLength()*2+1];
ZeroMemory(buf,strOldRecv.GetLength()*2+1);
WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,strOldRecv.GetBuffer(strOldRecv.GetLength())
,strOldRecv.GetLength(),buf,strOldRecv.GetLength()*2,NULL,NULL); char* stopstring;
char* string=NULL;
string=buf;
double x;
x= strtod(string, &stopstring ); //释放内存
delete[] pBuf;
pBuf = NULL;
delete[] buf;
buf = NULL;
return 0;
}
解决方案 »
- 请问怎么办?cout<<pszCurDir<<"\n";cout让它输出字串,它把指针的地址给输出来了!
- 动态创建的无模式对话框是否会导致资源泄露?
- skinmagic2.21的问题?
- VC中用ADO连数据库问题??
- 有经验的进,作为一个程序员有必要考硕吗?
- 改变控件位置的错误,急,在线等
- ActiveX控件接收IE地址栏地址的问题,解决立即给分
- 怎么考个证!?
- 哪位大虾现在手头上有BCGControlBar Library (v. 5.81)翻译过的中文资料??
- 有没有人做个高速公路应急资源管理系统啊!!!
- 谁能帮我下载一个东东 http://download.csdn.net/source/1840993
- 如何关闭一个CTabCtrl控件中所有对话框
只管赋值, 然后开个OnTimer,SetTimer(); 在里面UpdataData(FALSE);
在OnRecvSerialData添加OnTimer,SetTimer()后,函数无法进入OnTimer呀
{
AfxBeginThread(YourThread, this);
SetTimer();
}CMeasureDlg::OnTimer()
{
UpdateData(FALSE);
}write YourThread, receive your data in this function, and save it to this->YourString
你连接消息映射了么