2 scg08 scg08 于 2013.07.03 11:40 提问

ReadFile读的串口数据最高位为0,求助

rt用ReadFile读的串口数据最高位不对。比如0x80,读成了00,0x81读成了01,但是小于0x80的数读出来都对。存储用unsigned char保存。代码如下
unsigned char inbuff[1024];
//memset(inbuff,0,4096);//sizeof(inbuff));
memset(inbuff,0,sizeof(inbuff));
DWORD dwError;
int nBytes;
COMSTAT comstat;
CSF103TESTDlg pthis=(CSF103TESTDlg)lpParam;
HWND hdwnd = pthis->m_hWnd;

while(pthis->hCom != INVALID_HANDLE_VALUE)
{
    ClearCommError(pthis->hCom,&dwError,&comstat);
    if(comstat.cbInQue>256) nBytes = 256;
    else nBytes = comstat.cbInQue;                  
    bReadStat = ReadFile(pthis->hCom,inbuff,nBytes,(unsigned long *)&nBytes,NULL);
    if(!bReadStat)
    {
        break;
    }

1个回答

oyljerry
oyljerry   Ds   Rxr 2015.01.03 11:37

先打印一接收到数据时的值是否正确,是不是后面做了类型转换

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!