Recent

Author Topic: LazSerial not found  (Read 1417 times)

coradi

  • Full Member
  • ***
  • Posts: 197
Re: LazSerial not found
« Reply #15 on: February 15, 2026, 08:29:53 pm »
as soon as I use

  // COM-Port direkt öffnen
  LazSerial1.Device := 'COM2';
 // LazSerial1.BaudRate := TBaudRate.br_19200;
  // Integer, TLazSerial akzeptiert das
//  LazSerial1.Open;
                       

I got
this message
But any other program can access the port

same if I only try
LazSerial1.Open;
« Last Edit: February 15, 2026, 08:32:06 pm by coradi »
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

coradi

  • Full Member
  • ***
  • Posts: 197
Re: LazSerial not found
« Reply #16 on: February 15, 2026, 08:52:11 pm »
What does this mean?
Is there something missing?
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: LazSerial not found
« Reply #17 on: February 15, 2026, 09:06:39 pm »
It is not LazSerial1.Open; but LazSerial1.Active := True;
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

coradi

  • Full Member
  • ***
  • Posts: 197
Re: LazSerial not found
« Reply #18 on: February 15, 2026, 09:09:54 pm »
the same :-(
Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

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

type

  { TForm1 }

  TForm1 = class(TForm)
    Memo1: TMemo;
    LazSerial1: TLazSerial;
    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
Form1.Caption := 'Mein neues Fenster';
Caption := 'COM2 Empfänger - Version 1.0';
  Memo1.Clear;
  LazSerial1.Active := True;
// LazSerial1.Open;
  // COM-Port direkt öffnen
 // LazSerial1.Device := 'COM2';
 // LazSerial1.BaudRate := TBaudRate.br_19200;
  // Integer, TLazSerial akzeptiert das
//  LazSerial1.Open;

  FBuffer := '';
end;

procedure TForm1.LazSerial1RxData(Sender: TObject);
var
  s: string;
  p: Integer;
begin
  s := LazSerial1.ReadData;
  if s = '' then Exit;

  // Puffer erweitern
  FBuffer := FBuffer + s;

  // Daten sofort anzeigen
  Memo1.SelStart := Length(Memo1.Text);
  Memo1.SelText := s;

  // Prüfen, ob END_STRING empfangen wurde
  p := Pos(END_STRING, FBuffer);
  if p > 0 then
  begin
    // COM-Port schließen
    LazSerial1.Close;

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

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

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

coradi

  • Full Member
  • ***
  • Posts: 197
Re: LazSerial not found
« Reply #19 on: February 15, 2026, 09:12:12 pm »
any new try a new messge.
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: LazSerial not found
« Reply #20 on: February 15, 2026, 09:30:35 pm »
What if you set the badurate and the remaining settings from the IDE during design time and do not touch them during runtime?
Maybe try with 9 600, is it possible that your device does not support 19 200?

I think it should not matter, but I would use LazSerial1.BaudRate := br_19200; 

« Last Edit: February 15, 2026, 09:37:57 pm by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

jamie

  • Hero Member
  • *****
  • Posts: 7598
Re: LazSerial not found
« Reply #21 on: February 15, 2026, 09:50:52 pm »
Don't use ACTIVE := True in the FormCreate

Chances are the properties haven't been fully streamed yet to the control.

the Events to the triggers must be set fully before enabling that.

You can open the LazSerial file to see what code is at that location.

I don't have any problems with Verison 0.6, that is what's on the Online packager.

Btw, it used to be that the ACTIVE property was in the published section so the OI could set it but that used to cause issues and now that version I see on my system does not have that. %)

Jamie
« Last Edit: February 15, 2026, 09:52:45 pm by jamie »
The only true wisdom is knowing you know nothing

CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: LazSerial not found
« Reply #22 on: February 15, 2026, 10:01:29 pm »
Don't use ACTIVE := True in the FormCreate
...
Indeed @coradi, try to place a button on your control and (set and) start the serial port from there.
If it seems to work, move your code from .Create to .OnShow.
Mind that .OnShow might be fired multiple times so you will have to use a variable to store if the event was fired before.
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

jamie

  • Hero Member
  • *****
  • Posts: 7598
Re: LazSerial not found
« Reply #23 on: February 15, 2026, 10:06:43 pm »
I just looked at his Project Manager window there, the LazSerialPort is supposed to be in the package list, not in the source list.

The LazSerialPort is the package name not the Unit name.

The source list should have only "LazSerial" for the unit.

Jamie
The only true wisdom is knowing you know nothing

dseligo

  • Hero Member
  • *****
  • Posts: 1672
Re: LazSerial not found
« Reply #24 on: February 15, 2026, 10:12:53 pm »
any new try a new messge.

This messages you get, they look like the instance LazSerial1 isn't created. In reply #7 you mentioned something about renaming to 'LazSerial1RxData'.
Do you have LazSerial1 component on the form or do you have it only as a variable? If it is only a variable then you have to create it first.
Something like that could be in OnCreate event of the form:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   LazSerial1 := TLazSerial.Create(Self);
  4. end;

jamie

  • Hero Member
  • *****
  • Posts: 7598
Re: LazSerial not found
« Reply #25 on: February 15, 2026, 10:36:08 pm »
If that is the case then it wasn't installed in the IDE and a simple drop on the form.

jamie
The only true wisdom is knowing you know nothing

dseligo

  • Hero Member
  • *****
  • Posts: 1672
Re: LazSerial not found
« Reply #26 on: February 15, 2026, 11:48:29 pm »
If that is the case then it wasn't installed in the IDE and a simple drop on the form.

In reply #7 he said:
Quote
I ad a Tmemo and then name this to LazSerial1RxData?

Maybe he renamed component put on the form, and somehow added another as a LazSerial1 variable (without being on the form and thus created automatically). Of course, I am only guessing.

CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: LazSerial not found
« Reply #27 on: February 16, 2026, 07:53:48 am »
I think the picture should be descriptive enough.

Then double click the button in the frame editor and add this code:
TLazSerial.active := True;

Finally click Events on the left side on the screen (marked in a green rectangle), there click on OnRXData, you will see a button ..., click on it, the source editor will be open.

After
Code: Pascal  [Select][+][-]
  1. procedure TForm1.LazSerial1RxData(Sender:TObject);
  2. begin

add
Code: Pascal  [Select][+][-]
  1. Memo1.Append(LazSerial1.ReadData);

Build the app, press the Button, send some data over serial.

Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

coradi

  • Full Member
  • ***
  • Posts: 197
Re: LazSerial not found
« Reply #28 on: February 16, 2026, 02:58:16 pm »
NOW it works:-)
Is there any failure in Lazarus?
I clicked on Form => onCreate  = FormCreate THEN auf non, then again auf FormCreate
Then it's working?!!?

This is the working code
Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

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

type

  { TForm1 }

  TForm1 = class(TForm)
    LazSerial1: TLazSerial;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure LazSerial1Removed(Sender: TObject);
    procedure LazSerial1RxData(Sender: TObject);
    procedure LazSerial1Status(Sender: TObject; Reason: THookSerialReason;
      const Value: string);
    procedure Memo1Change(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Lines.Add('Start');

  LazSerial1.Device := 'COM2';
  LazSerial1.BaudRate := TBaudRate.br_19200;

  LazSerial1.Open;

  if LazSerial1.Active then
    Memo1.Lines.Add('Port offen')
  else
    Memo1.Lines.Add('Port NICHT offen');
end;

procedure TForm1.LazSerial1Removed(Sender: TObject);
begin

end;

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

procedure TForm1.LazSerial1Status(Sender: TObject; Reason: THookSerialReason;
  const Value: string);
begin

end;

procedure TForm1.Memo1Change(Sender: TObject);
begin

end;

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

CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: LazSerial not found
« Reply #29 on: February 16, 2026, 10:00:08 pm »
NOW it works:-)
Is there any failure in Lazarus?
I clicked on Form => onCreate  = FormCreate THEN auf non, then again auf FormCreate
Then it's working?!!?
...
I am not sure that I understand what you have done, but besides the source code (the .pas file), there is the .lfm file which contains some other info. In there is no link between the Form.Create event and the Form.Create routine in the .lfm file something might go wrong (usually the code in .Create, .OnClick, .OnMouseOver... is not executed). These links are made by the IDE when you click the events in the property editor.

If you do not intend to change these values during runtime, you can set them from the property editor of the Lazarus IDE:
Code: Pascal  [Select][+][-]
  1.   LazSerial1.Device := 'COM2';
  2.   LazSerial1.BaudRate := TBaudRate.br_19200;


Now when the issue is solved, you can rename the title to [SOLVED]old_title.
« Last Edit: February 17, 2026, 08:42:19 am by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

 

TinyPortal © 2005-2018