MLIB
Loading...
Searching...
No Matches
Serial Port Enumeration

Functions for retrieving available serial ports. More...

Functions

bool mlib::SerEnum_UsingCreateFile (std::vector< int > &ports)
 Iterate from 1 to 255 finding those ports for which the CreateFile function doesn't fail.
 
bool mlib::SerEnum_UsingSetupAPI (std::vector< int > &ports, std::vector< std::string > &names)
 Uses SetupDiEnumDeviceInfo function to retrieve available COM ports and their friendly name.
 
bool mlib::SerEnum_UsingRegistry (vector< int > &ports)
 Enumerates all values under HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM to retrieve available COM ports.
 

Detailed Description

Functions for retrieving available serial ports.

These functions are heavily inspired from [CEnumerateSerial] (http://www.naughter.com/enumser.html) code.

From the original code I've removed methods that don't seem to be working (ComDBOpen) or that take a ridiculous amount of time to execute (GetDefaultCommConfig).

In the end I was left with three methods: using CreateFile, using SetupAPI and using the registry. The CreateFile method has no particular advantage except that it is conceptually very simple. The setup API is a bit slower (about 15 ms per port on my machine) but it returns also the friendly port name. The registry method is blazing fast (under 1 ms) but does not provide the friendly name.