Page 1 of 1

COM port enumeration on PC

Posted: Sat Aug 16, 2008 6:51 pm
by richardhula
Windows (XP, Vista, Win 7) has a habit of using ever increasing COM port numbers even after devices that previously used them have been removed. This is bad news for applications that require connection to COM port number < 10 for example, especially as Device Manager will not allow manual allocation of COM ports created by Bluetooth.

When COM ports are created, the following registry entry is consulted, HKLM\System\CurrentControlSet\Control\Com name Arbiter\ComDB

COM port allocation always seems to take place above the highest port number stored in this entry. Unused COM ports below the highest in use seem to be ignored. If the value stored is not an accurate reflection of the ports in use, it can be manually adjusted. Check reg entry HKLM\Hardware\devicemap\serialcomm with bluetooth enabled & any other COM port creating devices attached, to see what ports are currently allocated.

In order to correct/tweak the ComDB entry some understanding of the 32 bit integer array indicating the status of COM ports 1 to 256 is needed. Each hex pair reflects the status of eight COM ports in reverse order, starting with the lowest group, COM 8 to 1. Converting the hex entry, each bit (1 or 0) indicates whether a COM port is used or not, e.g. 3D 00 00... would indicate that the following COM ports were in use: 1,3,4,5,6
i.e. hex 3D -> 0 0 1 1 1 1 0 1 indicating status of COM ports 8 -> 1

My own situation required that COM ports 6,7,8,9 were to be allocated automatically by my Edgeport/4 USB to COM port adaptor. GpsGate had already been used to create virtual COM ports 10,11 & 12. With COM ports 1,3,4 & 5 already in use by system/bluetooth, this left ComDB entry at 1D 0E 00... i.e. COM 12 highest port in use. Changing entry to 1D 00 00... allowed Windows to see COM 5 as highest port in use & create COM 6,7,8,9 when Edgeport adaptor was plugged in. A final check/tweak of ComDB left the value at FD 0F 00... reflecting the correct port status.

This tweak is most effective in making sure the Bluetooth stack creates COM ports where you want them, as Device Manager does not allow changing port allocation for such devices after creation. Unwanted COM ports can be uninstalled with Device Manager & ComDB checked/tweaked to accurately reflect the remaining COM ports in use. This leaves the system ready to create future ports directly above the highest in use.

Obviously great care must be taken to avoid duplicating ports although Windows has in the past managed to do this on it's own.

Regards Richard