How to determine a Windows system's maximum COM port number?
Asked Answered
S

0

6

I have a system which has some devices with which it communicates through virtual COM ports. With time, the COM port numbers change. I made some code that will search for the new COM port numbers for these devices and remember them. This works fine.

My problem is with defining the COM port number search range. I found, in the Microsoft KB, that there is usually (by default) a limit of 256 COM ports on a Windows NT OS. They also specify that this is configurable and there's nothing preventing a system to have a very different maximum COM port number.

I'm wondering if there's a way to programmatically know the COM port number range. Obviously, if I let the system only search the 2⁸ range, it's going to take a very significantly shorter time than searching the, say, 2¹⁶ range! But if the system running my application is set to support over 2⁸ COM port numbers, at some point the application will surely start failing over and over again, until the COM port number allocation loops back to COM0 (or is it COM1?). I'd like to avoid that, if it doesn't require too much sorcery.

I'm mainly working with Java, but any idea is welcome.

Scala answered 15/5, 2013 at 20:7 Comment(3)
This related question might be helpful: #1389371Fairman
@EricPi Thanks! Number 9. of GrahamS' answer led me to search for ways to read the Windows Registry in Java... for which I found David's answer from #62789 . Gives me the COM port numbers I'm interested in very, very quickly. Amazing hack.Scala
Possible duplicate of How do I get a list of available serial ports in Win32?Buerger

© 2022 - 2024 — McMap. All rights reserved.