C++/usb input/output in c and c++ is there any way?
this is venkatesh and i am an engineering computer student.i like to know if there is any way to write code in c or c++ to take input or out put from the usb port. in fact what exactly i like to do is i want to control the hard ware(any thing)through the usb port.i like to sent some sort of signal (may be 0 or 1 or else some voltage level- i mean a signal) through the port.
for example the audio jack .we send several signals in the form of voltage signals(amplitude)for bringing out a sound. the same way i like to send some signal through the usb connected wire and i like to do some work with that signal(abstract).
if i cant then how do these audio players designed?how can they send the signals through the audio jack? how they are programed?
The answer is yes - probably. It depends on what sort of system you are using. Most modern desktop / workstation / server operating systems [MS Windows 32 and 64 bit (except 9x and ME), UNIX, Linux, Mac OSX, etc.] do not allow you direct access to the hardware. Instead access to devices is provided through device drivers and operating system services. However C and C++ are perfectly valid choices here as well.
In some cases raw access to hardware (if you have access to it or say are writing a device driver) will require facilities not provided by standard C/C++ - Intel X86 I/O ports for example. In such cases you either have to rely on support via non-standard language extensions or additional library support or do such access using assembler.
However USB ports although simple in their physical make up are complex from the protocols and (presumably) signals and software points of view - I am a C++ expert not a USB specification expert, however I would think that looking at USB as more like a small network would be a better idea.
I remind you the computers we use day to day are _digital_ computers and this in fact is reflected in the interfaces they use including USB. USB is a serial binary interface - hence you only get to send signals meaning 0 or 1 down the wire - although these may of course be encoded electrically so that more than one bit at a time can be represented - again I am a C++ expert not a USB interface / signal expert. You do _not_ get to just hijack the interface to send your own arbitrary analogue signal down it. In fact signals such as MP3 only get decoded to audio analogue signals at the very last stages. I suspect decoding and listening to an MP3 track stored on your PC via a USB audio device connected to that PC would have a rough process path something like so:
(probably best to view using a fixed pitch font such as Courier)
MP3 encoded binary data
Raw binary audio samples
<USB audio device driver>
<USB protocol stack>
| (USB cable)
| (still binary data)
[USB Audio device
<Digital to analogue conversion>
Analogue audio signal
<amplification, filtering etc.>
| ( headphone cable)
Of course you can have variations - for example if the device understood MP3 formatted data then the MP3 decoding could be moved to the audio device.
Of course if the device were a MP3 player then it is likely that the USB connection is used more like this second scenario - the USB connection is used primarily for raw data transport - remember such devices have their own storage, and so appear more like an external storage device. If they can be programmed or controlled via the PC as well then their device driver will incorporate some sort of control system for sending commands and the like which the PC program can use.
I am not sure where you think audio jacks fit into the USB picture - they don't.
Of course some devices have custom connectors that might allow either a USB connection or an audio connection (or for other functions such as recharging the device) - this was popular with mobile phones until recently for example.
If you wish to know more about USB and PC interfacing in general then I suggest you start at a site like Beyond Logic:
You will notice the whole menu at the top of the page devoted to USB topics.
For some information on hardware interfacing using C++ (and C) from the ISO C++ standards committee then look at:
Specifically section 8.
Hope this is of use.