Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: From Support: Detecting COMM port and attached device names (if any)

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    From Support: Detecting COMM port and attached device names (if any)

    Issue request at http://www.thinbasic.com/community/p...hp?issueid=246


    Dear Paul,

    this inquiry is more a help request so maybe if you post into forum and not Support area you will get more help. Than if we recognize it is a bug we will move to support.


    COMM port can be indicated at runtime so you can always let your user indicate the port on which is needed to work before opening it.

    To have more info regarding an installed hardware you can use thinBasic WMI module (Windows Management Instrumentation) that let you query Windows to get info about hardware or many other areas.

    Here an example (also attached) from which you can have an idea:
      uses "WMI"
      uses "OS"
      uses "CONSOLE"
        
      dim vData()       as string
      dim nItems        as long
      dim Counter       as long
      dim ComputerName  as string   value OS_GetComputerName
      dim sBuffer       as string
    
      '---Ask data to WMI system
    
      sBuffer = WMI_GetData(ComputerName, "", "", "", "Win32_SerialPort", "", "DeviceID, MaxBaudRate, Name" )
    
      '---Parse returned data into single lines
      nItems = PARSE( sBuffer, vData(), $crlf)
    
      '---Print lines
      for Counter = 1 to nItems
        console_writeline vData(Counter)
      next
    
      '---Finished
      console_writeline "-----------------------------------------------------"
      console_writeline "Number of lines: " & nItems
      console_writeline "---------------------------Press a key to finish-----"    
      console_waitkey
    
    More info on WMI and COMM port can be found at: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    Hope this can help
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159
    I do a slight cheat which seems to work at the moment but WMI is probably a better option.

    Here is my whole routine but its only the first three lines that find the ports and organise them into an array. remember to add "\\.\" before the port name as ports over a certain number (which I cant remember) require it, so I add it to them all.
    Function GetComPorts(CBHNDL As DWord)
      Local N,M    As DWord
      Local nIdx   As DWord
      Local Buffer As String
      Local Ports() As String
      
      If Registry_PathExists("HKEYLM", "hardware\devicemap\serialcomm") Then
        Buffer = Registry_GetAllKeys("HKEYLM", "hardware\devicemap\serialcomm")
        Split(Buffer,$CRLF,Ports)
        If UBound(Ports) <> UBound(ComPorts) Then
        '---To minimize video redraw, better to stop control updates
          ListView_BeginUpdate CBHNDL, %LvwDisp1
            ListView_DeleteAllItems(CBHNDL, %LvwDisp1)
            ReDim ComPorts(UBound(Ports))
            For n = 1 To UBound(Ports)
              ComPorts(n) = Remain$(Ports(n),"=")
              ListView_InsertItem     CBHNDL, %LvwDisp1, n,  1, ""
              ListView_SetItem        CBHNDL, %LvwDisp1, n,  2, ComPorts(n)
              ListView_SetCheckState  CBHNDL, %LvwDisp1, n, %TRUE
            Next
        '---To minimize video redraw, better to stop control updates
          ListView_EndUpdate CBHNDL, %LvwDisp1
        EndIf
      EndIf
    End Function
    
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  3. #3
    Member
    Join Date
    Jan 2010
    Location
    Montreal, Canada
    Posts
    40
    Rep Power
    19

    Missing COM Port

    Eros;

    I tried your code and it gets the three Bluetooth ports on my system, but not the USB-to-Serial bridge (COM9). System is 64-bit Windows 7 - could this be the reason? See attached regedit screen shot.

    Rick
    Attached Images Attached Images

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    That is what WMI returns.

    Try this great util: WMI Explorer 1.10
    Download from http://www.ks-soft.net/hostmon.eng/downpage.htm#utils

    Run "wmiexplorer.exe".
    It will load all WMI class names
    Click on "Win32_SerialPort" and check what this software tells you.
    I'm quite sure it will tell you exactly the same as thinBasic script.

    Let me know, I'm curious.
    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    Member
    Join Date
    Jan 2010
    Location
    Montreal, Canada
    Posts
    40
    Rep Power
    19
    Same thing, Eros. It does not show COM9. Both the Registry and Device Manager do show it, however. Strange. Consequence of a 64-bit machine?

    Rick

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Quote Originally Posted by fgasoi View Post
    Consequence of a 64-bit machine?
    Well, not sure 100% but I do not think so.
    I think that WMI is a very precise system and maybe that serial port falls into a different WMI class.
    I will try to check. I have similar device at work.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Google_ing and BING_ing around seems we are not alone on this problem.
    The problem to be in WMI under Windows 7 that does not return virtual serial ports.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #8
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159
    Eros its not just Win7, I tested under XP Pro SP3 lastnight and WMI didnt report my prolific usb to rs232 adapter as a serial port but it did appear in the usb devices but that does directly show the com port number.

    Mike C.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  9. #9
    Member
    Join Date
    Jan 2010
    Location
    Montreal, Canada
    Posts
    40
    Rep Power
    19
    Most amusingly, Michael's script DOES show this port, but does not give the numbers for the other ports! See attached screen shot.

    Rick
    Attached Images Attached Images

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Quote Originally Posted by Michael Clease View Post
    Eros its not just Win7, I tested under XP Pro SP3 lastnight and WMI didnt report my prolific usb to rs232 adapter as a serial port but it did appear in the usb devices but that does directly show the com port number.Mike C.
    For me at the moment is to understand if thinBasic WMI module is working fine or not.For what I can see it is working fine because it seems it is reporting the same data as other tools are doing.otherwise I woul have a bug to fixNow the problem it to see why WMI does not report that kind of device, maybe there are other ways like (for example) interrogating USB classes devices checking details
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Page 1 of 2 12 LastLast

Similar Threads

  1. OpenCL: Device information [Updated Sep 04 2011]
    By Petr Schreiber in forum OpenCL
    Replies: 14
    Last Post: 09-02-2010, 14:09

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

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