Author Topic: Finding available COM port numbers  (Read 3005 times)

0 Members and 1 Guest are viewing this topic.

Offline Billysugger

  • Newbie
  • Posts: 2
    • View Profile
Finding available COM port numbers
« on: December 16, 2019, 05:08:17 pm »
Hi All,

I am writing a utility which writes data to a device connected to a Virtual COM Port connected by USB.  The trouble is, Windows has a nasty habit of re-assigning COM port numbers to different devices, or even sometimes the same device connected to a different USB port.  So while I can use Device Manager to establish which COM port I am connected to, and hand edit my code to use that port, that won't help eventual users who will run the executable using a device plugged into which ever USB port they choose.  So at runtime, m y code will have no idea which COM port to open.

Does anyone have a good idea how to find the next available COM port number, or which ports are available so I can give the user the option?

Marked as best answer by Billysugger on January 02, 2020, 05:05:31 am

Offline visionmercer

  • Newbie
  • Posts: 8
    • View Profile
Re: Finding available COM port numbers
« Reply #1 on: December 17, 2019, 07:22:33 am »
Hi
This example code in the wiki might help you:
https://www.qb64.org/wiki/Windows_Libraries#Windows_Ports

Offline Billysugger

  • Newbie
  • Posts: 2
    • View Profile
Re: Finding available COM port numbers
« Reply #2 on: January 02, 2020, 10:01:22 am »
Hi
This example code in the wiki might help you:

Thank you!  I'll give that a try :-)
« Last Edit: January 02, 2020, 10:04:35 am by Billysugger »