1

Topic: Stream open detection?

I am using HIDSharp in an app that has to converse with multiple units. I found that opening a stream takes about 7ms or so. I haven't determined a way to check and see if a stream is already open though. Is there a method to do that?

Thanks for the dll by the way. Saved my bacon a few times.

2

Re: Stream open detection?

Hmm. For compatibility (and you _have_ to do this on windows 10) HidSharp doesn't prevent multiple streams to the same HID device.

I do have a newer (unreleased) version which implements its own exclusion mechanism. Would this be of use to you? It'd only work to prevent connections from other programs using HidSharp, and does not work on Linux yet (and the Mac exclusion mechanism is not entirely robust).

3

Re: Stream open detection?

I kind of like that HIDSharp doesn't prevent multiple streams. I have found that I can shave about 7-8ms off of an HID communication by leaving streams open , or only opening them once for multiple transactions. Sometimes I run into situations where it would be convenient to know if a particular HID has an open stream. I try to limit to one stream per HID, but the code gets fairly complex when I have to send large operations off into a background worker thread, while still allowing the user to manipulate unit's internal params via the UI.  Currently thinking of rewriting the app I have now and I was just curious.

It is an app that controls any number of little HID devices, all the same VID/PID and all pretty much identical.

When my app discovers a unit being attached, do you think it is OK to open a stream and leave it open for the duration of that unit's interaction with the app?

What did you mean about _have_ to do this with Windows 10?

Thank you for your reply!

4

Re: Stream open detection?

Windows sends all received input reports to every program that has the device open, so yes, it's safe to leave the stream open.

On Windows, if a file handle is already opened, you can still open it if the sharing you allow is as or less restrictive than the current sharing. Windows 10 itself opens HID devices with sharing enabled. So, there's no good way to implement exclusivity that is compatible with Windows 10, even if the library did allow it on other operating systems.

5

Re: Stream open detection?

OK . Thanks Zer. !

6

Re: Stream open detection?

If you would like a way to detect if a stream is already open, the HIDSharp 2.0 alpha I posted has an OpenOption.Exclusive that, when true, makes it possible for you to detect other instances which have set OpenOption.Exclusive. It's a HIDSharp-specific option, but you may find it useful to coordinate multiple processes or threads of your application.

7

Re: Stream open detection?

Sweet. Thanks! Any other improvements in the beta version?

8

Re: Stream open detection?

Yes. Quite a few, the changelog is up, though I forgot to mention the Changed event for device connect/disconnect.