5

I've got a strange problem with some code I inherited from another programmer who's left the company, and need some guidance on how to even begin to solve it.

The problem is this - on a semi-regular basis, we are finding that duplicate USB virtual comm ports are being created. For example, on my PC, when I view the Ports in Device Manager, and select "View Hidden Devices", I have two entries for the same device - one on COM6, and one on COM8.

Unfortunately, we cannot reliably re-create the problem. We suspect it may happen when someone quickly disconnects and reconnects the USB cable when our software is running, but that needs to be confirmed.

As far as I can tell, the code was written assuming that no one would ever unplug a cable. I see no logic whatsoever to detect this condition after the SW is started. And it fails when you re-plug the cable - silently generating read and write errors even after the cable is plugged back in. You have to restart the program before it will work again.

I have very little serial and USB experience, and am at a bit of a loss as to how to even get started on fixing this.

Can anyone suggest why this might be happening?


Misc. details, in case they might be relevant:

USB serial code is in a C++ DLL

VS2008

FTDIBUS USB/Serial drivers

Windows XP and Win7

Screen shot of duplicate Registry entries (note the value of the selected key!)

Screen shot of Registry entries

Tom Bushell
  • 5,865
  • 4
  • 45
  • 60
  • 3
    Possibly related to this? http://blogs.msdn.com/b/oldnewthing/archive/2004/11/10/255047.aspx – jcoder May 11 '12 at 15:38
  • Yes, JohnB is correct. Devices with no serial number are identified by their location on the USB bus. When this changes, it is seen as a different device. – janm May 21 '12 at 23:39
  • FTDI is rather notorious for its crappy drivers. Contact them for support. – Hans Passant May 22 '12 at 01:13
  • But all our devices HAVE a serial number (albeit the same one for each device type). In the screen shot, the SN of the expanded node is "20100901" (the "A" is not returned as part of the SN by the FTDI API functions). – Tom Bushell May 22 '12 at 14:28
  • Just a guess, but back to the Old New Thing link *"I remember that one major manufacturer of USB devices didn't quite understand how serial numbers worked. They gave all of their devices serial numbers, that's great, but they all got the same serial number. Exciting things happened if you plugged two of their devices into a computer at the same time."* -- Maybe there is a special case since added for ***devices known to all have the same serial number*** to treat them as if they had no serial number. That's what I would do if I was Microsoft. – Ben Jun 16 '12 at 10:28
  • 1
    Aaaannnndddd: http://blogs.msdn.com/b/oldnewthing/archive/2004/11/10/255047.aspx#255062 (Pat Thoyts' comment) There is indeed a registry key to do this. – Ben Jun 16 '12 at 10:43
  • Just to note, the serial numbers are not chosen by FTDI, but by the electronics manufacturer designing boards with FTDI chips on them. FTDI reads the serial number, along with descriptor strings, current requirements, etc. from a companion EEPROM programmed by the board maker. – Ben Voigt Jun 18 '12 at 16:46

1 Answers1

2

As explained on Raymond Chen's blog, the Old New Thing, here, and by commenters above:

To summarize:

  • Devices which are unplugged and plugged in again are tracked so they are not treated as a new device every time.
  • Usually this uses the device serial number to detect whether a device is the same one.
  • However not every device has a serial number. These devices are treated as the same device only if they have the same vendor ID and product ID and are plugged into the same port. If they are plugged into a different port they are treated as a different device.
  • Some manufacturers do not understand the word "Serial" in "Serial Number" and give all devices the same number instead of giving them numbers serially... To cope with this there is a registry setting which can be used to force these devices to be treated as if they have no serial number.

Therefore, if a device with no serial number or which is flagged in the Windows Registry as having duplicate serial numbers is plugged in to a serial port it has not been plugged into before, it will be treated as a new device rather than a reconnection of an old device. This will result in "Ghost" devices as you describe.

Some FTDI devices are specifically called out as having this problem by the manufacturer:

Ben
  • 34,935
  • 6
  • 74
  • 113
  • BTW that FTDI technote is for the opposite problem -- when manufacturing or test equipment has thousands of identical (other than serial number) hardware plugged in sequentially, Windows assigns a new COM port number to each and soon runs out. Naive manufacturers "fix" this by sharing serial numbers, which creates the problem discussed in this question. That "IgnoreHardwareSerialNumber" hack is a way to prevent the manufacturing and test equipment from running out of COM ports, while still providing unique serial numbers on the devices, which gives the right behavior to end-users. – Ben Voigt Jun 16 '14 at 18:25