Recent

Author Topic: TLazSerial : serial port component for Lazarus (windows and linux).  (Read 256291 times)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 863
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #315 on: July 29, 2020, 02:14:47 am »
hello,
you cant'use events with TLazserial if your project isn't a GUI project (in GUI projects you have an event loop).
For synaser have a look here
Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

brochagdl

  • Newbie
  • Posts: 1
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #316 on: August 30, 2020, 07:34:47 pm »
Hello J.P., i make changes in your component for work in macos.

Do you want this changes?

hello,
Strange !   :-\  because cport.pas belongs to the comport library not lazserial.

Friendly, J.P

Hello esvignolo, can you share this modification?, I'm looking this for MacOS. Thanks.

MarkT1993

  • Newbie
  • Posts: 2
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #317 on: September 17, 2020, 08:24:33 am »
Hi
I am using TLazSerial V0.3 to transfer data to and from a HAAS milling terminal,
The transfer to the terminal is brilliant works great(really quick transfer too) as below:

LS is the name of my TLazserial component on the form,
txprog is just a simple memo box with 3600 lines.

Code: Pascal  [Select][+][-]
  1.   LS.Device := 'COM1';
  2.   LS.BaudRate := TBaudRate.br115200;
  3.   LS.DataBits := TDataBits.db7bits;
  4.   LS.FlowControl := TFlowControl.fcXonXoff;
  5.   LS.StopBits := TStopBits.sbOne;
  6.   LS.Parity := TParity.pEven;
  7.   LS.Active := True;
  8. For a := 0 To txprog.Lines.Count Do
  9.    Begin
  10.     b := txProg.Lines[a] + #13 + #10;
  11.     LS.WriteData(b);
  12.     If (a >= txprog.Lines.Count - 3) Then
  13.      Begin
  14.       Sleep(100);
  15.      End;
  16.    End;
  17.   LS.Active := False;

But I cant get the return from the terminal using the below

Code: Pascal  [Select][+][-]
  1. Var
  2.   a: Boolean;
  3.   b: String;
  4.   C: Integer;
  5. Begin
  6.   LS.Device := 'COM1';
  7.   LS.BaudRate := TBaudRate.br115200;
  8.   LS.DataBits := TDataBits.db7bits;
  9.   LS.FlowControl := TFlowControl.fcXonXoff;
  10.   LS.StopBits := TStopBits.sbOne;
  11.   LS.Parity := TParity.pEven;
  12.   LS.Active := True;
  13.   a:= true;
  14.   While (a = True) Do
  15.    Begin
  16.     If (B = '%') Then
  17.      Begin
  18.       C := C + 1;
  19.      End;
  20.     If (C = 2) Then
  21.      Begin
  22.       A := False;
  23.      End;
  24.     B := LS.ReadData();
  25.     txprog.Text := txprog.Text + B +#13+#10;
  26.    End;
  27.    LS.Close();

I know that the terminal and cables are working because I made a similar (albeit much slower) program in visual C# and the transfer and return come up.
Any thoughts?

(EDITED to  add code tags - please see Using the Forum)
« Last Edit: September 17, 2020, 11:32:04 am by trev »

BosseB

  • Sr. Member
  • ****
  • Posts: 304
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #318 on: September 17, 2020, 09:22:06 am »
It looks like you have not assigned the OnRxData event handler...
AFAIK LazSerial is an event driven component so the read should be done inside the OnRxData event. It is fired when the read thread in the component has detected data available on the serial line and is notifying you that it is time to read.
I don't know if it is possible to switch off the internal read thread in LazSerial but I believe not.
If you want to read yourself I think you need at least CheckSynchronize inside your own loop (or maybe Application.ProcessMessages if it is a GUI app).

PS: You should use code tags on your source code to make it better readable...
Select the code type pascal and it would look like this:
Code: Pascal  [Select][+][-]
  1. Var
  2.   a: Boolean;
  3.   b: String;
  4.   C: Integer;
  5. Begin
  6. LS.Device := 'COM1';
  7.   LS.BaudRate := TBaudRate.br115200;
  8.   LS.DataBits := TDataBits.db7bits;
  9.   LS.FlowControl := TFlowControl.fcXonXoff;
  10.   LS.StopBits := TStopBits.sbOne;
  11.   LS.Parity := TParity.pEven;
  12.   LS.Active := True;
  13.   a:= true;
  14.   While (a = True) Do
  15.    Begin
  16.     If (B = '%') Then
  17.      Begin
  18.       C := C + 1;
  19.      End;
  20.     If (C = 2) Then
  21.      Begin
  22.       A := False;
  23.      End;
  24.     B := LS.ReadData();
  25.     txprog.Text := txprog.Text + B +#13+#10;
  26.    End;
  27.    LS.Close();
  28.  
« Last Edit: September 17, 2020, 09:24:42 am by BosseB »
--
Bo Berglund
Sweden

MarkT1993

  • Newbie
  • Posts: 2
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #319 on: September 22, 2020, 01:54:37 pm »
Brilliant thanks BosseB thats sorted it now.
Thanks for the tip on Code tags too.

 

TinyPortal © 2005-2018