List All Comport in a Combo list

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

List All Comport in a Combo list

Post 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
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: List All Comport in a Combo list

Post by PJBlack »

try this (you need to be root or member of dialout):
Attachments
CheckSerialPorts.gambas.tar.gz
(2.33 KiB) Downloaded 224 times
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: List All Comport in a Combo list

Post 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
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: List All Comport in a Combo list

Post 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
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: List All Comport in a Combo list

Post 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?
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: List All Comport in a Combo list

Post by PJBlack »

i did not have rs232 or usb2seriell converter so i'm not shure but i guess it will maybe named ttyUSBxx ???
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: List All Comport in a Combo list

Post by AndyGable »

Ill try it and let you know

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