-1

I want to write code that will allow me to send a command (not just video) from a computer to a TV, specifically, a command that will change the input. The code needs to be in C++, and the communication must be done through a usb cable.

I am currently using Qt to communicate with the ports, but the only port that I can communicate with is "com1". I was wondering, how do I get the names of the usb ports that devices like my mouse, usb sound adapter, etc are currently using?

And if there is any Qt code that lets me send commands to usb devices, that would be sick.

Z Rev
  • 84
  • 1
  • 13
  • Serial port is a totally different technology to USB, you can't access the USB port as you want, you need to attach to the device driver (unless the device is a virtual com port which will create a serial port). – Gusman Feb 04 '16 at 15:44
  • What OS are you working on? – MikeCAT Feb 04 '16 at 16:02
  • @Gusman Strictly speaking, USB, which means Universal *Serial* Bus, is a kind of serial port. It is just not for RS-232C like communication. – MikeCAT Feb 04 '16 at 16:06
  • 1
    @MikeCAT No, it's not, the data is transferred serially, but that's the only ressemblance with a serial port, USB is managed through an USB controller which has endpoints, each endpoint describes a registered device, and when you need to transfer data you don't just bang the data through the port, you must create an sctructure accordingly to the descriptor to transfer the data. And even if you are capable of create that structure, you will not be allowed to access the underliying controller as the OS will take the control of the USB controller. – Gusman Feb 04 '16 at 16:09
  • Well, how do I send a command through a usb port then? Should I even be using Qt? – Z Rev Feb 04 '16 at 16:11
  • Hardware drivers for individual types of USB are very different from OS to OS. One class of devices: HID, Human Interface Devices like Mice, Keyboards, touch screen digitizers, etc are not trivially accessed or talked to. Each model from each company may have a completely different API for its low level interactions. The linux drivers for most devices are open for examination. Qt handles a lot of inputs and devices, but asking for a generic USB interface in Qt for * across all OS's is a little unrealistic. I would start with studying the API for the device you are trying to work with. – phyatt Feb 04 '16 at 16:21
  • The API for the monitor or for the PC? – Z Rev Feb 04 '16 at 16:23
  • 1
    @Z Rev: Your questions are a bit fragmented, but I managed to get a clear picture of what you want. The first bit is how you connect the RS-232 on your TV to your PC's USB port. That requires a small converter, and that **converter** will get a name like COM2. This is not generalizable to other USB devices. – MSalters Feb 04 '16 at 23:40
  • To give your question some substance, you'll have to post the output of usbview, showing the TV device. Make sure you use the stackoverflow's image hosting to do that, and that you crop out unnecessary content. – Kuba hasn't forgotten Monica Feb 05 '16 at 13:37

1 Answers1

0

Just because USB means Universal Serial Bus, doesn't make every USB device a serial port.

USB devices have different classes, handled by different drivers. Human interface input devices like mice and keyboards are of a HID class. These devices are not serial ports, and will not appear on a list of serial ports. Same goes for a majority of other popular devices such as scanners, video cameras, etc.

The only devices that will appear on a list of serial ports are communications class devices (CDC), and USB-to-serial converters that have drivers that expose them as serial ports, like e.g. FTDI chips.

As for your TV, you need to figure out what kind of a device class your TV appears as. You would use a tool like usbview to enumerate USB devices and see their properties. Your TV could even be a composite device that has a HID class device, and some other device class.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313