关于ReadFile读串口的疑问

时刻准备中 2011-04-28 02:36:19
在打开串口的时候使用SetupComm(_hPort,512,512);将串口的缓冲区设置为512字节,但不理解为什么用ReadFile(_hPort, outBuffer, dwToReadLen, &dwReadLen, NULL)读取串口数据时,dwReadLen的值会大于512?(dwReadLen使用前初始化为0)。
求高手解答
...全文
355 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
QQ515311445 2011-05-18
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 liu103bing 的回复:]

SetupComm在WINCE驱动下面是没有实现的,没什么作用。
[/Quote]
正解!
henrypiao 2011-05-14
  • 打赏
  • 举报
回复
SetupComm在WINCE驱动下面是没有实现的,没什么作用。
nackli 2011-05-14
  • 打赏
  • 举报
回复
SetupComm在WINCE中是没有任何作用的,只是一个空的调用,在ReadFile中,你可以限制读取的数据大小的吧,我记得
当我遇上-你 2011-05-03
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 xiaosan5871 的回复:]
ReadFile()是微软封装之后,传给wince驱动的。这个dwReadLen,并不是你驱动里边的length。

这个参数是不是驱动传递过来的,是ReadFile()自己用来返回给客户的。
[/Quote]
正解
BossJ2011 2011-05-03
  • 打赏
  • 举报
回复
使用clearcommerr不是能得到现在缓冲区里有多少个字符吗?
贝隆 2011-05-03
  • 打赏
  • 举报
回复
xiaosan5871 2011-05-03
  • 打赏
  • 举报
回复
ReadFile()是微软封装之后,传给wince驱动的。这个dwReadLen,并不是你驱动里边的length。

这个参数是不是驱动传递过来的,是ReadFile()自己用来返回给客户的。
mz_zhang 2011-05-01
  • 打赏
  • 举报
回复
dwToReadLen设置它 不就能 决定你最多读多少 了?
yf882 2011-04-30
  • 打赏
  • 举报
回复
好像是申请的堆空间,无限大
wxf54318 2011-04-29
  • 打赏
  • 举报
回复
官方文档说
BOOL SetupComm(
HANDLE hFile,
DWORD dwInQueue,
DWORD dwOutQueue
);
dwInQueue
[in] Specifies the recommended size, in bytes, of the device's internal input buffer.

dwOutQueue
[in] Specifies the recommended size, in bytes, of the device's internal output buffer.
The dwInQueue and dwOutQueue parameters specify the recommended sizes for the internal buffers used by the driver for the specified device
也就是和设备底层驱动有关的输入输出缓冲区
和readfile的缓冲区是不一样的
时刻准备中 2011-04-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wxf54318 的回复:]
官方文档说
BOOL SetupComm(
HANDLE hFile,
DWORD dwInQueue,
DWORD dwOutQueue
);
dwInQueue
[in] Specifies the recommended size, in bytes, of the device's internal input buffer.

dwOutQueue
[……
[/Quote]

那readfile的缓冲区默认是多大?有设置的方法吗?
当我遇上-你 2011-04-28
  • 打赏
  • 举报
回复
http://download.csdn.net/source/3114525
看看我的测试实例
sunrain_hjb 2011-04-28
  • 打赏
  • 举报
回复
dwReadLen的上限是dwToReadLen,跟SetupComm设置的值没有任何关系。
实际上在WinCE系统中,SetupComm好似没什么作用的。

19,519

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧