4 Attachment(s)
EnumPorts - Find the system's COM and/or LPT ports
The EnumPorts class will find the COM ports, LPT ports, or both. If a new device arrives or leaves the list of devices gets refreshed.
The information you can retrieve is:
- PortDescription
- PortName
- PortNumber
- PortType
These can be retrieved by index from 1 to Count or by key (PortName, e.g. "COM1:").
Each refresh raises the Refresh event so you can update a menu, etc.
No special requirements, but Windows 2000 or newer is required. Only tested on Windows 10 1709.
2 Attachment(s)
Re: EnumPorts - Find the system's COM and/or LPT ports
I thought I should test ports numbered greater than 9 that spill over to two digits (e.g. COM15).
This worked but I didn't care for the results:
Attachment 156227
I have now updated the code in EnumPort.cls to provide results sorted in logical order by PortName:
Attachment 156229
New code reposted above. This won't matter for some uses but for menus, pick lists, etc. it is probably desirable.
Re: EnumPorts - Find the system's COM and/or LPT ports
One more update.
Improves crash-avoidance due to subclassing if you compile EnumPorts.cls to raise exceptions.
Adds the ability to do subclassing in IDE runs.
See the compile-time options:
Code:
#Const SUBCLASS_IN_IDE = True 'True risks crashing the IDE when debugging.
#Const FAIL_ON_ERRORS = False 'True causes errors to raise exceptions.
'Exceptions raised here should turn off
'subclassing. No further device monitoring
'will be done until you assign a non-0 value
'to the PortTypes property.
'
'If you handle such exceptions you can just
'use: .PortTypes = .PortTypes to resume the
'monitoring process.
Re: EnumPorts - Find the system's COM and/or LPT ports
Just so you know that your efforts are appreciated I downloaded EnumPorts.zip regardless of the fact that I've never had an issue with Windows CommPort assignments.
Thanks,
Chris
Re: EnumPorts - Find the system's COM and/or LPT ports
Well this has nothing to do with "Windows CommPort assignments." it is for finding the list of available ports with descriptive names and keeping it up to date if a USB adapter is plugged or unplugged in later.
The main use is probably for menus and pick lists, where the description could make it easier for a user to choose the correct port.
You might possibly use it for finding a port of a USB adapter if it "moves" (assuming it has a unique driver that gives it a unique description). This isn't completely reliable of course because you might have two or more with the same description at any given time.
Re: EnumPorts - Find the system's COM and/or LPT ports
It would seem that I should have unzipped it before posting that comment.
Thanks,
Chris