是否可以使用 winusb 同时与多个相同的 USB 设备通信? [英] Is it possible to use winusb to communicate with multiple identical usb devices simultaneously?

查看:70
本文介绍了是否可以使用 winusb 同时与多个相同的 USB 设备通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用多个相同的设备,我希望能够同时读取它们.因此,所有设备的产品和供应商 ID 都相同.我想知道我是否能够并行读取它们.

I am using multiple identical devices and i would like to be able to read from them simultaneously. So the Product and Vendor ID are the same for all devices. I am wondering if i will be able to read from them in parallel.

在我看来,我认为这应该是可能的,因为对于特定的设备路径,您会创建一个唯一的 winusb 句柄以及一个唯一的 createfile 句柄.

In my opinion i would think that it should be possible because for specific device path, you create a unique winusb handle as well as a unique createfile handle.

但是在实践中,我意识到它不起作用.我没有使用重叠结构,因为由于独特的 createfile 句柄,它们是完全分开的.从设备读取的数据不是并行读取的,它只是读取第一个设备,第二个,第三个等等......

However in practice, i realized that it didn't work. I didn't use overlapped structure as i though they were completely separate due to unique createfile handles. The data read from the devices isn't read in parallel, instead it just reads the first device, second, third etc...

我用 C++ 编写了代码,希望得到一些建议,谢谢.
使用重叠结构会解决问题吗?还是 winusb 不应该这样使用?

I wrote the code in c++ and i would like some advice, thank you.
Would using overlapped structure fix the problem? Or is winusb not meant to be used this way?

这是我的代码的链接,https://drive.google.com/drive/folders/1qvcGwNLxzJ0oRrFZbtyZUG=10g分享

推荐答案

是的,您可以使用 WinUSB 并行连接两个不同的 USB 设备,无论它们是否相同.您将使用两个不同的路径调用 CreateFile 两次.要真正获得并行性,您需要使用重叠 I/O 或使用多个线程.

Yes, you can use WinUSB to talk to two different USB devices in parallel, whether or not they are identical. You would call CreateFile twice with two different paths. To actually get parallelism, you would either need to use overlapped I/O or use multiple threads.

overlapped I/O 的一点是,你可以非常快速地从一个线程启动多个请求,操作系统会并行处理它们,你可以稍后查询它们是否已经完成.

The point of overlapped I/O is that you can start multiple requests very quickly from a single thread, and the operating system will work on them in parallel, and you can later query to see whether they have been completed.

这篇关于是否可以使用 winusb 同时与多个相同的 USB 设备通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆