CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2010
    Location
    Mirano, VE, Italy
    Posts
    7

    COM port by usb Vendor Id

    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

  2. #2
    Join Date
    Apr 2010
    Location
    Western WA, USA
    Posts
    59

    Re: COM port by usb Vendor Id

    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.

  3. #3
    Join Date
    May 2010
    Location
    Mirano, VE, Italy
    Posts
    7

    Re: COM port by usb Vendor Id

    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.

  4. #4
    Join Date
    Apr 2010
    Location
    Western WA, USA
    Posts
    59

    Re: COM port by usb Vendor Id

    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.
    Last edited by cosmicvoid; May 28th, 2010 at 04:50 AM. Reason: typos

  5. #5
    Join Date
    May 2010
    Location
    Mirano, VE, Italy
    Posts
    7

    Re: COM port by usb Vendor Id

    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

  6. #6
    Join Date
    May 2010
    Location
    Mirano, VE, Italy
    Posts
    7

    Re: COM port by usb Vendor Id

    There's also some ideas in this pdf: http://docs.google.com/viewer?a=v&q=...7AxKKIIVpg2oDQ

  7. #7
    Join Date
    May 2010
    Location
    Mirano, VE, Italy
    Posts
    7

    Re: COM port by usb Vendor Id

    An idea: find the right key in the system registry and get the name of the port from it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured