Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

c++ - Is it possible to use winusb to communicate with multiple identical usb devices simultaneously?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...