: : : : : : : 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.