This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Port Windows USB API to C#?

Guru 15580 points


Could we talk you guys into porting the Windows USB API to C#, or create a callable .dll that we could reference in C#?

  • This is more of a general Windows USB programming issue than anything MSP430 specific, since the same USB host program can be used to communicate with an MSP430F55xx, a Stellaris, or a C5xxx if they all implement the same application protocol and the program recognizes their VID/PIDs.

    There are library wrappers that interface various Windows USB APIs with C# (and other .Net managed code). Here are some resources to get you started:

    http://code.google.com/p/winusbnet/

    http://libusbdotnet.sourceforge.net/V2/Index.html

    http://www.ti.com/litv/pdf/slaa453

    Tony

  • Tony,

    Thanks for the references, but I was under the impression that the TI HID "datapipe" (which is what I want to implement) required a special form of communication from the PC-app. The excerpts below, taken from the API Programmer Guide,  are what I am referring to. Please let me know if I am mistaken.

    • HID-Datapipe Interface: HID interfaces in this API can either be datapipe or traditional.
    Datapipe eases the creation of general-purpose applications over HID. A defining feature is
    its usage of the API’s default report descriptor, which defines a report with a “size/data” field
    format. The distinction between datapipe and traditional is made only by which function calls
    the application uses to access the HID interface.

    ...and 

    The HID datapipe function calls implement an unformatted datastream, just like the CDC calls.
    It defines a very simple report, consisting of a size byte and a large data field. At the level of the
    MSP430 application, there’s essentially no difference in how the CDC and HID-Datapipe calls
    operate. The call sets are identical, except for their prefix (USBCDC_ vs. USBHID_). Programs
    written for one can be quickly migrated to the other. The engineer who learns one of these APIs
    already knows the other.


    The datapipe calls are not an industry standard protocol, but rather something created by TI.
    However, this type of approach is commonly used among USB engineers.

  • Hi Mike,

    What the TI document is trying to say is that there's no "distinction" between the HID datapipe and "traditional" modes. That is, they are both recognized as HID devices on the host, and they both send out HID packets. The API functions they refer to are the MSP430 device side API for sending and receiving from the host.

    In the USB standard, when an HID device enumerates, the host asks what types of "reports" (HID packets) the device can send and receive; so when "traditional" devices like keyboards and mice enumerate they tell the host they are keyboards and mice. When this happens, the host will use the builtin drivers for these traditional devices since the format of their "reports" are well defined.

    However if you have a custom HID device, the host would not know how to deal with the custom report formats; this is where libraries like WinUSB and libUSB come in, they provide you with a way to handle the custom HID reports.

    Actually there is an HID specific library that you may be interested in: http://www.signal11.us/oss/hidapi/

    Hope I cleared things up for you. :)

    Tony

  • Tony,

    Yes. Very clear. Thanks. I'll take a look at these other libraries you've pointed out. The Signal11 looks encouraging.

  • I'm just about to look at doing something similar. Did you make any progress that might save me some time?

  • Fred,

    I gave up. But you would be the hero of many people here if you can make it happen!! 

    Keep us posted if you do give it a try. 

  • I spent a couple of hours last night with very little success. I can see the HID device and connect, but can't send a report to it.

    If I get something working then I'll definitely post it here, but I may just go with a fallback of using a CDC serial port instead.

  • Fred,

    My apologies. I mis-read your original post. I thought you were referring to a C# port of the BSL, which I had previously given up on.

    However, I am able to communicate with the MSP430 API using Jan Axleson's Generic HID for C# v4.6 (http://www.lvr.com/hidpage.htm). One of the key technical gotcha's is to use report type=63 (outputReportBuffer[0]=63). Otherwise the TI API will not recognize the transaction.

    Good luck!!

  • Thanks. I thought it'd be something like that, as I could send messages but they were being ignored. I must admit that time pressures meant I gave up and went with CDC serial instead of HID.

**Attention** This is a public forum