Is it possible to write/read data from USB with C/C++?

Hi

I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?

Thanks in advance.

loco

Comments

  • : Hi
    :
    : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    :
    : Thanks in advance.
    :
    : loco
    :


    Yes. Though if you wish to connect something to a Windows PC, you'll likely end up writing a driver. Needless to say, you need to be an experienced Windows programmer.

    I know nothing about USB myself, but here is a good link:
    http://www.beyondlogic.org/


  • : : Hi
    : :
    : : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    : :
    : : Thanks in advance.
    : :
    : : loco
    : :
    :
    :
    : Yes. Though if you wish to connect something to a Windows PC, you'll likely end up writing a driver. Needless to say, you need to be an experienced Windows programmer.
    :
    : I know nothing about USB myself, but here is a good link:
    : http://www.beyondlogic.org/


    I have never worked with USB. However, as a Linux developer, I can say that this matter belongs to the operational system itself. When I wanto to read or write to a serial port (as USB is) I just open it with fopen and write using any file function. The OS takes care to discover what is the type of the port and which driver. Do not know if Windows has the same method.
  • : : : Hi
    : : :
    : : : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    : : :
    : : : Thanks in advance.
    : : :
    : : : loco
    : : :
    : :
    : :
    : : Yes. Though if you wish to connect something to a Windows PC, you'll likely end up writing a driver. Needless to say, you need to be an experienced Windows programmer.
    : :
    : : I know nothing about USB myself, but here is a good link:
    : : http://www.beyondlogic.org/
    :
    :
    : I have never worked with USB. However, as a Linux developer, I can say that this matter belongs to the operational system itself. When I wanto to read or write to a serial port (as USB is) I just open it with fopen and write using any file function. The OS takes care to discover what is the type of the port and which driver. Do not know if Windows has the same method.
    :


    I assume that he wish to make his own USB hardware and connect it to a PC. The question is vaugely formulated though, could mean anything.

    Using fopen() on a port is not ANSI C. How can you used fseek() and such functions on a "file" that changes all the time? (Unless you have a huge hw buffer) The standard clearly states that fopen() should only be used on files.
  • : : : : Hi
    : : : :
    : : : : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    : : : :
    : : : : Thanks in advance.
    : : : :
    : : : : loco
    : : : :
    : : :
    : : :
    : : : Yes. Though if you wish to connect something to a Windows PC, you'll likely end up writing a driver. Needless to say, you need to be an experienced Windows programmer.
    : : :
    : : : I know nothing about USB myself, but here is a good link:
    : : : http://www.beyondlogic.org/
    : :
    : :
    : : I have never worked with USB. However, as a Linux developer, I can say that this matter belongs to the operational system itself. When I wanto to read or write to a serial port (as USB is) I just open it with fopen and write using any file function. The OS takes care to discover what is the type of the port and which driver. Do not know if Windows has the same method.
    : :
    :
    :
    : I assume that he wish to make his own USB hardware and connect it to a PC. The question is vaugely formulated though, could mean anything.
    :
    : Using fopen() on a port is not ANSI C. How can you used fseek() and such functions on a "file" that changes all the time? (Unless you have a huge hw buffer) The standard clearly states that fopen() should only be used on files.
    :

    The point of the project is I have to create an application in C/C++ which can detect an send/receive data from USB. The application will be communicating with the Atmel ARM microcontroller (Has USB interface).

    Loco
  • : : : : Hi
    : : : :
    : : : : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    : : : :
    : : : : Thanks in advance.
    : : : :
    : : : : loco
    : : : :
    : : :
    : : :
    : : : Yes. Though if you wish to connect something to a Windows PC, you'll likely end up writing a driver. Needless to say, you need to be an experienced Windows programmer.
    : : :
    : : : I know nothing about USB myself, but here is a good link:
    : : : http://www.beyondlogic.org/
    : :
    : :
    : : I have never worked with USB. However, as a Linux developer, I can say that this matter belongs to the operational system itself. When I wanto to read or write to a serial port (as USB is) I just open it with fopen and write using any file function. The OS takes care to discover what is the type of the port and which driver. Do not know if Windows has the same method.
    : :
    :
    :
    : I assume that he wish to make his own USB hardware and connect it to a PC. The question is vaugely formulated though, could mean anything.
    :
    : Using fopen() on a port is not ANSI C. How can you used fseek() and such functions on a "file" that changes all the time? (Unless you have a huge hw buffer) The standard clearly states that fopen() should only be used on files.

    Lundin, I think that there is not an ANSI way to read and write serial devices. In Linux, as you must know, everything is a file (almost literally). The OS hides the dirty details of the hardware driver (serial port, memory address, hard disk, ...).
  • : : : : : Hi
    : : : : :
    : : : : : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    : : : : :
    : : : : : Thanks in advance.
    : : : : :
    : : : : : loco
    : : : : :
    : : : :
    : : : :
    : : : : Yes. Though if you wish to connect something to a Windows PC, you'll likely end up writing a driver. Needless to say, you need to be an experienced Windows programmer.
    : : : :
    : : : : I know nothing about USB myself, but here is a good link:
    : : : : http://www.beyondlogic.org/
    : : :
    : : :
    : : : I have never worked with USB. However, as a Linux developer, I can say that this matter belongs to the operational system itself. When I wanto to read or write to a serial port (as USB is) I just open it with fopen and write using any file function. The OS takes care to discover what is the type of the port and which driver. Do not know if Windows has the same method.
    : : :
    : :
    : :
    : : I assume that he wish to make his own USB hardware and connect it to a PC. The question is vaugely formulated though, could mean anything.
    : :
    : : Using fopen() on a port is not ANSI C. How can you used fseek() and such functions on a "file" that changes all the time? (Unless you have a huge hw buffer) The standard clearly states that fopen() should only be used on files.
    :
    : Lundin, I think that there is not an ANSI way to read and write serial devices. In Linux, as you must know, everything is a file (almost literally). The OS hides the dirty details of the hardware driver (serial port, memory address, hard disk, ...).
    :


    That is correct, there is no standard way unless you can access the hardware registers directly. But using an ANSI C function in a way it isn't ment to be used is worse than using "MyLinuxSpecificFunction()" since it will make the code appear portable, while in reality it will crash when running on another system.

    I know that everything in Linux is a file, but you can't assume that every other OS in the world works in the same manner. And as mentioned, by using fopen() on a port will make other parts of the standard, like fseek(), non-compatible.
  • : : : : : : Hi
    : : : : : :
    : : : : : : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    : : : : : :
    : : : : : : Thanks in advance.
    : : : : : :
    : : : : : : loco
    : : : : : :
    : : : : :
    : : : : :
    : : : : : Yes. Though if you wish to connect something to a Windows PC, you'll likely end up writing a driver. Needless to say, you need to be an experienced Windows programmer.
    : : : : :
    : : : : : I know nothing about USB myself, but here is a good link:
    : : : : : http://www.beyondlogic.org/
    : : : :
    : : : :
    : : : : I have never worked with USB. However, as a Linux developer, I can say that this matter belongs to the operational system itself. When I wanto to read or write to a serial port (as USB is) I just open it with fopen and write using any file function. The OS takes care to discover what is the type of the port and which driver. Do not know if Windows has the same method.
    : : : :
    : : :
    : : :
    : : : I assume that he wish to make his own USB hardware and connect it to a PC. The question is vaugely formulated though, could mean anything.
    : : :
    : : : Using fopen() on a port is not ANSI C. How can you used fseek() and such functions on a "file" that changes all the time? (Unless you have a huge hw buffer) The standard clearly states that fopen() should only be used on files.
    : :
    : : Lundin, I think that there is not an ANSI way to read and write serial devices. In Linux, as you must know, everything is a file (almost literally). The OS hides the dirty details of the hardware driver (serial port, memory address, hard disk, ...).
    : :
    :
    :
    : That is correct, there is no standard way unless you can access the hardware registers directly. But using an ANSI C function in a way it isn't ment to be used is worse than using "MyLinuxSpecificFunction()" since it will make the code appear portable, while in reality it will crash when running on another system.
    :
    : I know that everything in Linux is a file, but you can't assume that every other OS in the world works in the same manner. And as mentioned, by using fopen() on a port will make other parts of the standard, like fseek(), non-compatible.
    :

    I understand your point of view, and I agree. However, this is how it is made in Linux, as far as I know. Do you know how it works under Windows?
  • [b][red]This message was edited by SilverDEATHC at 2007-1-23 8:45:18[/red][/b][hr]
    : : : : Hi
    : : : :
    : : : : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    : : : :
    : : : : Thanks in advance.
    : : : :
    : : : : loco
    : : : :
    : : :
    : : :
    : : : Yes. Though if you wish to connect something to a Windows PC, you'll likely end up writing a driver. Needless to say, you need to be an experienced Windows programmer.
    : : :
    : : : I know nothing about USB myself, but here is a good link:
    : : : http://www.beyondlogic.org/
    : :
    : :
    : : I have never worked with USB. However, as a Linux developer, I can say that this matter belongs to the operational system itself. When I wanto to read or write to a serial port (as USB is) I just open it with fopen and write using any file function. The OS takes care to discover what is the type of the port and which driver. Do not know if Windows has the same method.
    : :
    :
    :
    : I assume that he wish to make his own USB hardware and connect it to a PC. The question is vaugely formulated though, could mean anything.
    :
    : Using fopen() on a port is not ANSI C. How can you used fseek() and such functions on a "file" that changes all the time? (Unless you have a huge hw buffer) The standard clearly states that fopen() should only be used on files.
    :
    As far as I know Windows makes it easy but What do you want to write to the USB Drive? if you are wanting to write a data file it would be just as simple as using the
    [code]
    file.open("a:input.dat");
    file.close("a:input.dat");
    [/code]
    where 'a' is the drive letter and you choose your names for 'file' and 'input'.


  • : [b][red]This message was edited by SilverDEATHC at 2007-1-23 8:45:18[/red][/b][hr]
    : : : : : Hi
    : : : : :
    : : : : : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    : : : : :
    : : : : : Thanks in advance.
    : : : : :
    : : : : : loco
    : : : : :
    : : : :
    : : : :
    : : : : Yes. Though if you wish to connect something to a Windows PC, you'll likely end up writing a driver. Needless to say, you need to be an experienced Windows programmer.
    : : : :
    : : : : I know nothing about USB myself, but here is a good link:
    : : : : http://www.beyondlogic.org/
    : : :
    : : :
    : : : I have never worked with USB. However, as a Linux developer, I can say that this matter belongs to the operational system itself. When I wanto to read or write to a serial port (as USB is) I just open it with fopen and write using any file function. The OS takes care to discover what is the type of the port and which driver. Do not know if Windows has the same method.
    : : :
    : :
    : :
    : : I assume that he wish to make his own USB hardware and connect it to a PC. The question is vaugely formulated though, could mean anything.
    : :
    : : Using fopen() on a port is not ANSI C. How can you used fseek() and such functions on a "file" that changes all the time? (Unless you have a huge hw buffer) The standard clearly states that fopen() should only be used on files.
    : :
    : As far as I know Windows makes it easy but What do you want to write to the USB Drive? if you are wanting to write a data file it would be just as simple as using the
    : [code]
    : file.open("a:input.dat");
    : file.close("a:input.dat");
    : [/code]
    : where 'a' is the drive letter and you choose your names for 'file' and 'input'.
    :
    :
    :

    Simple as file.open("a:[red][b][/red][/b]input.dat"); ;-)

    As he says, he wish to communicate with a microcontroller, not portable USB memory sticks...
  • : : : : : : : Hi
    : : : : : : :
    : : : : : : : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    : : : : : : :
    : : : : : : : Thanks in advance.
    : : : : : : :
    : : : : : : : loco
    : : : : : : :
    : : : : : :
    : : : : : :
    : : : : : : Yes. Though if you wish to connect something to a Windows PC, you'll likely end up writing a driver. Needless to say, you need to be an experienced Windows programmer.
    : : : : : :
    : : : : : : I know nothing about USB myself, but here is a good link:
    : : : : : : http://www.beyondlogic.org/
    : : : : :
    : : : : :
    : : : : : I have never worked with USB. However, as a Linux developer, I can say that this matter belongs to the operational system itself. When I wanto to read or write to a serial port (as USB is) I just open it with fopen and write using any file function. The OS takes care to discover what is the type of the port and which driver. Do not know if Windows has the same method.
    : : : : :
    : : : :
    : : : :
    : : : : I assume that he wish to make his own USB hardware and connect it to a PC. The question is vaugely formulated though, could mean anything.
    : : : :
    : : : : Using fopen() on a port is not ANSI C. How can you used fseek() and such functions on a "file" that changes all the time? (Unless you have a huge hw buffer) The standard clearly states that fopen() should only be used on files.
    : : :
    : : : Lundin, I think that there is not an ANSI way to read and write serial devices. In Linux, as you must know, everything is a file (almost literally). The OS hides the dirty details of the hardware driver (serial port, memory address, hard disk, ...).
    : : :
    : :
    : :
    : : That is correct, there is no standard way unless you can access the hardware registers directly. But using an ANSI C function in a way it isn't ment to be used is worse than using "MyLinuxSpecificFunction()" since it will make the code appear portable, while in reality it will crash when running on another system.
    : :
    : : I know that everything in Linux is a file, but you can't assume that every other OS in the world works in the same manner. And as mentioned, by using fopen() on a port will make other parts of the standard, like fseek(), non-compatible.
    : :
    :
    : I understand your point of view, and I agree. However, this is how it is made in Linux, as far as I know. Do you know how it works under Windows?
    :


    Nope, or would have posted it :-)

    I assume that you need a driver for the specific device or Windows will go bananas every time you connect. As for the communication part, perhaps there are generic functions you can use. Perhaps it is as simple as using CreateFile(), like you do when talking through COM ports.
  • : : [b][red]This message was edited by SilverDEATHC at 2007-1-23 8:45:18[/red][/b][hr]
    : : : : : : Hi
    : : : : : :
    : : : : : : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    : : : : : :
    : : : : : : Thanks in advance.
    : : : : : :
    : : : : : : loco
    : : : : : :
    : : : : :
    : : : : :
    : : : : : Yes. Though if you wish to connect something to a Windows PC, you'll likely end up writing a driver. Needless to say, you need to be an experienced Windows programmer.
    : : : : :
    : : : : : I know nothing about USB myself, but here is a good link:
    : : : : : http://www.beyondlogic.org/
    : : : :
    : : : :
    : : : : I have never worked with USB. However, as a Linux developer, I can say that this matter belongs to the operational system itself. When I wanto to read or write to a serial port (as USB is) I just open it with fopen and write using any file function. The OS takes care to discover what is the type of the port and which driver. Do not know if Windows has the same method.
    : : : :
    : : :
    : : :
    : : : I assume that he wish to make his own USB hardware and connect it to a PC. The question is vaugely formulated though, could mean anything.
    : : :
    : : : Using fopen() on a port is not ANSI C. How can you used fseek() and such functions on a "file" that changes all the time? (Unless you have a huge hw buffer) The standard clearly states that fopen() should only be used on files.
    : : :
    : : As far as I know Windows makes it easy but What do you want to write to the USB Drive? if you are wanting to write a data file it would be just as simple as using the
    : : [code]
    : : file.open("a:input.dat");
    : : file.close("a:input.dat");
    : : [/code]
    : : where 'a' is the drive letter and you choose your names for 'file' and 'input'.
    : :
    : :
    : :
    :
    : Simple as file.open("a:[red][b][/red][/b]input.dat"); ;-)
    :
    : As he says, he wish to communicate with a microcontroller, not portable USB memory sticks...
    :

    So if i just need to send data to microcontroller via USB, I can just use [Blue]fprintf(..)[/Blue] function. :-)
  • : Hi
    :
    : I would like to write an app that can read/write to a USB. Is it possible to do that using C/C++?
    :
    : Thanks in advance.
    :
    : loco
    :
    try this book http://www.yui.ru/books/index.php?FPost=619
    i hope it is usefull(i didn't read it)
    Simion314
    simion314

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories