[Lazarus] How to list available serial ports on Linux?
Corpsman
corpsman at web.de
Wed Oct 7 06:08:26 CEST 2020
That is how do it:
Function GetSerialPortNames(): String;
Var
sl: TStringlist;
Var
Info: TSearchRec;
hdl: THandle;
b: Boolean;
Begin
sl := TStringlist.create;
If FindFirst('/dev/tty*', faSysFile, Info) = 0 Then Begin
Repeat
b := true;
Try
hdl := FileOpen('/dev/' + info.Name, fmOpenReadWrite);
If hdl = -1 Then Begin
b := false;
End;
Except
b := false;
End;
If hdl >= 0 Then Begin
FileClose(hdl);
End;
If b Then Begin
sl.Add('/dev/' + info.Name);
End;
Until FindNext(info) <> 0;
End;
FindClose(Info);
result := sl.CommaText;
sl.free;
End;
On 10/6/20 11:35 PM, Bo Berglund via lazarus wrote:
> Is there a way to list the available (working) serial ports on a Linux
> platform like the RaspberryPi?
>
> I would like to offer a dropdown list of working serial ports to the
> user to select among, but I am dissuaded from it when I do the
> following:
>
> ls -la /dev/tty*
> It returns a very long list of serial devices and most of these are
> probably not even existing in real life.
>
> On an RPi I get
> /dev/tty
> /dev/ttyN (where N=0..63
> /dev/ttyAMA0 <== This is RPi Serial0 port on the pin header.
> /dev/ttyprintk
> and:
> /dev/ttyUSB0../dev/ttyUSB3 depending on what is plugged into USB
>
> All in all about 70 devices, but not sure which are actually available
> for use.
>
> Is this an impossible task or can one check for "live" serial ports
> only? If so how?
>
> On Windows I have ported a convoluted function from Delphi, which uses
> Registry reads to give me the list.
>
>
--
Auf meiner Homepage www.Corpsman.de ist immer was los, ständig wird sie aktualisiert und erweitert. Da ist für jeden was dabei.
--
Schütze deine Privatsphäre, nutze E-mail Verschlüsselung.
Wie das geht steht z.B. hier :
https://support.mozilla.org/en-US/kb/digitally-signing-and-encrypting-messages#w_installing-gpg-and-enigmail
More information about the lazarus
mailing list