Reading HID cause app to become unresponsive.

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
Ive tried creating an app in C# to capture information from a custom USB device and things have been going well. Ive managed to use Mike OBriens HIDLibrary which works perfectly for what I need, however I think Ive done something stupid. The device
is contantly polled with a timer and it works fine, but the whole thing becomes unresponsive to user input (including exiting the application) until it recieves another report from the USB device.
I basically have this code set up in a timer:
<div style="color:Black;background-color:White; <pre>
HidDeviceData inData;
HidDevice[] hidDeviceList;
HidDevice myDevice;

hidDeviceList = HidDevices.Enumerate(0x1234, 0x0001);

<span style="color:Blue; if (hidDeviceList.Length > 0)
{
<span style="color:Blue; int waitTries;

myDevice = hidDeviceList[0];
waitTries = 0;

myDevice.Open();

<span style="color:Blue; while (!myDevice.IsConnected && waitTries < 10)
{
Thread.Sleep(10);
waitTries++;
}

<span style="color:Blue; if (myDevice.IsConnected)
{
inData = myDevice.Read();
<span style="color:Blue; if (inData.Data[2] == 0x1)
{
textBox1.Text += <span style="color:#A31515; "Button 1rn";
}
}
myDevice.Close();
myDevice.Dispose();
}
[/code]
Theres only one part to check for the button for testing purposes. I need to be able to solve the unresponsiveness issue before moving on. I can keep pressing Button 1 on my device and it captures most of the presses (again, losing data isnt something
I really want either).
If anyone can help out with this problem, Id be greatly appreciative. Thanks so much in advance!

View the full article
 
Back
Top