C# and USB HID Devices

老子叫甜甜 提交于 2019-11-26 12:12:22

问题


I\'m looking for one of either 2 things

1 - A working example of code using Florian\'s library from: http://www.florian-leitner.de/index.php/2007/08/03/hid-usb-driver-library/

This seems to be one of the better (only???) C#/HID libraries but the author has gone MIA and I can\'t seem to get a code example to work. The code I have is:

{
    USBHIDDRIVER.USBInterface usb = new USBInterface(myvid,mypid);
    if (usb.Connect())
        MessageBox.Show(”connection!”);
    else
        MessageBox.Show(”FAIL”);

    usb.enableUsbBufferEvent(new System.EventHandler(myEventCacher));
    usb.startRead();
}

private void myEventCacher(object sender, EventArgs e)
{
    string content = e.ToString();
    MessageBox.Show(content);
}

The connection part works but the event proc is never fired. So I\'d like to know if anyone has a working example of this library code with the event handler firing.

2 - If there is a better library for handling C#/HID interaction I\'d like to hear about it.


回答1:


The library you mention is now hosted on google see http://code.google.com/p/csharp-usb-hid-driver/

Perhaps these are helpful too:

  • https://github.com/mikeobrien/HidLibrary
  • http://www.usbhidnetclass.com/ (commercial) (usbhidnetclass.org previously)
  • http://www.codeproject.com/KB/cs/USB_HID.aspx
  • http://janaxelson.com/hidpage.htm
  • http://www.codeproject.com/KB/system/HIDAche.aspx?q=C%23+and+USB+HID+Devices
  • http://www.codeproject.com/Tips/530836/Csharp-USB-HID-Interface



回答2:


In Florian's project, take a look at TestFixture.cs. It's his unit test, but in it you'll see an example use of his code. You'll need to send a command to your device before you'll receive a message back.

I would recommend http://www.codeproject.com/KB/cs/USB_HID.aspx from the links above. I also had trouble with Florian's driver. The Code Project driver worked for me. If you use the Code Project driver there are small modifications which you need to make if you are using a Windows 7 x64 project. They are hidden in the page's comment section.



来源:https://stackoverflow.com/questions/7164055/c-sharp-and-usb-hid-devices

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!