QSerialPortInfo: Find the hardware location of the USB virtual serial port

I have a USB hub chip and a microcontroller connected to it on one of its ports.

I can list and communicate with the microcontroller using QSerialPortInfo / QSerialPort. My problem is that I have to tell if a shared USB device is connected to the same USB hub as my microcontroller or not.

It should be easy, I can tell the general location of the USB device like "Port_ # 0001.Hub_ # 0010", so if the Hub_ # number matches where the microcontroller is connected, I can tell it is the same hub to which they are connected.

The problem is that QSerialPortInfo.systemLocation () returns the string "\. \ COM31" and has no meaning, for example "Port_ # 0002.Hub_ # 0010".

How can I get which interface of the USB device does QSerialPortInfo / QSerialPort belong to?

Additional Information:

Windows 7, Qt 5.3, C ++ 11

QSerialPortInfo returns information:

QSerialPortInfo.portName() == "COM31"
QSerialPortInfo.description() == "LPC USB VCom Port"
QSerialPortInfo.serialNumber() == "" // (Empty string)

      

Whereas Windows Device Manager displays the real USB port correctly: (sorry but can't send images)

DeviceManager> Ports (COM and LPT)> LPC USB VCom Port (COM31)

Properties> General> Location: Port_ # 0002.Hub_ # 0010

How can I access this information from my Qt code?

+3


source to share


1 answer


Well, managed to get it working, but this is not the desired solution: I am using the SetupDiGetClassDevs Windows api call to get all devices for a specific GUID, then using the SetupDiGetDeviceRegistryProperty winApi. I get the properties until I find the specific port the MCU is on and initialize the QSerialPort with that port name. The SPDRP_LOCATION_PATHS and SPDRP_LOCATION_INFORMATION properties then provide information that can be used to locate a shared USB device on the same hub.



The problem is that this is "throw away the high level API that Qt provides and starts to get around with the winApi solution." I would rather avoid this. If there are more Qt-like and less direct winApi dependent solutions for this, it would be appreciated.

+1


source







All Articles