为什么我在调试用API写的串口通信程序时,以文本形式发送能接收到,文本不能显示的接收不到呢?
例如:0x34能接收到,而0x11就接收不到。
例如:0x34能接收到,而0x11就接收不到。
解决方案 »
- ADO的recodeset对象打开出错
- Unhandle exception in test.exe :0xC0000005 access violation
- 在CComboBoxEx中如何实现文件目录的缩进显示?
- 如何将01001010 按位转换成一个字节啊?
- 在线请教:我是一个VC新手,想请教大家我为什么在VC开发环境里找不到drivelistbox and dirlistbox and filelistbox
- 深入浅出mfc 的问题!!
- VC当中资源脚本与资源模板的区别是什么?
- 写文件的问题
- 如何用vc编译vfp程序?
- 判断ini文件的key存在,在线等
- 入门问题:VC里如何调用数据结构的变量:如下,急,急,
- 500分:求vfw压缩、解压缩视频源码,或帮助,绝不食言!顶者有分 !
代码如下:void CMySerialComDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int Len;
char buffer[1024];
//buffer[Len]='\0';
Len=::ReadCommBlock(m_ComConfig,buffer,1024);
//buffer[Len]='\0';
if(Len!=0)
{
buffer[Len]='\0';
m_receive+=buffer;
UpdateData(FALSE);
}
CDialog::OnTimer(nIDEvent);
}
int ReadCommBlock(CComStatus& comDev,LPSTR lpszBlock, int nMaxLength )
{
BOOL fReadStat ; COMSTAT ComStat ;
DWORD dwErrorFlags;
DWORD dwLength;
DWORD dwError;
char szError[ 10 ] ; // only try to read number of bytes in queue
ClearCommError( comDev.m_hCom, &dwErrorFlags, &ComStat ) ;
dwLength = min( (DWORD) nMaxLength, ComStat.cbInQue ) ; if (dwLength > 0)
{
fReadStat = ReadFile( comDev.m_hCom, lpszBlock,
dwLength, &dwLength, &(comDev.m_rdos) ) ;
if(dwLength!=0)
dwLength=32;
if (!fReadStat)
{
if (GetLastError() == ERROR_IO_PENDING)
{
OutputDebugString("\n\rIO Pending");
// We have to wait for read to complete.
// This function will timeout according to the
// CommTimeOuts.ReadTotalTimeoutConstant variable
// Every time it times out, check for port errors
while(!GetOverlappedResult( comDev.m_hCom ,
&(comDev.m_rdos), &dwLength, TRUE ))
{
dwError = GetLastError();
if(dwError == ERROR_IO_INCOMPLETE)
// normal result if not finished
continue;
else
{
// an error occurred, try to recover
wsprintf( szError, "<CE-%u>", dwError ) ;
ClearCommError( comDev.m_hCom , &dwErrorFlags, &ComStat ) ;
break;
} } }
else
{
// some other error occurred
dwLength = 0 ;
ClearCommError( comDev.m_hCom , &dwErrorFlags, &ComStat ) ;
}
}
} return ( dwLength ) ;}