Results 1 to 5 of 5

Thread: Comm Port

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Comm Port

    Hi

    How to get the Number of USB to Serial Port Comm Port . Number gets frequently changed.

    Thanks

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,392

    Re: Comm Port

    You can check Device Manager. Note that the COM port numbers can go way up to at least 98 or 99. You may want to look into limiting this by a registry setting so that they don't exceed 10 or so, since some software can't handle higher COM port numbers.

    https://stackoverflow.com/questions/...om-port-number

    http://woshub.com/how-to-clean-up-an...-in-windows-7/

  3. #3
    Addicted Member
    Join Date
    Feb 2018
    Location
    Texas
    Posts
    168

    Re: Comm Port

    Quote Originally Posted by Jagjit View Post
    Hi

    How to get the Number of USB to Serial Port Comm Port . Number gets frequently changed.

    Thanks
    Why is it changing? Is the Serial com cable being plugged into different USB ports at various times. For example, like where a service tech has to connect to different computers and needs to get his diagonistic reader to receive the signal, which on different computers would be coming over differing ports depending on what port assignments had already been made by the computer for other components?

  4. #4
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,191

    Re: Comm Port

    This is for .Net so you'll need to convert back to VB6, but this is how I do it.

    VB.Net Code:
    1. Public Function findComDevice(ByVal PartialName As String) As String
    2.         Try
    3.             Dim moReturn As Management.ManagementObjectCollection
    4.             Dim moSearch As Management.ManagementObjectSearcher
    5.             Dim mo As Management.ManagementObject
    6.             moSearch = New Management.ManagementObjectSearcher("Select * from Win32_PnPEntity")
    7.             moReturn = moSearch.Get
    8.  
    9.             For Each mo In moReturn
    10.                 If IsNothing(mo.Properties.Item("Name").Value) Then Continue For
    11.                 If CStr(mo.Properties.Item("Name").Value).ToUpper.Contains(PartialName.ToUpper) Then
    12.                     'returns something like: "Prolific USB-to-Serial Comm Port (COM17)"
    13.                     Dim IPRegEx As Regex = New Regex("(?<=\().*?(?=\))")
    14.                     Return IPRegEx.Match(mo.Properties.Item("Name").Value.ToString).Value
    15.  
    16.                 End If
    17.             Next
    18.             Return Nothing
    19.         Catch ex As Exception
    20.             Messagebox.Show(ex.ToString)
    21.             Return Nothing
    22.         End Try
    23.  
    24.     End Function

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Comm Port

    I don't know if this helps you, but I just posted this:

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

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