Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate USB virtual serial ports being created - what might cause this?

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

like image 386
Tom Bushell Avatar asked Nov 05 '22 00:11

Tom Bushell


1 Answers

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

  • https://blogs.msdn.com/b/oldnewthing/archive/2004/11/10/255047.aspx

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:

  • http://www.ftdichip.com/Support/Knowledgebase/index.html?ignorehardwareserialnumber.htm
like image 197
Ben Avatar answered Nov 13 '22 17:11

Ben