Using GetLastError:
Code:
FOR p% = 1 TO 255
port% = OPENIN("COM" + STR$(p%) + ": 115200,N,8,1")
SYS "GetLastError" TO winerr%
CASE winerr% OF
WHEN 0:
PRINT "COM" + STR$(p%) + " Free"
CLOSE# port%
WHEN 1:
PRINT "COM" + STR$(p%) + " In Use"
ENDCASE
NEXT
This works OK, but only for port name values "COMn" (this includes VSPE ports).
If com0com is in use, you have no idea how the port name values are defined -- the user can specify any value -- so the above code won't work.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Re WMI, http://bb4w.wikispaces.com/Enumerating+serial+ports , I tried that. Strangely, it only enumerates the com0com ports (but doesn't do this properly), and ignores COM ports altogether! (This is under Windows 7/32).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So the only accurate source of port name values that I can find is in the registry. Problem now is discovering the names, so I can then retrieve the values.
--
Ian