Sujet : Re: Find all COM ports (Windows)
De : ralfixx (at) *nospam* gmx.de (Ralf Fassel)
Groupes : comp.lang.tclDate : 13. Jun 2024, 09:40:28
Autres entêtes
Message-ID : <ygamsnpqlqb.fsf@akutech.de>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
* Helmut Giese <
hgiese@ratiosoft.com>
| is there a way to find all COM ports which currently exist on a
| Windows machine? IIRC I once had a twapi routine which could do that
| but either I am wrong or I cannot find it anymore.
| Any help will be greatly appreciated
Using the registry package:
# Retrieve actually available com-ports from Windows registry.
proc get_serial_ports_from_windows_registry {{hwpath 0}} {
set ComPorts [list]
#
# Get available com-ports from windows registry
#
package require registry
set serial_base "HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM"
if {![catch { registry values $serial_base } values]} {
foreach valueName $values {
if {![catch {string trim [registry get $serial_base $valueName]} port]} {
if {$hwpath} {
lappend ComPorts "\\.\$port"
} else {
lappend ComPorts $port
}
}
}
set ComPorts [lsort $ComPorts]
}
return $ComPorts
}
HTH
R'