how to detect a serial device

I have a USB compatible serial device that is providing a data stream (no writing to it).
I succeed to locate the serialport in MacOS by getting system.serialportcount and stepping through the ports checking their names (when the device is plugged in the port name has '‘usbmodem’ in it).
However in Windows this utterly fails. I can find the relevant COMx port using the WindowsDeviceMBS function (using the property ‘friendly name’). However when I step through the ports searching the portNUMBER with the corresponding to COMx it happens that in spite of giving me a portcount of for example 4, it gives an out of bounds exception when I use a port number >1.
So how do I get the relevant port number in Windows (I need that to set properties and read the port of course).

Have you seen these links: