Is it possible to use winusb to communicate with m

2019-09-21 12:14发布

问题:

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.

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.

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...

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?

Here is the link to my code, https://drive.google.com/drive/folders/1qvcGwNLxzJ0oRrFZbtyZ7g0zCU0XUG1n?usp=sharing

回答1:

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.

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.