Topic: HIDSharp: Cannot open datastream, TryOpen() always returns false?
Hello all,
I'm fairly new to working with HID, especially from the host side. I usually stick to microcontrollers but in this case I need to write an application to monitor the traffic from my microcontroller based HID devices for testing purposes.
I've dabbled in C# .NET so HIDSharp seems perfect for whipping something up quickly with WinForms. It's strange to me that MS doesn't just have libraries in .NET for this but that's not my problem today.
I'm working with HIDSharp v2.0.2.0 attempting to monitor traffic from a composite HID device. The composite device consists of a Keyboard with LEDs and a 3-Button mouse. Both are HID. Keyboard Codes on EP1, Mouse is on EP2. The device works with the standard windows HID Mouse and Keyboard drivers.
First things first, I want to have a look at the keyboard traffic, since I have a few weird custom scancodes I need to ensure are coming through correctly.
I am able to find the device based on the VID/PID and confirm based on the name if I am seeing the Keyboard:
HidDevice KeyboardDevice;
HidStream KeyboardStream;
HidSharp.Reports.ReportDescriptor KeyboardRptDescriptor;
HidSharp.Reports.Report KeyboardReport;
HidSharp.Reports.Input.HidDeviceInputReceiver InputReceiver;
OpenConfiguration KbdConnectCfg = new OpenConfiguration();
if (d.VendorID == 0x0000 && d.ProductID == 0xA0A0)
{
if (d.GetProductName() == "Keyboard")
{
KeyboardDevice = d;
KeyboardRptDescriptor =KeyboardDevice.GetReportDescriptor();
}
}
if (KeyboardDevice != null)
{
/*Device Found*/
if (KeyboardDevice.TryOpen(out KeyboardStream)) //This always returns false
{
KeyboardReport = KeyboardRptDescriptor.InputReports.FirstOrDefault();
keyboardBuffer = new byte[KeyboardDevice.GetMaxInputReportLength()];
InputParser = KeyboardReport.DeviceItem.CreateDeviceItemInputParser();
InputReceiver = KeyboardRptDescriptor.CreateHidDeviceInputReceiver();
InputReceiver.Start(KeyboardStream);
InputReceiver.Received -= new EventHandler(HidInputReceived);
InputReceiver.Received += new EventHandler(HidInputReceived);
}
else
{
rtb_hidLog.AppendText("Unable to open Datastream\r\n");
}
}
else
{
rtb_hidLog.AppendText("No Device Found\r\n");
}
The device is found with no problem and my KeyboardDevice object populates, but when I use TryOpen(), it always returns false and I don't get a datastream. Might someone be able to point out why this might be, or maybe how to get some more information to determine why I can't open the datastream to this device? The only thing I've really tried is opening the device with the Exclusive and Transient options set:
KbdConnectCfg.SetOption(OpenOption.Exclusive, true);
KbdConnectCfg.SetOption(OpenOption.Transient, true);
KeyboardDevice.TryOpen(KbdConnectCfg,out KeyboardStream)
but it appears to have no effect, I still cannot get the datastream.
I'm probably just missing something due to not really being familiar with HID from the host side. If there's any additional information I can provide that would be of help, let me know. Any thoughts are appreciated.
Thanks!