Recent

Author Topic: /dev/ttyUSBx ports enumeration and inclusion in LazSerial.Device combobox  (Read 5294 times)

Momboz

  • New member
  • *
  • Posts: 7
I would like to check the existing serial ports on an Ubuntu 12.04 LTS based machine and include those as choice to the user in the LazSerial.Device combobox.

Any advice on how to do that?

Paul Breneman

  • Sr. Member
  • ****
  • Posts: 290
    • Control Pascal
Look at the example Synaser code here (I've modified the code that lists the ports): http://ctrlterm.com/
Regards,
Paul Breneman
www.ControlPascal.com

Momboz

  • New member
  • *
  • Posts: 7
Thanks for the example indication.

I looked at it. It's not based on the LazSerial.

In my environment I am using the LazSerial package and I would like to stick to that package.

Many thanks any way.

Paul Breneman

  • Sr. Member
  • ****
  • Posts: 290
    • Control Pascal
Yes, but if you look at GetSerialPortNames at the bottom of synaser.pas you can see how to get the port names.   :)
Regards,
Paul Breneman
www.ControlPascal.com

Momboz

  • New member
  • *
  • Posts: 7
Many thanks for your help and here is what I get as result.
TheResult picture is the output when selecting a device and the FormDesign picture is the form of my application.
the code is:
Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  SynAser, LazSerial,
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    LazSerial1: TLazSerial;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }


function GetSerialPortNames: string;
var
  sr : TSearchRec;
begin
  Result := '';

  if FindFirst('/dev/ttyUSB*', $FFFFFFFF, sr) = 0 then
  begin
    repeat
      if (sr.Attr and $FFFFFFFF) = Sr.Attr then
      begin
        if Result <> '' then
          Result := Result + ',';
        Result := Result + sr.Name;
      end;
    until FindNext(sr) <> 0;
  end;
  FindClose(sr);

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  LazSerial1.ShowSetupDialog;
end;

end.

Maybe ou have any advice to me.

In advance many thanks

six1

  • Full Member
  • ***
  • Posts: 117
...one hint:
it can be also
   if FindFirst('/dev/rfcomm*', $FFFFFFFF, sr) = 0 then
if it is a bluetooth device



Momboz

  • New member
  • *
  • Posts: 7
Thanks for the hint.

The issue is that I don't know how to tell the LazSerial package that there many devices on my machine.
The function GetSerialPortNames gives me the right result, i.e. the list of the existing real serial ports.

I have a list of port and I would like to make a choice among those via the LazSerial.Device property and I don't know how.

Thanks for your help even though I could get further.

 

TinyPortal © 2005-2018