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.