Link to home
Start Free TrialLog in
Avatar of tommym121
tommym121Flag for Canada

asked on

How do I communicate to a USB device using C++?

I am attempting to write a driver for a device that communicates via USB for Windows in C++. It is my understanding that when a USB device is installed, it will create a virtual communications port (COM#) through which it will actually communicate. This USB device is connected to another external device via ethernet cable. The driver is written to use the same protocol as the devices on the other end of the ethernet cable. So far I have been attempting to connect to the COM port I believe to be associated with this USB connection, however I have no way to tell which of the 5 COM ports I can see are in use is the correct one. Having attempted to connect to each of them with limited success, I am wondering if I can even "talk" to this USB device through a COM port or if I need to seek an alternate means of communication.
Avatar of arnold
arnold
Flag of United States of America image

much depends on the characteristics of the USB device.

If the device is ethernet based,

Usually, that will be part of the user configuration , or you have to attempt to validate by connecting to each port and sending at commands to see if there is info coming back.

The device is either USB or it is COM based
i.e. when the USB is connected, the system will load the driver that came with the device and if needed will establish/setup the com port.

You seem to be looking to write an application that will be interacting with the hardware connected via USB but is visible via a Com port.
Avatar of Dr. Klahn
Dr. Klahn

It is my understanding that when a USB device is installed, it will create a virtual communications port (COM#) through which it will actually communicate.

This is not generally correct.  With few exceptions the only USB devices that appear as COM ports, are USB COM ports.

From the problem description it sounds like you are expecting the hardware to behave in a way that USB devices do not behave.

When a (theoretical, general) USB device is installed the device appears in Device Manager as an unknown device.  Windows then goes looking for a driver.  If it finds one and depending on what kind of device has been attached, the device will then show up as a printer, sound device, line printer port, serial COM port, Ethernet interface or whatever the device may be.

linux behaves differently, but in many ways linux makes devices easier to approach when it comes to intelligent external devices.

Give us more information on the actual physical devices in question so that we can provide better advice.  Without that information we are making best guesses and shooting in the dark.
i hope this helps you get underway :  windows - C++ USB Programming - Stack Overflow 
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial