Click to See Complete Forum and Search --> : COM port by usb Vendor Id
pezzzz
May 27th, 2010, 01:30 PM
I need to find automatically which COM port (COM1,COM2...COMx) has been assigned to a usb device (in this instance it is FTDI serial-usb adapter)
I can list usb devices and get theirs information using DeviceIoControl. To do this, i use some of the code you can found here: www.intel.com/intelpress/usb/examples/DUSBVC.PDF
I get those info:
wVendorID 0403
wProductID 6001
wDeviceID 0600
iSerialNumber A700dAut
But even if i can associate them to a HANDLE (usb device handle), i have no idea about to get the serial port HANDLE that i can use for serial communication, or at least the COM name (like "COM5")
Any idea? Thank you all
cosmicvoid
May 27th, 2010, 08:51 PM
One way, though not very sophisticated, is to try opening each COMn port, and then request the device ID, until you find the right one.
I have used this method in some of my programs, and it works fairly well, although XP will sometimes give a fault for reasons I never discovered.
pezzzz
May 28th, 2010, 04:03 AM
Do you mean that i can get usb information (vendor id, product id...) from the COM port HANDLE?
I thought that COM port was a different type of handle, due to the fact that it is a "virtual" port.
cosmicvoid
May 28th, 2010, 04:49 AM
My suggestion was misleading, perhaps. You can't get usb device info directly from the file handle of the virtual port that the driver emulates. What I have done is, for each COM port that opens successfully, ask the ID of the device on the other end of the serial link. This assumes that you can identify your target device with a serial port transmission.
I have used FTDI usb to serial devices, but I have never needed to acutally get the usb vendor or product info programmatically, so I don't know offhand how you'd go about querying it. Maybe the driver will respond to a DeviceIoControl call, or maybe FTDI can give you more info about this.
pezzzz
May 28th, 2010, 06:36 AM
Ok, thank you! My problem is that the device connected at the other end of serial link cannot tell me anything and should be not connected. I just want to identify the ftdi connected via usb to the pc, no matter about the other end.
Maybe I can use DeviceIoControl (but i can't find which dwIoControlCode i have to use) or SetupDiGetDeviceInterfaceDetail
pezzzz
May 28th, 2010, 06:38 AM
There's also some ideas in this pdf: http://docs.google.com/viewer?a=v&q=cache:qGYPvO290UQJ:www.delcomproducts.com/downloads/USBPRGMNL.pdf+DeviceIoControl+usb+com+port&hl=it&gl=it&pid=bl&srcid=ADGEESicJUUtPqoDj2uKay56gJEKQ2lFgOPKftAICE4o8lp-3F5M9gsrzZO5mIYyETKrbS7HGFbh7iCq9pV61vg4MuAEioDxtV5L06SYLL6IiUCFCnJItYH48GhrHlMliGvSzSpv95tF&sig=AHIEtbQpMj4yIXhJFlqE7AxKKIIVpg2oDQ
pezzzz
May 28th, 2010, 09:15 AM
An idea: find the right key in the system registry and get the name of the port from it! :)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.