freebasic

how can I find an available COM port in FreeBASIC?


I'm working on a graphical COM port monitor in FreeBASIC, but I feel kinda wrong re-compiling every time I change the computer or the adapter. Is there any way to scan for an available COM port in FreeBASIC?


Solution

  • You can get a list of the ports available using the Win32 API function EnumPorts or you can check the registry branch HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM.

    The following two code snippets illustrate the two ways mentioned above:

    Unfortunately, the code snippet pages are in German but the given source codes, of course, will work on non German systems, too. ;-)