Results 1 to 6 of 6

Thread: Com Port Detection

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    97

    Com Port Detection

    Hi,

    Is there any way to detect the numbers of serial com port in my computer using visual basic ?

    Thanks

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

    Re: Com Port Detection

    Quote Originally Posted by part0
    Hi,

    Is there any way to detect the numbers of serial com port in my computer using visual basic ?

    Thanks
    Yes. You will be using MSCommControl 6.0 to do that. You can write code that will list all your comports in a list or combo box. You can also write code that returnes whether or not any of the ports are in use. MsCommControl was supplied with the Pro & Enterprise editions only. It was not included in the free and learning editions.
    <--- 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??

  3. #3
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Com Port Detection

    The simplest way would be to enumerate the values in the regisrty under:
    HKEY_LOCAL_MACHINE\Hardware\DeviceMap\SerialComm

    I believe that you can also enumerate them using WMI but that might be a bit of an overkill

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

    Re: Com Port Detection

    Quote Originally Posted by Doogle
    The simplest way would be to enumerate the values in the regisrty under:
    HKEY_LOCAL_MACHINE\Hardware\DeviceMap\SerialComm

    I believe that you can also enumerate them using WMI but that might be a bit of an overkill
    I'm a bit Registry shy so I tend to stay away from those options. Off the top of my head I think you could write (with proper error handlers) code to loop through all your comports and execute a 'MSComm1.PortOpen = True' statement. Since Windows will return the error number for "Port not found", "Port In Use!", etc, you can handle all your errors or lack of them with a Select Case block.

    I have a 'Find Ports' routine and will post it if I can find it.
    <--- 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
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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

    Re: Com Port Detection

    Try this code. It's not cleaned up yet, but I think it's one direction for a none API alternative.

    http://www.vbforums.com/showpost.php...5&postcount=21
    <--- 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