Page 1 of 1

List All Comport in a Combo list

Posted: Friday 5th March 2021 11:10pm
by AndyGable
Hi all,

Does anyone have any code they could share with me on how to get all active Comports and list them in a combo list so i can have it so a user can select them from the list

Re: List All Comport in a Combo list

Posted: Saturday 6th March 2021 12:50am
by PJBlack
try this (you need to be root or member of dialout):

Re: List All Comport in a Combo list

Posted: Saturday 6th March 2021 10:28pm
by AndyGable
Hi PJ,

That works perfectly but i get a Error saying "Port must be closed first" but if you click ignore it works

how would i add that function to my own app now? as the file only had the exe in it and not the source code

Re: List All Comport in a Combo list

Posted: Saturday 6th March 2021 10:54pm
by PJBlack
very good question ... i've deleted that one yesterday without thinking :roll:

rewriting it ;)

EDIT:

try out if it works ...
Public oRS232 As SerialPort

Public Function GetActivePorts() As String[]

    Dim ReturnValue As New String[]
    '----------------------------------------
    Dim sShell As String
    Dim aSerPorts As String[]

    oRS232 = New SerialPort

    Shell "ls -m /dev/ttyS*" To sShell
    Replace(sShell, "\n", "")
    aSerPorts = Split(sShell, ",")
    For Each sSP As String In aSerPorts
        oRS232.PortName = Trim(sSP)
        Try oRS232.Open()
        If oRS232.Status = Net.Active Then ReturnValue.add(sSP)
        oRS232.Close
    Next

    '----------------------------------------
    Return ReturnValue

Catch
    ' Do some Error Handling if you like

End

Re: List All Comport in a Combo list

Posted: Saturday 6th March 2021 11:47pm
by AndyGable
Thank-you PJ I shall add that to my project :)

For this to list USB Ports would I just change the tty to USB?

Re: List All Comport in a Combo list

Posted: Saturday 6th March 2021 11:58pm
by PJBlack
i did not have rs232 or usb2seriell converter so i'm not shure but i guess it will maybe named ttyUSBxx ???

Re: List All Comport in a Combo list

Posted: Sunday 7th March 2021 12:08am
by AndyGable
Ill try it and let you know

Some of my Printers are USB so I can test it :)