Recent

Author Topic: LazSerial not found  (Read 1340 times)

coradi

  • Full Member
  • ***
  • Posts: 197
LazSerial not found
« on: February 15, 2026, 05:49:08 pm »
Whats wrong?!
Windows 10, and the package is installed
unit1.pas(11,13) Error: Cannot find LazSerial used by Unit1. Check if package LazSerialPort is in the dependencies of the Project Inspector.

Code: [Select]
// Version 1.0

unit Unit1;

{$mode objfpc}{$H+}

interface

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

type

  { TForm1 }

  TForm1 = class(TForm)
    ButtonStart: TButton;
    LazSerial1: TLazSerial;
    Memo1: TMemo;
    procedure ButtonStartClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure LazSerial1RxData(Sender: TObject);
  private
    FBuffer: string;
    const END_STRING = 'end';
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Caption := 'COM Empfaenger - Version 1.0';
  Memo1.Clear;

  LazSerial1.Device := 'COM20';
  LazSerial1.BaudRate := br9600;
end;

procedure TForm1.ButtonStartClick(Sender: TObject);
begin
  FBuffer := '';
  Memo1.Clear;
  LazSerial1.Open;
end;

procedure TForm1.LazSerial1RxData(Sender: TObject);
var
  s: string;
begin
  s := LazSerial1.ReadData;

  // fortlaufend anzeigen
  Memo1.Text := Memo1.Text + s;
  Memo1.SelStart := Length(Memo1.Text);

  // Puffer erweitern
  FBuffer := FBuffer + s;

  // Prüfen auf END_STRING
  if Pos(END_STRING, FBuffer) > 0 then
  begin
    LazSerial1.Close;

    // "end" entfernen
    Delete(FBuffer, Pos(END_STRING, FBuffer), Length(END_STRING));
    Memo1.Text := FBuffer;

    ShowMessage('Empfang abgeschlossen');
  end;
end;

end.
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

coradi

  • Full Member
  • ***
  • Posts: 197
SOLVED
« Reply #1 on: February 15, 2026, 05:55:26 pm »
sorry, now I found the solution.
I didn't know, that I have to add lazserial in Objekt Inspektor dependecies
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

jamie

  • Hero Member
  • *****
  • Posts: 7589
Re: LazSerial not found
« Reply #2 on: February 15, 2026, 05:57:33 pm »
in case for some reason, you don't like that one, there is a UNIT called SERIAL that comes with fpc+laz

jamie
The only true wisdom is knowing you know nothing

coradi

  • Full Member
  • ***
  • Posts: 197
Re: LazSerial not found
« Reply #3 on: February 15, 2026, 06:03:17 pm »
Yes, I will try later, this is an chatgpt example:-)
But now I can't change Baudrate?!
 LazSerial1.BaudRate :='B9600';
unit1.pas(43,32) Error: Incompatible type for arg no. 1: Got "Constant String", expected "TBaudRate"

Where can I see, how I use it correct?
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

jamie

  • Hero Member
  • *****
  • Posts: 7589
Re: LazSerial not found
« Reply #4 on: February 15, 2026, 06:07:47 pm »
Code: Pascal  [Select][+][-]
  1.  TBaudRate=(br___110,br___300, br___600, br__1200, br__2400, br__4800,
  2.            br__9600,br_14400, br_19200, br_38400,br_56000, br_57600,
  3.            br115200,br128000, br230400,br256000, br460800, br921600);
  4.  
  5.  

If you highliight the unit with control-C and click on it, it will open the source page, there you can see the defines.
The only true wisdom is knowing you know nothing

coradi

  • Full Member
  • ***
  • Posts: 197
Re: LazSerial not found
« Reply #5 on: February 15, 2026, 06:08:55 pm »
thank you:-)
LazSerial1.BaudRate := TBaudRate.br19200;   
are thre different Versions?
LazSerial1.BaudRate := TBaudRate.br_19200;
LazSerial1.BaudRate := TBaudRate.br__19200;   
?   
« Last Edit: February 15, 2026, 07:06:59 pm by coradi »
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

jamie

  • Hero Member
  • *****
  • Posts: 7589
Re: LazSerial not found
« Reply #6 on: February 15, 2026, 06:16:17 pm »
Could be, I just gave you what I have installed here.

I have 0.6 is what my info displays


The only true wisdom is knowing you know nothing

coradi

  • Full Member
  • ***
  • Posts: 197
Re: LazSerial not found
« Reply #7 on: February 15, 2026, 06:18:58 pm »
How can I use the Form?
I ad a Tmemo and then name this to LazSerial1RxData?
But it doesn't work:-(
« Last Edit: February 15, 2026, 06:23:57 pm by coradi »
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

jamie

  • Hero Member
  • *****
  • Posts: 7589
Re: LazSerial not found
« Reply #8 on: February 15, 2026, 06:29:34 pm »
did you supply a OnStatus event ?

Also, what device are you connecting to it and is COM20 actually there not in used elsewhere?

Also, there could be a naming issue for ports above COM9, you may need to use //com20 or something similar, can't remember now.

Jamie


The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7589
Re: LazSerial not found
« Reply #9 on: February 15, 2026, 06:31:49 pm »
it is like this.

'\\.\COM20';

The only true wisdom is knowing you know nothing

coradi

  • Full Member
  • ***
  • Posts: 197
Re: LazSerial not found
« Reply #10 on: February 15, 2026, 06:32:51 pm »
ok, I have changed it To 2, that ist free but I can'T answer the other questions...don'T know how I do that.. I want my old TP7 back ....
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

jamie

  • Hero Member
  • *****
  • Posts: 7589
Re: LazSerial not found
« Reply #11 on: February 15, 2026, 06:37:06 pm »
ok, I have changed it To 2, that ist free but I can'T answer the other questions...don'T know how I do that.. I want my old TP7 back ....

 :D TP, The good ole days..

I don't have a device to plug into here at the moment so I can only give you suggestions, I know it works I used at work.

But for windows, anything above 9 or any port for that matter you prepend '\\.\" before the name.

Jamie
The only true wisdom is knowing you know nothing

coradi

  • Full Member
  • ***
  • Posts: 197
Re: LazSerial not found
« Reply #12 on: February 15, 2026, 06:52:21 pm »
I think that was it for today...
I don't know...
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: LazSerial not found
« Reply #13 on: February 15, 2026, 06:54:30 pm »
You can take an updated version ot TLazSerial from here:
https://forum.lazarus.freepascal.org/index.php/topic,20481.msg575974.html#msg575974
Inside there are Test and Test1 folders - both contain examples.
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

jamie

  • Hero Member
  • *****
  • Posts: 7589
Re: LazSerial not found
« Reply #14 on: February 15, 2026, 07:10:31 pm »
I just did a loop-back test and it works here.

I used a jumper to close pin 2, 3 on the serial port.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   LazSerial1.Open;
  4. end;
  5.  
  6. procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
  7. begin
  8.   If lazserial1.Active then
  9.   begin
  10.    LazSerial1.WriteData(Key);
  11.   end;
  12.  
  13. end;
  14.  
  15. procedure TForm1.LazSerial1RxData(Sender: TObject);
  16. begin
  17.   Caption := LazSerial1.ReadData;
  18. end;
  19.  
  20. procedure TForm1.LazSerial1Status(Sender: TObject; Reason: THookSerialReason;
  21.   const Value: string);
  22. begin
  23.   Caption := Value;
  24. end;                                        
  25.  
  26.  

Make sure you set the KeyPreview property to True in the form.

Jamie
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018