none
How do I get data from and send data too a USB port using VS 2010 and C# to call System.IO.Pipes? RRS feed

  • Question

  • I assume there is some class or method or some kind of library function I can call in order to get data from and send data too a USB port?  How do I do this.  I have looked at multiple books and all I see is read/write file streams and console read/write.  I see the namespace System.IO.Pipes and assume this is what you use, is there any examples.  prior threads asked the same question but there was no answers, for instance if you have a hardware demo board that enumerates as a mass storage device, I assume that you can access the data as files just using a directory path,  However, if the demo board enumerates as a HID (human interface device) and it just sends out serial characters, how do I attach to this stream?   the demo board is reading 8 analog to digital converters and converting the data into one string, and sends out the read values back to the PC 1 time a second, (or one time every 1/2 second) so I want to create a visual studio 2010 windows form that attaches to the stream, parses the data string into 8 separate channels and then displays each channels a to d converter value in a separate box on the form.  

    ADC1  12.85V            ADC2  3.45V           ADC3   0.12V             ADC4   1.25V
    ADC5    3.15V            ADC6  7.45V           ADC7   5.12V             ADC8   3.75V

    Monday, February 18, 2013 5:37 PM

Answers

  • See code project below.  There is complete source code.  The code uses the Product ID and Vendor ID of the device to locate the device.  USB devices can be plugged into any of the USB plugs on the computer and the COM number will change.  To make sure you connect to the right USB device you must enumerate through all the device until you find the port with the device you are looking for.

    http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=18099


    jdweng

    Monday, February 18, 2013 6:50 PM
  • The problem is with USB finding the correct port number for the device you are using.  If you were using COM1 it would be simple because you just plug you  RS-232 inrto the COM1 connector on the PC and you know it will always be Com1.  With USB you can plug into 10 different USB plugs on the computer and you have to go searching to find the device.  So most of the code in the example is needed just to figure out which port number is the device you are using.

    You only need the code that is used to find the product ID and Vendor ID.  Also you need the code to open the device.


    jdweng

    Monday, February 18, 2013 9:37 PM

All replies

  • See code project below.  There is complete source code.  The code uses the Product ID and Vendor ID of the device to locate the device.  USB devices can be plugged into any of the USB plugs on the computer and the COM number will change.  To make sure you connect to the right USB device you must enumerate through all the device until you find the port with the device you are looking for.

    http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=18099


    jdweng

    Monday, February 18, 2013 6:50 PM
  • thanks for the example, however me being a "VC C# beginner" it only brings up another 20 questions about the code on the example and what part do I need, vs. what gets built when you compile, vs. is it VS2010 compatible etc..   would I just need to use USBApp, or do I need to recreate every *.cs file into a project??  this is probably one of those things you just have to play around with and step through with the debugger to see how it works, etc...  nothing in this world is free right?  you have to put in the time, read the books, do the examples, etc.
    • Edited by jetro57070 Monday, February 18, 2013 8:44 PM
    Monday, February 18, 2013 7:50 PM
  • The problem is with USB finding the correct port number for the device you are using.  If you were using COM1 it would be simple because you just plug you  RS-232 inrto the COM1 connector on the PC and you know it will always be Com1.  With USB you can plug into 10 different USB plugs on the computer and you have to go searching to find the device.  So most of the code in the example is needed just to figure out which port number is the device you are using.

    You only need the code that is used to find the product ID and Vendor ID.  Also you need the code to open the device.


    jdweng

    Monday, February 18, 2013 9:37 PM