Author Topic: simple way to send raw HID data via c#  (Read 11894 times)

ulao

  • Frequent Contributor
  • ****
  • Posts: 172
simple way to send raw HID data via c#
« 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.
« Last Edit: June 15, 2017, 11:24:16 am by ulao »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: simple way to send raw HID data via c#
« Reply #1 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.

ulao

  • Frequent Contributor
  • ****
  • Posts: 172
Re: simple way to send raw HID data via c#
« Reply #2 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.
« Last Edit: June 15, 2017, 10:29:17 pm by ulao »

ulao

  • Frequent Contributor
  • ****
  • Posts: 172
Re: simple way to send raw HID data via c#
« Reply #3 on: June 17, 2017, 06:09:47 pm »
I decided to try the HIDInterface project and that worked out just fine.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: simple way to send raw HID data via c#
« Reply #4 on: June 19, 2017, 10:08:54 pm »
Thanks for reporting what worked for you!