gpt4 book ai didi

c++ - 串行端口 : ReadFile and CloseHandle

转载 作者:行者123 更新时间:2023-11-28 02:57:21 33 4
gpt4 key购买 nike

<分区>

我想读取串行端口的传入数据并处理它们(Windows: native C++)。但是我有两个问题:

1- 我应该将什么作为 nNumberOfBytesToRead 放入 ReadFile :

ReadFile( hCom, buffer, nNumberOfBytesToRead, &read, NULL );

如果我输入 50 和 40 个字节,ReadFile 将不会返回。因为它还需要 10 个字节。如果我输入 1,我的应用程序将不会被优化。最好的数字是多少?我该怎么办?

2- 当我想退出我的应用程序时,如果没有数据通过串行端口,ReadFile 将被锁定而不返回。所以我无法使用 CloseHandle 正确关闭它。如何在串口等待数据时强制ReadFile返回?

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com