1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Reading com ports information from the registry

Discussion in 'Code Samples & Tips' started by Erel, May 29, 2007.

  1. Erel

    Erel Administrator Staff Member Licensed User

    This is an example of finding the available serial ports (and their descriptions) from the registry.

    Attached Files:

  2. alfcen

    alfcen Well-Known Member Licensed User

    Hi Erel
    Thanks so much for your fantastic snippet!
    It supports my therory about scanning GPS devices in a more elegant way.
    I have modified the code to allow recognition of PnpId of external devices, such as CF GPS cards and further to show the Key entry if no FriendlyName available.

    Sub Globals
    Dim subKeys(0),values(0)
    Dim id, fn
    End Sub

    Sub App_Start
    If Not(cPPC) Then
    MsgBox("This application is not supported on the desktop.")
    End If
    'for repeated queries
      subKeys() = Reg.GetSubKeyNames("Drivers\Active"'Gets the list of active drivers.
      For i = 0 To ArrayLen(SubKeys())-1
        values() = Reg.GetValueNames(
    "Drivers\Active\" & subKeys(i))
    For i2 = 0 To ArrayLen(values())-1
    If values(i2) = "Name" Then 'Checks if Name value exists.
            name = Reg.GetValue("Drivers\Active\" & subKeys(i),"Name")
    If SubString(name,0,3) = "COM" Then  'Checks if the driver name starts with COM.
              key = Reg.GetValue("Drivers\Active\" & subKeys(i),"Key")
              fn = reg.GetValue(key,
    id = Reg.GetValue("Drivers\Active\" & subKeys(i),"PnpId")
    If fn = "" Then fn = key           'Use Key if no FriendlyName available
              If StrLength(id) > 0 Then fn = ""  'Prefer PnpId over Key'
              al1.Add(name & " " & fn & id)      'Gets the FriendlyName value and PnpId, if available.
            End If
    End If
    'Sorts the values.
      ListBox1.Clear    'for repeated queries
      For i = 0 To al1.Count-1
    'Adds the values to the ListBox.
    End Sub
    Last edited: Nov 23, 2007
  3. Erel

    Erel Administrator Staff Member Licensed User

  4. Angor

    Angor Member

    USB port scanner

    Hi, what about USB scanner ?
    I want to use iPod as external data storage, but it not work property without additional drivers. And I decided that I should write drivers myself, but I don't now how to scan USB ports.
  5. alfcen

    alfcen Well-Known Member Licensed User

    Hi Angor,

    On an iPAQ (PPC 2003SE), the above routine will reveal

    COM9: Serial on USB

    Maybe it helps knowing to which port USB is tied.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice