List All Comport in a Combo list

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 69
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

List All Comport in a Combo list

Post by AndyGable » Friday 05th March 2021 11:10pm

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

User avatar
PJBlack
Posts: 132
Joined: Tuesday 09th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: List All Comport in a Combo list

Post by PJBlack » Saturday 06th March 2021 12:50am

try this (you need to be root or member of dialout):
Attachments
CheckSerialPorts.gambas.tar.gz
(2.33 KiB) Downloaded 33 times

AndyGable
Posts: 69
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

Re: List All Comport in a Combo list

Post by AndyGable » Saturday 06th March 2021 10:28pm

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

User avatar
PJBlack
Posts: 132
Joined: Tuesday 09th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: List All Comport in a Combo list

Post by PJBlack » Saturday 06th March 2021 10:54pm

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

AndyGable
Posts: 69
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

Re: List All Comport in a Combo list

Post by AndyGable » Saturday 06th March 2021 11:47pm

Thank-you PJ I shall add that to my project :)

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

User avatar
PJBlack
Posts: 132
Joined: Tuesday 09th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: List All Comport in a Combo list

Post by PJBlack » Saturday 06th March 2021 11:58pm

i did not have rs232 or usb2seriell converter so i'm not shure but i guess it will maybe named ttyUSBxx ???

AndyGable
Posts: 69
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

Re: List All Comport in a Combo list

Post by AndyGable » Sunday 07th March 2021 12:08am

Ill try it and let you know

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

Post Reply