I'm trying to learn how to use USB for general two way communications with a generic HID device.
For the device I have selected the Atmel ATxmega256A3BU on a demo board which includes an LCD, buttons, and LEDs.
For the host application I'm using Jan's 'generic_hid_cs_60' (Visual C#).
I have modified the code for PC and device to support two basic features --
⦁ When a button on the windows form is clicked, an OUT report is sent to endpoint 2 with 64 bytes of character data (obtained from a new text box on the form). When received, the text is displayed on the device's LCD.
⦁ When a button on the device is pressed, a different text string is written to the device endpoint 1 buffer. Then when the 'Get Input Report' (by interrupt) button on the form is clicked, the received text string is written to a listbox (new listbox, not LstResults) on the form.
Both of these features are working, but I don't want to have to click a button on the form in order to get the message to display in the listbox.
In an attempt to fix this, I made changes to the application code - 1) changed the readTimeout value from 5000 to -1 (no timeout). 2) After receiving the IN report, I call the method to initiate another IN report. This way the host is always sending IN tokens, and when the device writes to the IN buffer, the data is transferred immediately. This makes the second feature work as intended.
Of course this creates a different problem, the OUT report (first feature) can never occur because it is blocked by the _transferInProgress flag.
Question: is there a way to make both these features work as intended? For instance, can the Get IN Report be canceled so the Get OUT Report can be sent?
I did see the following on the HID FAQ page, and it might relate to my problem, but I don't really understand the answer. Could someone clarify? Is there example code?
" How can I find out if a report is available without hanging my application?
Use overlapped ReadFile with a short timeout or use ReadFileEx to signal when a report is available. In .NET, you can do asynchronous ReadFile calls with a delegate and BeginInvoke and EndInvoke methods. "
Any help will be greatly appreciated.