locked
USB read write RRS feed

  • Question

  • Hello,

     

    I am looking for a sample code ( C#  , C++ , VB ) to read and write to usb port.

    data can be binary or ascii , any help is greatly appreciated

     

    thanks

    Michael

     

     

    Thursday, July 27, 2006 4:17 PM

Answers

  • hi,

    thanks , you kind of solved the problem , let me explain . using a "PC to PC USB cables " I can connect the two PC and the dirver is already

    installed , at this point Windows sees the USB port as a  DVD or disc drive , doesn't make sense just to open a file ("E:\myfile") and read or write to it ?

    thanks

    Michael

     

    Thursday, July 27, 2006 9:33 PM

All replies

  • Sadly using C# to access a USB port is nothing like accessing a regular RS-232 serial port... in order to do anything with the port or the device on the other side you generally need to know what kind of device you are dealing with, what you want to do with it and the driver that is proving the entry point to it.

    What sort of device are you trying to work with?

    Thursday, July 27, 2006 4:22 PM
  • hi ,

    thanks for your reply  , how about a simple case of two PC's connected via USB port and process A writes to and process B reads from

    the USB port .

    I don't have to do this in C# , any language (C++,JAVA , PERL , etc.. ) is acceptable.

    thanks

    Michael

     

     

     

    Thursday, July 27, 2006 8:24 PM
  • Even that kind of task is driver dependant because USB devices only work in a host/device sort of interface where the host runs the show and the device responds... in the case of a connecting two PC’s USB ports directly things would fail (aside from the major electrical issues) because both PC’s would try to exert control and expect the other to submit... to get around this problem PC to PC USB cables have a controller within that allows each PC to think that they are in charge... but even this doesn’t get you where you want to be because there is still a major missing piece... the driver.

    I’ll say it again, ANY kind of USB device you use with a PC requires a driver on the PC side to allow you to control the USB device and depending on the device and it is very difficult to give any specific pointers because of the wide range of ways it would need to be controlled.

    In terms of a starting direction you may want to familiarize yourself with DeviceIoControl() and how it can be used in C# with something like #USBLib... any specifics though will heavily depend on the drivers of the device you want to work with and such information is rarely publicly available.

    Depending on what you are trying to do (PC to PC communication?) you might want to look in a different direction such as direct network communication.

    Thursday, July 27, 2006 8:51 PM
  • hi,

    thanks , you kind of solved the problem , let me explain . using a "PC to PC USB cables " I can connect the two PC and the dirver is already

    installed , at this point Windows sees the USB port as a  DVD or disc drive , doesn't make sense just to open a file ("E:\myfile") and read or write to it ?

    thanks

    Michael

     

    Thursday, July 27, 2006 9:33 PM
  • Hello,

    I think this connection is ( PC to Storage Device, " hard disk " ) for both PCs, try to work with this idea if you want to share files between it.

    but if you want to control one PC from another via USB connection cable try to think about another idea.

    I hope to succeed.
    • Edited by t.s.al-zahrani Saturday, September 6, 2008 11:31 PM additional idea.
    Saturday, September 6, 2008 11:26 PM
  • hello

    i am in the same situation that you some years ago, i would like to know how do you solve it?

    thaks

    Fran
    • Proposed as answer by Callius Tuesday, March 22, 2011 2:40 PM
    • Unproposed as answer by Callius Tuesday, March 22, 2011 2:40 PM
    Tuesday, June 2, 2009 11:19 AM
  • USB has allways been aside in the main development lines (of MS). That arises a question whether the ICT-technology is delayed, because of MS had so dominant a role in it? Would all necessary iivers been otherwise developed for years  ago, and, given to the wide publicity?

    Maybe you think about that, befor bothering again and again those complicated details, into which we (as programmers) must go now, as we are mainly supported by the USB-standards and halfly misleading strips of program examples in the internet.

     

     

     

    Tuesday, March 22, 2011 2:47 PM