1

Topic: HIDSharp - adding event

Dear All,
I am kind of newbie in programming, thus I want to ask you (advanced programmers) if there is any way (and if it is please point it out) to add an event which can be fired by this library when new data is available on particular USB device (maybe via DeviceLoader class).
For example: my hardware is sending data only when I press a button, and I do not want to directly pool for the button status on the PC application constantly.
I would like to have OnNewUSBDataAvailable event to which I can attach functions.

Is it possible to archive this ? and if yes, then how should this be implemneted? Guidance will be really appreciated.

Many thanks in advance and best regards,
Grzegorz

2

Re: HIDSharp - adding event

The underlying system APIs all issue read commands. The canonical way to do this is to set the timeout to Timeout.Infinite (or some other large value), and to use BeginRead.

With BeginRead, you can either
(1) monitor the IAsyncResult to check for completion, and call EndRead on completion, or,
(2) use the callback in BeginRead to call EndRead and then queue the data for your application, using BeginInvoke for instance.