PORTS Forum

Ports and Interfaces => USB => Topic started by: ulao on June 15, 2017, 09:41:02 am

Title: simple way to send raw HID data via c#
Post by: ulao on June 15, 2017, 09:41:02 am
I have made a few c++ applications using usb.dll but I need make this work on a c# project. There are quite a few projects out there as there is no native way to do this, or so I gather. Every library I use has an error.

example 1: https://forum.zer7.com/topic/10094/
example 2: https://github.com/MightyDevices/MightyHID/issues/5

I see Jan wrote some software but looks rather robust and not sure what was used there. Does anyone have a simple example of how they made c# or other .net apps talk to a HID device? Just looking for a reference or class that will allow write and read.

--update, I was just working with a pickit3 device I have here and made the connection it also uses HID for communication. Then it occurred to me I have the pickit3 source code. I see how they do it in usb.cs. They just use a dllinpirt of usb.dll. A search brings me here.
https://github.com/temach/HIDInterface

Looks easy enough, ill try this next.
Title: Re: simple way to send raw HID data via c#
Post by: Jan Axelson on June 15, 2017, 12:25:53 pm
In my example code at

http://www.janaxelson.com/hidpage.htm#MyExampleCode

hid.cs has the HID-specific code. See the readme for details.

Scroll to the bottom of the same web page for several alternatives.
Title: Re: simple way to send raw HID data via c#
Post by: ulao on June 15, 2017, 10:26:13 pm
I have made some great success implementing this in my code. I'm getting errors on my test code. I'm guessing this will make sense to you but if you need to see my class let me know.

in SendOutputReportViaInterruptTransfer at the catch I get

IO operation will not work. Most likely the file will become too long or the handle was not opened to support synchronous IO operations."

I'm sure I just missed something. I did removed the cts from the call signs following the fileStreamDeviceData because I don't have the windows you did nor do I really know how to use cts. I'm assuming since the constructor allows without that's ok.
Title: Re: simple way to send raw HID data via c#
Post by: ulao on June 17, 2017, 06:09:47 pm
I decided to try the HIDInterface project and that worked out just fine.
Title: Re: simple way to send raw HID data via c#
Post by: Jan Axelson on June 19, 2017, 10:08:54 pm
Thanks for reporting what worked for you!