0
\$\begingroup\$

I am making a device that uses 232RL to translate from UART to USB and windows see a COM port. The connections are like so:

schematic

simulate this circuit – Schematic created using CircuitLab

I want to find a way so that when the customer plugs the product and opens their software, the software can find in which port the product is connected to. I design both the Hardware (product) and the software, so I can have access to anything I might need to change.

My solution, which I think is not optimal: I solved this problem by opening the COM ports one by one (done automatically from the software from COM port 0 to 255) until I find a COM port that sends a code that only the software and the product knows. That way, I know I opened the correct COM port and continue with the communication. (This takes less than a second so it works for me, I just feel there must be a better way)

The question: Is there a 'faster', simplier way to overcome this issue? Like, Can I program the 232RL so that it shows a specific name (vendor name) along with the COM port?

I use win32 API and C/C++ for the software, but I can switch to another API or library if I need to, I can even change the 232RL to another IC if that is what It takes.

\$\endgroup\$
9
  • 2
    \$\begingroup\$ You can list serial port names to find ports by description and you can configure the FT232RL EEPROM with FTDI tool to change a lot of stuff. But if you change VID/PID then the drivers don't get installed automatically. FTDI appnotes should get you started to figure out best way for you to proceed. \$\endgroup\$
    – Justme
    Commented Jul 5, 2021 at 8:53
  • \$\begingroup\$ I keep the VID/PID the same to keep the automatic driver update and I can mess with the others. Thanks. :) You may post it as an answer so I can accept it. \$\endgroup\$ Commented Jul 5, 2021 at 9:00
  • \$\begingroup\$ COM Port uses windows default driver and should not require any third party driver as long it uses the USB virtual COM class, even if the pid/vid is changed. \$\endgroup\$
    – Damien
    Commented Jul 5, 2021 at 9:08
  • \$\begingroup\$ @Damien I can communicate with the device via COM port without any drivers. My issue was to detect the device (in which COM port its connected) \$\endgroup\$ Commented Jul 5, 2021 at 9:09
  • 1
    \$\begingroup\$ @Damien FT232RL is not a CDC device so it needs FTDI VCP drivers. Whether Windows can automatically download them for you or not is another matter. \$\endgroup\$
    – Justme
    Commented Jul 5, 2021 at 14:10

2 Answers 2

1
\$\begingroup\$

You can list which serial ports exist in the system so you don't have to blindly open all ports that could exist, but only the ports that actually are connected at the moment.

You can also query the description of the serial ports, so you can skip the ports that don't look like FTDI USB ports, and only try opening the ports that look like FTDI USB ports.

And finally skip ports that are already opened by other programs.

FTDI also provides a tool for configuring the FT232RL EEPROM parameters so it can be used to customize some things that might be helpful for detecting the port.

\$\endgroup\$
0
\$\begingroup\$

The best way to do that, is to find the PID/VID number of the usb chip for the com port, since it's a "virtual com port" through USB, it still has the USB layer.

You should be able to find that through the device manager -> com port -> properties.

Here is a C# method that allows you to get the COM Port list based on a PID/VID. Note that it will return any connected devices with that PID/VID.

        /// <summary>
        /// Compile an array of COM port names associated with given VID and PID
        /// </summary>
        /// <param name="VID"></param>
        /// <param name="PID"></param>
        /// <returns>List of COM port with matching pid/vid</returns>
        List<string> ComPortNames(String VID, String PID)
        {
            String pattern = String.Format("^VID_{0}.PID_{1}", VID, PID);
            Regex _rx = new Regex(pattern, RegexOptions.IgnoreCase);
            List<string> comports = new List<string>();
            RegistryKey rk1 = Registry.LocalMachine;
            RegistryKey rk2 = rk1.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum");
            foreach (String s3 in rk2.GetSubKeyNames())
            {
                RegistryKey rk3 = rk2.OpenSubKey(s3);
                foreach (String s in rk3.GetSubKeyNames())
                {
                    if (_rx.Match(s).Success)
                    {
                        RegistryKey rk4 = rk3.OpenSubKey(s);
                        foreach (String s2 in rk4.GetSubKeyNames())
                        {
                            RegistryKey rk5 = rk4.OpenSubKey(s2);
                            RegistryKey rk6 = rk5.OpenSubKey("Device Parameters");
                            comports.Add((string)rk6.GetValue("PortName"));
                        }
                    }
                }
            }
            return comports;
        }

The 232RL datasheet states:

USB Vendor ID (VID) 0403h FTDI default VID (hex)

USB Product ID (PID) 6001h FTDI default PID (hex)

Thus be used with ComPortNames("0403", "6001");

That will return a list of devices with that pid/vid, that should be one if you only have one connected.

The datasheet also states that the PID/VID can be modified on the eeprom.

COM Port uses windows default driver and should not require any third party driver as long it uses the USB virtual COM class even if the pid/vid is changed, but it's not the case for the 232RL which uses proprietary driver. If you change the PID/VID, you need to change it in the driver INF file, but you will then need to resign the driver.

VID are assigned by the USB foundation and the fee is expensive. There are some chip manufacturers, like microchip, that can assign you a VID/PID for free if you use their chip.

If you change the PID/VID, be careful as the system automatically searches for driver, if a driver is registered on windows with that pid/vid, it will install the wrong driver and your system may BSOD.

\$\endgroup\$
5
  • \$\begingroup\$ Thank you! In combination with @Justme's comment, I can also change the Device description to not accidentally open another device that uses the same PID/VID. I dont think I will modify them, since this will not let windows update their drivers. \$\endgroup\$ Commented Jul 5, 2021 at 9:06
  • \$\begingroup\$ This "COM Port uses windows default driver and should not require any third party driver as long it uses the USB virtual COM class even if the pid/vid is changed." may be true for devices which use the USB CDC class, but this question is about a device that does not. \$\endgroup\$
    – Ben Voigt
    Commented Jul 5, 2021 at 15:49
  • \$\begingroup\$ @BenVoigt, surprisingly, correct, added clarification. \$\endgroup\$
    – Damien
    Commented Jul 6, 2021 at 3:20
  • \$\begingroup\$ You still seem to be encouraging selection of a new VID arbitrarily. There is a central clearinghouse that assigns VID to vendors. "if a driver is registered on windows with that pid/vid, it will install the wrong driver and your system may BSOD" is never a problem if you follow the rules. \$\endgroup\$
    – Ben Voigt
    Commented Jul 6, 2021 at 4:46
  • \$\begingroup\$ There are some vendor, like microchip, that can provide you with a pid/vid for free. I'm not encouraging to get arbitrary pid/vid, I explain what it does. Not everyone wants to pay the 3'500$ USB fee to get a VID for a hobby project. @BenVoigt \$\endgroup\$
    – Damien
    Commented Jul 6, 2021 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.