Results 1 to 6 of 6

Thread: EnumPorts - Find the system's COM and/or LPT ports

  1. #1

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.


    Name:  sshot1.png
Views: 1590
Size:  2.7 KB

    Menu populated by demo's Form1


    Name:  sshot2.png
Views: 2157
Size:  3.2 KB

    Plugged in a USB serial IoT device. Got a Refresh event.
    Menu updated to show the current list


    Name:  sshot3.png
Views: 1497
Size:  2.0 KB

    Menu item clicked on, Form1 printed some of its info


    No special requirements, but Windows 2000 or newer is required. Only tested on Windows 10 1709.
    Attached Files Attached Files
    Last edited by dilettante; Feb 13th, 2018 at 01:23 PM. Reason: Updated to version 1.2

  2. #2

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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:

    Name:  sshot4 oops.png
Views: 734
Size:  2.5 KB


    I have now updated the code in EnumPort.cls to provide results sorted in logical order by PortName:

    Name:  sshot5 fixed.png
Views: 726
Size:  2.5 KB


    New code reposted above. This won't matter for some uses but for menus, pick lists, etc. it is probably desirable.

  3. #3

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.
    Last edited by dilettante; Feb 15th, 2018 at 08:52 PM. Reason: typo

  4. #4
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    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
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  5. #5

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  6. #6
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    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
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width