none
how to access usb port in C# and VB.NET

    Question

  • can any one tell me how to access a usb port in c# and vb.net. actually i am trying to send and receive a character from usb port.

    please tell me the code for the above mentioned problem.

    thanks

    Saturday, June 19, 2010 5:40 PM

Answers

  • Hi zedge123,

    You can't access USB devices (or any other device) directly from user mode applications in windows, this is done by the Device driver. The software that came with the device includes a Device driver, a COM library and a VB sample. The VB sample uses the interface exposed by the COM library, if you want to build new (with extended functionality) applications using C#, you have to import the typelibrary to access the same COM object from managed code, However, if you meant that the functionality offered by the library is rather limitted, you will have to call Device driver API directly from C++ or C#(using Pinvoke), but it's obvious you will need the API's documentation.

    A good start for USB in C# is this website.

    Hope them help too:
    http://weblogs.asp.net/israelio/archive/2005/08/15/422637.aspx
    http://bytes.com/topic/net/answers/637380-read-write-usb-port-using-c

    Sincerely,
    Helen Zhou


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by Helen Zhou Friday, June 25, 2010 3:23 AM
    Wednesday, June 23, 2010 9:53 AM

All replies

  • Usb is not a port like the serial port where you can send / recieve byes, its a bus that allows multiple devices to be on all talking in a different protocol, so there is no generic 'send/recieve byte' , communicating with usb devices is usually done though the vendor supplied driver and you'll have to contact the vendor to get additional programmin information.  What device are you trying to communicate with?

    Saturday, June 19, 2010 6:33 PM
  • hi Zedge

    what i get till now that you are using usb port and then u have some device like microcontroller or like that you want to communicate with them ?

    or you are having flash drive and you want to write something on it ?


    if the post helpful please mark it right else feel free to correct me
    Saturday, June 19, 2010 11:12 PM
  • Hi zedge123,

    You can't access USB devices (or any other device) directly from user mode applications in windows, this is done by the Device driver. The software that came with the device includes a Device driver, a COM library and a VB sample. The VB sample uses the interface exposed by the COM library, if you want to build new (with extended functionality) applications using C#, you have to import the typelibrary to access the same COM object from managed code, However, if you meant that the functionality offered by the library is rather limitted, you will have to call Device driver API directly from C++ or C#(using Pinvoke), but it's obvious you will need the API's documentation.

    A good start for USB in C# is this website.

    Hope them help too:
    http://weblogs.asp.net/israelio/archive/2005/08/15/422637.aspx
    http://bytes.com/topic/net/answers/637380-read-write-usb-port-using-c

    Sincerely,
    Helen Zhou


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by Helen Zhou Friday, June 25, 2010 3:23 AM
    Wednesday, June 23, 2010 9:53 AM
  • Is there an easy way to access usb devices? Because, I only want to access an usb flash drive and write on it.

    Greetings

    Wednesday, November 03, 2010 10:32 PM
  • Flash drives will just show up as any other drive and no special code is needed to access them.
    Wednesday, November 03, 2010 11:23 PM