WinUSB: multiple programs + multiple handles

I’ve searched the forum for “winusb multiple” and read
about 10 pages of results with no definite answer so far.
I apologize in advance if the answer is obvious.

“WinUSB does not support multiple concurrent applications.”

To me the above caveat means, “Two or more programs cannot
access the same USB device.” Great. I don’t need that.

But what about separate programs each accessing a separate
USB device? Can WinUSB support two or more copies of my
software running on the same PC provided that each copy
controls a different USB device? Each software copy uses a
unique device handle. Can WinUSB “crosstalk” data between
devices? Does each unique device handle keep things separate?

My USB devices all have the same VID/PID, and therefore,
the same GUID. However, I can read a unique serial-number
from an EEProm inside each device and keep them organized.
Program copy #1 will load serial# 1234 while copy #2 loads
serial# 4567.

Unfortunately, my experiments indicate crosstalk between
driver handles may occur. My devices work fine provided
only one software copy uses USB bandwidth. In other words,
the secondary copies must sit idle while the first copy
transfers data across USB. If two programs try to control
two devices at the same moment, the data becomes
fouled for at least one program, sometime both. Of
course, there is no shared memory between programs.

I suspect this is a timing issue with my data acquisition
hardware. However, I wanted to Ask Some Experts about
WinUSB before starting a tedious chase on the hardware side.

Many thanks!

Brian

Brian_Bledsoe wrote:

“WinUSB does not support multiple concurrent applications.”

To me the above caveat means, “Two or more programs cannot
access the same USB device.” Great. I don’t need that.
But what about separate programs each accessing a separate
USB device? Can WinUSB support two or more copies of my
software running on the same PC provided that each copy
controls a different USB device?

Absolutely.  The restriction is that you can only open one file handle
to a given WinUSB instance.  If you have two devices, that means you
have two instances that are totally unrelated.

Can WinUSB “crosstalk” data between devices?

Could it?  Yes.  Does it?  No.  With a properly designed device driver,
instances are totally separate.

Does each unique device handle keep things separate?

Yes.

Unfortunately, my experiments indicate crosstalk between
driver handles may occur. My devices work fine provided
only one software copy uses USB bandwidth. In other words,
the secondary copies must sit idle while the first copy
transfers data across USB. If two programs try to control
two devices at the same moment, the data becomes
fouled for at least one program, sometime both. Of
course, there is no shared memory between programs.

Well, remember that there is still only one bus.  If you have two
devices connected to the same bus, they ARE going to share bandwidth. 
In a USB 2 bus, there’s less than 60MB/s available. If your device needs
to transmit 40MB/s, then you’re only going to be able to run one at a
time.  If you run two, they’ll get throttled.  What is your data rate? 
How much buffering do you have on the device?  Are you using bulk?

Even when the bus is jam-packed busy, the system is certainly able to
keep the packets separated.

I suspect this is a timing issue with my data acquisition
hardware. However, I wanted to Ask Some Experts about
WinUSB before starting a tedious chase on the hardware side.

Depends.  If your FIFOs overflow because you can’t get bandwidth, that
can certainly cause corruption.

Modern systems have multiple usb HCs. If you are saturating the bus on one HC with your device, plug your second device into a separate usb HC. WinUSB state is entirely within the device instance, if you are seeing cross talk it is happening at a lower layer.

d

Bent from my phone


From: Tim_Roberts
Sent: Wednesday, December 12, 2018 4:51:39 PM
To: Doron Holan
Subject: Re: [NTDEV] WinUSB: multiple programs + multiple handles

OSR https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Fosr.vanillacommunities.com%2F&data=02|01|doron.holan%40microsoft.com|52d055896083461caff108d660952511|72f988bf86f141af91ab2d7cd011db47|1|0|636802591022218515&sdata=y27JHCoUe9PbhKCUxRhIe15rza0Sx2K2jJzFpizeM3I%3D&reserved=0
Tim_Roberts commented on WinUSB: multiple programs + multiple handles

Brian_Bledsoe wrote:
> “WinUSB does not support multiple concurrent applications.”
>
> To me the above caveat means, “Two or more programs cannot
> access the same USB device.” Great. I don’t need that.
> But what about separate programs each accessing a separate
> USB device? Can WinUSB support two or more copies of my
> software running on the same PC provided that each copy
> controls a different USB device?

Absolutely. The restriction is that you can only open one file handle
to a given WinUSB instance. If you have two devices, that means you
have two instances that are totally unrelated.

> Can WinUSB “crosstalk” data between devices?

Could it? Yes. Does it? No. With a properly designed device driver,
instances are totally separate.

> Does each unique device handle keep things separate?

Yes.

> Unfortunately, my experiments indicate crosstalk between
> driver handles may occur. My devices work fine provided
> only one software copy uses USB bandwidth. In other words,
> the secondary copies must sit idle while the first copy
> transfers data across USB. If two programs try to control
> two devices at the same moment, the data becomes
> fouled for at least one program, sometime both. Of
> course, there is no shared memory between programs.

Well, remember that there is still only one bus. If you have two
devices connected to the same bus, they ARE going to share bandwidth.
In a USB 2 bus, there’s less than 60MB/s available. If your device needs
to transmit 40MB/s, then you’re only going to be able to run one at a
time. If you run two, they’ll get throttled. What is your data rate?
How much buffering do you have on the device? Are you using bulk?

Even when the bus is jam-packed busy, the system is certainly able to
keep the packets separated.

> I suspect this is a timing issue with my data acquisition
> hardware. However, I wanted to Ask Some Experts about
> WinUSB before starting a tedious chase on the hardware side.

Depends. If your FIFOs overflow because you can’t get bandwidth, that
can certainly cause corruption.

Thanks for the fast and thoughtful replies! I was very
doubtful the WinUSB would mix-up data between two
or more devices. So I’ll dive into the hardware side.
I already suspect the issue is timing.

What is your data rate? How much buffering do you
have on the device? Are you using bulk?

We get full USB 2.bulk 0 speeds with a decent host.
I use bulk and I can’t believe a slower data rate would
matter since the device works fine under USB 1.1.

If your FIFOs overflow because you can’t get
bandwidth, that can certainly cause corruption.

The data being sent back to the host was stored in
onboard memory. This isn’t my area, but I think the
DDR memory controller is governed by the Cypress
FIFO via the Cypress “GPIF” interface. It won’t refill
the FIFO until the GPIF says it’s okay.

Anyway, thanks again!