为什么从串口中读到的汉字信息,不能在windows下显示?请帮我呀个位老大。
发送来的信息应是“v0600212c'\017'在在在在在“
可收到的却是“v0600212c|"
LRESULT CTerminalView::OnCommNotify(WPARAM wParam,LPARAM lParam)
{
char buf[MAXBLOCK/4];
// CPaintDC dc(this);
CString str;
int nLength,nTextLength;
CTerminalDoc* pDoc=GetDocument();
CEdit& edit=GetEditCtrl();
if(!pDoc->m_bConnected||(wParam & EV_RXCHAR)!=EV_RXCHAR)
{
SetEvent(pDoc->m_hPostMsgEvent);
return 0L;
}
nLength=pDoc->ReadComm(buf,100);
if(nLength)
{
nTextLength=edit.GetWindowTextLength();
edit.SetSel(nTextLength,nTextLength);
for(int i=0;i<nLength;i++)
{
switch(buf[i])
{
case '\r':
if(!pDoc->m_bNewLine)
break;
case '\n':
str+="\r\n";
break;
case '\b':
edit.SetSel(-1,0);
edit.ReplaceSel(str);
nTextLength=edit.GetWindowTextLength();
edit.SetSel(nTextLength-1,nTextLength);
edit.ReplaceSel("");
str="";
break;
case '\a':
MessageBeep((UINT)-1);
break;
case '\0x0E':
break;
case '\0x0F':
break;
default:
str+=buf[i];
}
}
edit.SetSel(-1,0);
edit.ReplaceSel(str);
// dc.TextOut(10,10,str,str.GetLength());
}
SetEvent(pDoc->m_hPostMsgEvent);
return 0L;
}