求解用C++写COM串口通信的问题,缓冲区有数据但读不出来
如题,cbInQue,就是输入缓冲区字节数里的数字不断增加,但是调用ReadFile就是读不出来,ReadFile函数返回值总是0,一小段代码是bResultR=Clea...
如题,cbInQue,就是输入缓冲区字节数里的数字不断增加,但是调用ReadFile就是读不出来,ReadFile函数返回值总是0,一小段代码是
bResultR = ClearCommError(handle, &dwError, &comstat);
if ((comstat).cbInQue == 0)
continue;
if (bRead)
{
bResultR = ReadFile(handle, &RXBuff, 1, NULL, &m_ov);
//后面是错误处理不贴了
问题已解决,不用回答了 展开
bResultR = ClearCommError(handle, &dwError, &comstat);
if ((comstat).cbInQue == 0)
continue;
if (bRead)
{
bResultR = ReadFile(handle, &RXBuff, 1, NULL, &m_ov);
//后面是错误处理不贴了
问题已解决,不用回答了 展开
2个回答
2014-12-25
展开全部
请问如何解决的,我也遇到这个问题了。
补:
readfile第四个参数,msdn上解释为
OVERLAPPED structure
For an hFile that supports byte offsets, if you use this parameter you must specify a byte offset at which to start reading from the file or device. This offset is specified by setting the Offset and OffsetHighmembers of the OVERLAPPED structure. For an hFile that does not support byte offsets, Offset andOffsetHigh are ignored.
The calling process must set this member before passing the OVERLAPPED structure to functions that use an offset, such as the ReadFile or WriteFile (and related) functions.
根据我的经验,对于关闭Flow Control的文件,readfile第四个参数OVERLAPPED structure需要手动设置offset、OffsetHigh为0或其他需要的值,否则readfile正确返回,但读取长度为0,即读不出来数据
对于打开Flow Control的文件,似乎offset、OffsetHigh参数对readfile函数不是必须的
补:
readfile第四个参数,msdn上解释为
OVERLAPPED structure
For an hFile that supports byte offsets, if you use this parameter you must specify a byte offset at which to start reading from the file or device. This offset is specified by setting the Offset and OffsetHighmembers of the OVERLAPPED structure. For an hFile that does not support byte offsets, Offset andOffsetHigh are ignored.
The calling process must set this member before passing the OVERLAPPED structure to functions that use an offset, such as the ReadFile or WriteFile (and related) functions.
根据我的经验,对于关闭Flow Control的文件,readfile第四个参数OVERLAPPED structure需要手动设置offset、OffsetHigh为0或其他需要的值,否则readfile正确返回,但读取长度为0,即读不出来数据
对于打开Flow Control的文件,似乎offset、OffsetHigh参数对readfile函数不是必须的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-07-20
展开全部
看 龚建伟 的书 吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询