Recent

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

mas steindorff

  • Hero Member
  • *****
  • Posts: 551
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #435 on: August 08, 2023, 08:15:05 pm »
hi Jurassic,
I have only used Lazserial in simple single port windows apps. however it is based off the older  synaser which I have used hard and a lot. With it, I've had up to 3 ports running under one program without any comm issues. besides making it OS independent, has Lazserial changed the low level interface in windows in the last few years since I last grabbed a copy?
PS, I do use each TBlockSerial in separate threads /port

And again, thanks  for the hard work.
Mas
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1251
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #436 on: August 09, 2023, 01:13:53 am »
I have only used Lazserial in simple single port windows apps. however it is based off the older  synaser which I have used hard and a lot. With it, I've had up to 3 ports running under one program without any comm issues. besides making it OS independent, has Lazserial changed the low level interface in windows in the last few years since I last grabbed a copy?
PS, I do use each TBlockSerial in separate threads /port
No change in the low-level interface in windows. I don't know if you have seen that i have edited my previous message to say that i have solved my problem on windows (error in s baud speed settings for the second tLazSerial component). In attachment a screen capture of my two ports sertest project working on windows.

And for BeaglePi : As af0815 has said :
Quote
Drop 2 LazSerial on the form and create the OnRXData Event. Only in this Event read the Data and add it to the meno. Do not read it in a timer, use the Event and store the read data, then read it in the timer if you need it there.
I use RxData events in my project.

Friendly, J.P
« Last Edit: August 09, 2023, 01:27:56 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

mas steindorff

  • Hero Member
  • *****
  • Posts: 551
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #437 on: August 09, 2023, 01:57:26 am »
No change in the low-level interface in windows. I don't know if you have seen that i have edited my previous message to say that i have solved my problem on windows (error in s baud speed settings for the second tLazSerial component). In attachment a screen capture of my two ports sertest project working on windows.
Friendly, J.P
no, our post must have bounced over to the dark side of the planet and passed as two ships in the night...
Was it in the component object editor or did you create this GPS sertest app and the bug was in it?  I ask because I have a update task coming for a Linix app and I don't use OS-X (target of latest set of changes?).  the app's copy of tLazSerial is working fine and I tend to go with a (if it's not broken, don't fix it) attitude.
 
FYI: my 3 port windows project was also a GPS app.  2 GPS input and one port output. Used it to compare data flow and timing. 
MAS
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

BeaglePi

  • New Member
  • *
  • Posts: 32
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #438 on: August 09, 2023, 02:25:49 am »
Thanks J.P. and af0815.  I will reattack the problem, bearing in mind your inputs.

I use lazSerial a lot so it would be good to have a solution.

Hil

BeaglePi

  • New Member
  • *
  • Posts: 32
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #439 on: August 10, 2023, 03:20:30 am »
I'm afraid that my outcome was rather boring but I hate it when the solution to a problem is not published.

I tried af0815's solution and it is incorporated here.  Sadly I still could not connect to both serial outputs.  I'm using a Waveshare USB to RS485 dongle for the MFCs and it may be part of the problem.

I tried slowing down the baudrate to the Arduino Mega but that did not solve the problem. 

The following code connects to both serial connections every time:

Code: Pascal  [Select][+][-]
  1.  
  2.  { TForm1 }
  3.  
  4.   TForm1 = class(TForm)
  5.     LazSerial1: TLazSerial;
  6.     LazSerial2: TLazSerial;
  7.     Memo1: TMemo;
  8.     Timer1: TTimer;
  9.     Timer2: TTimer;
  10.     procedure FormCreate(Sender: TObject);
  11.     procedure LazSerial1RxData(Sender: TObject);
  12.     procedure LazSerial2RxData(Sender: TObject);
  13.     procedure Timer1Timer(Sender: TObject);
  14.     procedure Timer2Timer(Sender: TObject);
  15.   private
  16.  
  17.   public
  18.  
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.lfm}
  27.  
  28. { TForm1 }
  29.  
  30. var
  31.   inputFrom1,
  32.   inputFrom2   :  string ;
  33.  
  34. procedure TForm1.FormCreate(Sender: TObject);
  35. var
  36.   workStr : string ;
  37. begin
  38.  try
  39.   LazSerial1.Active:= true ;
  40.   LazSerial1.Open;
  41.   Application.ProcessMessages;
  42.   workStr := '' ;
  43.   if LazSerial1.Active then
  44.    begin
  45. //    fConnect.Show ;
  46.     repeat
  47.       LazSerial1.WriteData('@E121!');
  48.       sleep (1000) ;
  49.       if LazSerial1.DataAvailable then workStr := LazSerial1.ReadData ;
  50.     until workStr = '' ;  //Was <>
  51.    end;
  52. //  fConnect.Close
  53.   except
  54.     showMessage ( 'Cannot open the Arduino serial port' ) ;
  55.     application.Terminate;
  56.   end; //try except
  57.    lazSerial2.Open;
  58.    lazSerial2.Active:= true ;
  59. end;
  60.  
  61. procedure TForm1.LazSerial1RxData(Sender: TObject);
  62.  begin
  63.   while lazSerial1.DataAvailable do
  64.       inputFrom1 := inputFrom1 + lazSerial1.ReadData ;
  65.  end;
  66.  
  67. procedure TForm1.LazSerial2RxData(Sender: TObject);
  68.  begin
  69.    while lazSerial2.DataAvailable do
  70.       inputFrom2 := inputFrom2 + lazSerial2.ReadData ;
  71.  end;
  72.  
  73. procedure TForm1.Timer1Timer(Sender: TObject);
  74. begin
  75.   lazSerial1.WriteData('@E121!');
  76.   lazSerial2.WriteData('A' + #13 );
  77. end;
  78.  
  79. procedure TForm1.Timer2Timer(Sender: TObject);
  80.  begin
  81.   if inputFrom1 <> '' then
  82.    begin
  83.     memo1.Lines.Add(inputFrom1);
  84.     inputFrom1 := '' ;
  85.    end;
  86.   if inputFrom2 <> '' then
  87.    begin
  88.     memo1.Lines.Add(inputFrom2);
  89.     inputFrom2 := '' ;
  90.    end;
  91.  end;
  92.  
  93. end.      
  94.  
  95.  

fConnect is simply a form that tells the user that the system is connecting.

I honestly don't know why this works.  It's code that I wrote ages ago to connect and I made the mistake of trying to create an improved wheel.  Perhaps it is the sleep command that is essential?  That would perhaps tie with the fact that the previous version of the code would sometimes work if I debugged into it line by line.

The output is attached.  The laser is responding to @E121! through the Mega (data from @ to !) and the Alicat MFC A is responding directly (twice) in the line starting A and ending N2.

Hil

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1251
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #440 on: August 11, 2023, 09:47:13 am »
hello,
BeaglePi, if your received frames have a terminated string (ex: !)  put the data received in a buffer until you receive the terminated string. See the OnRxData of my demo project sertest where the terminated string is char(10) (Linefeed).
Don't use DataAvailable and timer for receive.
Friendly, J.P
« Last Edit: August 11, 2023, 02:44:13 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

mig-31

  • Sr. Member
  • ****
  • Posts: 306
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #441 on: August 11, 2023, 03:16:55 pm »
Hello BeaglePi,
additionally, in case of MFC you should wait on number of  available bytes (if counted it correctly 40 bytes) to read.




 
Lazarus 2.2.6 - OpenSuse Leap 15.4, Mageia 8, CentOS 7

Joek

  • New Member
  • *
  • Posts: 27
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #442 on: August 22, 2023, 11:50:56 pm »
Please help the fool:
I'm playing with a device that sends binary data of varying lengths. Separated only by a gap of approx. 15ms.
If I receive the data with a commercial terminal, everything is OK - see the hexa output, data sentences indicated by arrows.
But when using LazSerial I get the same data presented differently.
For example hex 00 00 00 00 06 F9 is received as 00 00 00 00 78 86 by LazSerial.

Hexa editor and Memo1 is filled in by the procedure according to the example:
Code: Pascal  [Select][+][-]
  1. procedure TFMain.SerialRxData(Sender: TObject);
  2. var Str,HexaS : string;
  3.     I: integer;
  4. begin
  5.   if Serial.Synser.WaitingDataEx < 5 then exit;
  6.   Str :=  Serial.ReadData;
  7.   KHexEditor1.Append( KHexEditor1.LastVisibleIndex,Str);
  8.  
  9.   for I := 1 to Length(Str) do
  10.        begin
  11.            HexaS := HexaS + InttoHex(Ord(Str[I]),2)+ ' ';
  12.        end;
  13.   Memo1.Lines.BeginUpdate;
  14.   Memo1.Lines.Add(HexaS);
  15.   Memo1.Lines.EndUpdate;
  16.   Memo1.SelStart := Length(Memo1.Lines.Text)-1;
  17.   Memo1.SelLength:=0;
  18. end;            
  19.  

In the attached figures, identical data are indicated by arrows.
Can someone point me in the next direction?

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1251
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #443 on: August 23, 2023, 07:40:15 am »
Hello,
are you sure of your serial port settings ? what are your serial port settings ? what is your commercial terminal ? Manual or automatic settings ?
Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Joek

  • New Member
  • *
  • Posts: 27
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #444 on: August 23, 2023, 06:39:00 pm »
Thank you very very very much!
Poor communication speed.
It bothered me all day...
Jurassic Pork, You're the boss!

CM630

  • Hero Member
  • *****
  • Posts: 1195
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #445 on: December 21, 2023, 09:03:56 am »
Is it possible to detect if the connection is lost?
When I unplug the serial adapter from the PC, .active remains True. LazSerial1Status is not triggered.

Some more info: It occurs that there is something wrong, maybe with the driver of one of the devices (Prolific USB to serial). When the device is disconnected while a connection with it is open, it does not disappear from Regitry: Computer\HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM.
Another device with CH430 does not have this problem.
« Last Edit: December 22, 2023, 08:18:21 pm by CM630 »
Лазар 4,0RC1 32 bit (sometimes 64 bit); FPC3,2,2

LaurentDelaon

  • New Member
  • *
  • Posts: 21
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #446 on: January 06, 2024, 03:37:38 pm »
Bonjour Jean-PIerre,

J'essaie de transmettre des trames binaires avec LazSerial a un teensy4.0 via serial UART.
Bauds=38400.
Les trames de 10 bytes pas de soucis.
Les trames de  170octets sont souvent ratées par le teesny...
Je le voie car j'ai mis un CRC et a la réception il est Nok.
Je transmets une trame toutes les 1 s.  donc je suis dans les clous : le T4.0 peut aller jusqu' a 4000000bauds...
 
As tu rencontré ce problème qui ne vient pas  lazSerial selon moi (socat via terminal les trames sont ok).

J'ai aussi fait des essais de transmission en hexa et en decoupant par paquets mais cela double la taille des trames et les paquet doivent être a mis environ  taille 40. En plus cela charge (beaucoup) le programme émetteur qui a d'autre choses à faire....

Merci de ton retour.

Laurent.

lazarus 2.2.0
lazarus 2.2.0
fpc 3.2.2
linux x86 gtk2 ubuntu 18.04.6LTS

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1251
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #447 on: January 06, 2024, 05:21:54 pm »
Hello,
who is Jean-Pierre ? it is not me -> J.P  = Jurassic Pork 
May be see  here

Friendly J.P (not Jean-Pierre)
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

LaurentDelaon

  • New Member
  • *
  • Posts: 21
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #448 on: January 07, 2024, 02:00:12 pm »
Thank's JP for your reply.

I haven't found this post but it seem concern usb not uart.
But it seem also strangely  similar to my issue...

regards.

Laurent.
lazarus 2.2.0
lazarus 2.2.0
fpc 3.2.2
linux x86 gtk2 ubuntu 18.04.6LTS

Mistral

  • Newbie
  • Posts: 1
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #449 on: July 23, 2024, 11:33:45 pm »
May be it'll be usefull for someone, I wish to share my experience. I'm trying to use TLazSerial in my program and I had difficulties with reading data (OnRxData didn't fire).
My program using threads for every serial port, so not only reading not in main thread, but writing too.
I found that function CallEvent called through Synchronize(@CallEvent), so it's working in main thread. I commented it and just simply call CallEvent and now it's working for me as expected.

 

TinyPortal © 2005-2018