Future Technology Devices International Ltd. Application Note AN_123 How COM Ports Are Allocated On Driver Installation Document Reference No.: FT_000171 Version 1.0 Issue Date: 2009-08-27 The purpose of this application note is to clarify how COM ports are assigned when installing the FTDI Virtual COM Port (VCP) driver, and what the user can do to manipulate the assignment. Future Technology Devices International Limited (FTDI) Unit 1, 2 Seaward Place, Centurion Business Park, Glasgow G41 1HH, United Kingdom Tel.: +44 (0) 141 429 2777 Fax: + 44 (0) 141 429 2758 E-Mail (Support): [email protected] Web: http://www.ftdichip.com Copyright © 2009 Future Technology Devices International Limited Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 Table of Contents 1 Introduction................................................................... 2 2 Why does my COM port keep incrementing for new devices? ............................................................................. 3 2.1 3 4 Default FTDI Device States ....................................................... 3 Options for Controlling the COM Port Assignment ........... 4 3.1 Re-assign the COM Port After Installation................................. 4 3.2 Reprogram all devices to use identical VID, PID, Serial Number. 5 3.3 Reprogram all devices to use no Serial Number ........................ 6 3.4 Use Location IDs ....................................................................... 7 3.5 Use IgnoreHardwareSerialNumber Setting in the Registry ....... 8 3.6 Adding Intelligence to the Application ...................................... 9 3.7 Create a co-installer to force the assignment. ......................... 10 Contact Information ..................................................... 11 Appendix A – Abbreviations .............................................. 13 Appendix B – Revision History........................................... 14 Copyright © 2009 Future Technology Devices International Limited 1 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 1 Introduction A common request from designers is “how do I force the COM port assignment for a device to allow my application to always connect to the same port”. The purpose of this application note is to clarify how COM ports are assigned when installing the FTDI Virtual COM Port (VCP) driver, and what the user can do to manipulate the assignment. Copyright © 2009 Future Technology Devices International Limited 2 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 2 Why does my COM port keep incrementing for new devices? Any device connected to a Windows PC is identified by its VID, PID and Serial Number. When the device is connected for the first time, these parameters will be associated with a COM port by the installation wizard on the basis of the next available COM port. This is defined in the registry at: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter\ComDB These 3 parameters, VID, PID and Serial Number, are stored in the descriptor EEPROM used with the FTDI devices. With the FTxxxR devices the EEPROM is internal to the chip, while the other devices require an external EEPROM. If any of these 3 parameters change or a second device is plugged in with different VID, PID or Serial Number then the PC will detect new hardware and associate a different COM port with the device. 2.1 Default FTDI Device States If a FTxxxB device is being used, then every device is supplied with the same VID, PID and no Serial Number. VID = 0403, PID = 6001, Serial Number = blank To change these values it is necessary to interface the FTxxxB to an external EEPROM. If a FTxxxR is being used, then every device is supplied with the same VID, PID and a unique Serial Number. VID = 0403, PID = 6001, Serial Number = unique To change these values it is necessary to edit the internal EEPROM of the FTxxxR. If a FT2232D device is being used, then every device is supplied with the same VID, PID and no Serial Number. VID = 0403, PID = 6010, Serial Number = blank To change these values it is necessary to interface the FT2232D to an external EEPROM. If a FT2232H device is being used, then every device is supplied with the same VID, PID and no Serial Number. VID = 0403, PID = 6010, Serial Number = blank To change these values it is necessary to interface the FT2232H to an external EEPROM. If a FT4232H device, then every device is supplied with the same VID, PID and no Serial Number. VID = 0403, PID = 6011, Serial Number = blank To change these values it is necessary to interface the FT4232H to an external EEPROM. Copyright © 2009 Future Technology Devices International Limited 3 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 3 Options for Controlling the COM Port Assignment The next sections provide a variety of alternative methods to manipulate the COM port assignment. They also highlight the pro’s and con’s of a particuar approach. 3.1 Re-assign the COM Port After Installation A COM port may be changed to another currently unused COM port after installation. An advanced properties page is available for devices using VCP drivers. To access the advanced properties page in Windows 200 or XP, go to "Control Panel > System" then select the "Hardware" tab and click "Device Manager…", or "Control Panel > Device Manger" in Vista. Find the USB serial port which require the properties to be changed and right-click on the port. Select "Properties" from the menu then select the "Port Settings" tab to get the window below. To access more advanced settings, click on the "Advanced…" button to display the advanced properties page (shown below). Copyright © 2009 Future Technology Devices International Limited 4 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 The above screenshot shows COM3 could be changed to COM 18 or above as the other COM Ports are in use. PROs: No adjustment to hardware. No adjustment to drivers. CONs: Can only re-assign to another free port. Only one device can use a specific port. 3.2 Reprogram all devices to use identical VID, PID, Serial Number. If the design is fitted with an EEPROM to alter the device descriptors, these can be edited with MPROG. MPROG is a free FTDI utility at: http://www.ftdichip.com/Resources/Utilities.htm . You can create a template to program the same VID, PID and Serial Number into every device. The other parameters stored in the EEPROM will not have an impact on the COM Port Number assigned. PROs: All devices have same COM port assigned. CONs: Can only ever plug one device into a PC at a time. Copyright © 2009 Future Technology Devices International Limited 5 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 3.3 Reprogram all devices to use no Serial Number If the design is fitted with an EEPROM to alter the device descriptors, these can be edited with MPROG. MPROG is a free FTDI utility at: http://www.ftdichip.com/Resources/Utilities.htm . You can create a template to program the same VID, PID and Serial Number into every device. The other parameters stored in the EEPROM will not have an impact on the COM Port Number assigned. This only affects the FTxxxR devices as the other devices do not have a serial number by default. The screenshot below indicates the box which should be checked in MPPROG to disable the USB serial number. PROs: All devices using the same USB port have the same COM port assigned. Supports multiple devices connected to the PC at any time. CONs: No serial number to trace the device by. Copyright © 2009 Future Technology Devices International Limited 6 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 3.4 Use Location IDs Location IDs are used with the VID and PID to identify the device. Effectively this ignores the serial number if one exists. This method allows for the device to be untouched, but the driver must be edited before installation, which would invalidate any certification and the settings are likely to be different on every PC. Location IDs for devices may be found by using another free FTDI utility called USBVIEW. USBVIEW is downloadable at: http://www.ftdichip.com/Resources/Utilities/usbview.zip The screenshot below shows an example of a device at LocID21 To make the changes to the driver ftdibus.inf file for this location it is necessary to add the following text to the file. [FtdiBus.NT.AddService] AddReg = FtdiBus.NT.AddService.AddReg [FtdiBus.NT.AddService.AddReg] HKR,Parameters,"LocIds",1,21,00,00,00, 00 This value is held in the registry key located at: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\FTDIBUS\Parameters\LocIds For further information on driver editing refer to AN_107 Advanced Driver options at: http://www.ftdichip.com/Documents/AppNotes/AN_107_AdvancedDriverOptions_AN_000073.pdf PROs: All devices have the same COM port assigned. Do not need to change the devices EEPROMs CONs: Different settings may be required on different PCs. challenging bit more difficult to implement and prone to human error. Copyright © 2009 Future Technology Devices International Limited 7 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 3.5 Use IgnoreHardwareSerialNumber Setting in the Registry It is possible to make the system ignore a device's serial number and treat all devices with matching VID and PID connected to the same USB port as if they were the same device. This is achieved by adding a REG_BINARY value called IgnoreHWSerNum to the registry and setting it to 01. This value is held in the registry key located at: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\UsbFlags\IgnoreHWSerNum{De vice VID, PID and interface} For a default FTDI device ID (VID 0x0403, PID 0x6001), add the following registry REG_BINARY value set to 01: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\UsbFlags\IgnoreHWSerNum040 36001 For port A of an FT2232 device with default VID and PID, the IgnoreHWSerNum string would be: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\UsbFlags\IgnoreHWSerNum040 3601000 and for port B of an FT2232 device the IgnoreHWSerNum string would be: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\UsbFlags\IgnoreHWSerNum040 3601001 As the FT2232 device also uses the Windows composite device driver, an additional IgnoreHWSerNum entry is required to prevent Windows from creating additional composite driver registry entries: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\UsbFlags\IgnoreHWSerNum040 36010 PROs: All devices have the same COM port assigned. Do not need to alter the hardware. Same settings work on all PCs. Only needs setup once. CONs: Need to be able to access the registry. Copyright © 2009 Future Technology Devices International Limited 8 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 3.6 Adding Intelligence to the Application Potentially the most flexible solution is to allow any application to automatically detect the COM port being used. This can be done using the FT_GetComPortNumber function call defined in: http://www.ftdichip.com/Documents/ProgramGuides/D2XX_Programmer's_Guide(FT_000071).pdf The following code snippet is from a project at: http://www.ftdichip.com/Projects/CodeExamples/VC++.htm /*********************************************************************** //Find the com port that has been assigned to your device. /***********************************************************************/ res = FT_Open(0, &fthandle); if(res != FT_OK){ printf("opening failed! with error %d\n", res); return 1; } res = FT_GetComPortNumber(fthandle,&COMPORT); if(res != FT_OK){ printf("get com port failed %d\n", res); return 1; } if (COMPORT == -1){ printf("no com port installed \n"); } else{ printf("com port number is %d\n", COMPORT); } FT_Close(fthandle); /********************************************************/ // Open the com port assigned to your device /********************************************************/ n = sprintf(COMx, "COM%d",COMPORT); hCommPort = CreateFile( COMx, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if (hCommPort == INVALID_HANDLE_VALUE) { printf("Help - failed to open\n"); return(1); } PROs: Moves problem to application Copyright © 2009 Future Technology Devices International Limited 9 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 CONs: May run out of COM ports. 3.7 Create a co-installer to force the assignment. In theory a user could create a co-installer to force the assignment of a COM port during installation. However, if the co-installer tried to install to a port already in use (as defined by the registry) the installation would either have to fail or revert to letting the wizard select the next free port, making the co-installer redundant. This method is not supported by FTDI. Copyright © 2009 Future Technology Devices International Limited 10 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 4 Contact Information Head Office – Glasgow, UK Future Technology Devices International Limited Unit 1, 2 Seaward Place, Centurion Business Park Glasgow G41 1HH United Kingdom Tel: +44 (0) 141 429 2777 Fax: +44 (0) 141 429 2758 E-mail (Sales) [email protected] E-mail (Support) [email protected] E-mail (General Enquiries) [email protected] Web Site URL http://www.ftdichip.com Web Shop URL http://www.ftdichip.com Branch Office – Taipei, Taiwan Future Technology Devices International Limited (Taiwan) 2F, No 516, Sec. 1 NeiHu Road Taipei 114 Taiwan, R.O.C. Tel: +886 (0) 2 8797 1330 Fax: +886 (0) 2 8751 9737 [email protected] E-mail (Sales) E-mail (Support) [email protected] E-mail (General Enquiries) [email protected] Web Site URL http://www.ftdichip.com Branch Office – Hillsboro, Oregon, USA Future Technology Devices International Limited (USA) 7235 NW Evergreen Parkway, Suite 600 Hillsboro, OR 97123-5803 USA Tel: +1 (503) 547 0988 Fax: +1 (503) 547 0987 E-Mail (Sales) [email protected] E-Mail (Support) [email protected] Web Site URL http://www.ftdichip.com Branch Office – Shanghai, China Future Technology Devices International Limited (China) Room 408, 317 Xianxia Road, ChangNing District, ShangHai, China Tel: +86 (21) 62351596 Fax: +86(21) 62351595 E-Mail (Sales): [email protected] E-Mail (Support): [email protected] E-Mail (General Enquiries): [email protected] Web Site URL: http://www.ftdichip.com Copyright © 2009 Future Technology Devices International Limited 11 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 Distributor and Sales Representatives Please visit the Sales Network page of the FTDI Web site for the contact details of our distributor(s) and sales representative(s) in your country. Neither the whole nor any part of the information contained in, or the product described in this manual, may be adapted or reproduced in any material or electronic form without the prior written consent of the copyright holder. This product and its documentation are supplied on an as-is basis and no warranty as to their suitability for any particular purpose is either made or implied. Future Technology Devices International Ltd will not accept any claim for damages howsoever arising as a result of use or failure of this product. Your statutory rights are not affected. This product or any variant of it is not intended for use in any medical appliance, device or system in which the failure of the product might reasonably be expected to result in personal injury. This document provides preliminary information that may be subject to change without notice. No freedom to use patents or other intellectual property rights is implied by the publication of this document. Future Technology Devices International Ltd, Unit 1, 2 Seaward Place, Centurion Business Park, Glasgow, G41 1HH, United Kingdom. Scotland Registered Number: SC136640 Copyright © 2009 Future Technology Devices International Limited 12 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 Appendix A – Abbreviations Terms Description PID Product ID, a unique product identification issued by the holder of the VID Vendor ID, a unique vendor identification number issued by the USB USB USB Universal Serial Bus EEPROM Electrically Erasable Programmable Read Only Memory Copyright © 2009 Future Technology Devices International Limited 13 Document Reference No.: FT_000171 How COM Ports Are Allocated On Driver Installation Application Note AN_123 Version 1.0 Clearance No.: FTDI#102 Appendix B – Revision History Version 1.0 Initial Release 27th August 2009 Copyright © 2009 Future Technology Devices International Limited 14