I have a custom ATMEL chip with firmware that uses LUFA for driving the USB. I can read and write output reports on Windows with existing software in .Net using PInvoke.
I now want to develop a cross platform desktop app with a shared codebase for communicating with my device.
I can successfully write output reports to the device on Mac using both HidApi in C++ as well as my preferred library HidSharp in C# via Mono.
However, I am unable to read HID reports. Both platforms give me a timeout when I call the equivalent .Read() method.
My relevant LUFA code looks like this:
bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
uint8_t* const reportId,
const uint8_t reportType,
void* reportData,
uint16_t* const reportSize)
{
if(reportType == HID_REPORT_ITEM_In && reportId != NULL && *reportId != 0) {
if(debug) {
serial_write_str_P(PSTR("USB IN Packet: "));
serial_write_uint8(reportId == NULL ? 0xff : *reportId, 10);
}
I am able to get into "USB IN Packet: " and read reports in .Net using something like this:
[DllImport("hid.dll", SetLastError = true)]
static extern Boolean HidD_GetInputReport(IntPtr hFileHandle, byte[] reportBuffer, uint reportBufferLength);
byte[] buffer = new byte[packetSize];
buffer[0] = MY_CONTROL_PACKET;
HidD_GetInputReport(_fileHandle.DangerousGetHandle(), buffer, (uint)buffer.Length)
On a Mac or PC using HidSharp or HidApi libraries I can never break into the "USB IN Packet:" line, and I get a timeout. My HidSharp code looks like this:
HidStream stream;
device.TryOpen(out stream);
using (stream) {
var bytes = new byte[37];
bytes[0] = MY_REPORT_ID;
stream.Read(bytes)
}
What am I doing wrong wrong in HidSharp? If HidSharp is broken how do I accomplish this in HidApi? If HidApi is broken what other options do I have?