Recent

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

Frolov

  • New member
  • *
  • Posts: 8
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #360 on: March 27, 2021, 04:42:14 pm »
Friends, please tell me why I have in this code the string is transferred after 32 characters

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.    Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, LazSerial;
  9.  
  10. type
  11.  
  12.    { TForm1 }
  13.  
  14.    TForm1 = class(TForm)
  15.       Button1: TButton;
  16.       Button2: TButton;
  17.       Button3: TButton;
  18.       Button4: TButton;
  19.       ComboBox1: TComboBox;
  20.       Edit1: TEdit;
  21.       LazSerial1: TLazSerial;
  22.       Memo1: TMemo;
  23.       RadioButton1: TRadioButton;
  24.       procedure Button1Click(Sender: TObject);
  25.       procedure Button2Click(Sender: TObject);
  26.       procedure Button3Click(Sender: TObject);
  27.       procedure Button4Click(Sender: TObject);
  28.       procedure Edit1KeyPress(Sender: TObject; var Key: char);
  29.       procedure FormCreate(Sender: TObject);
  30.       procedure LazSerial1RxData(Sender: TObject);
  31.    private
  32.  
  33.    public
  34.  
  35.    end;
  36.  
  37. var
  38.    Form1: TForm1;
  39.  
  40. implementation
  41.  
  42. {$R *.lfm}
  43.  
  44. { TForm1 }
  45.  
  46. procedure TForm1.LazSerial1RxData(Sender: TObject);
  47. var xxx: string;
  48. begin
  49.    xxx:= LazSerial1.ReadData;
  50.    Memo1.Lines.Add(xxx);
  51. end;
  52.  
  53. procedure TForm1.Button1Click(Sender: TObject);
  54. begin
  55.    try
  56.       LazSerial1.Device:= ComboBox1.Text;
  57.       LazSerial1.Active:= True;
  58.       if LazSerial1.Active then RadioButton1.Visible:= True;
  59.       ComboBox1.Enabled:= False;
  60.    except
  61.       ShowMessage('Не удалось подключить');
  62.    end;
  63. end;
  64.  
  65. procedure TForm1.Button2Click(Sender: TObject);
  66. begin
  67.    LazSerial1.Active:= False;
  68.    if not LazSerial1.Active then RadioButton1.Visible:= False;
  69.    ComboBox1.Enabled:= True;
  70. end;
  71.  
  72. procedure TForm1.Button3Click(Sender: TObject);
  73. var zzz: string;
  74. begin
  75.    zzz:= Edit1.Text;
  76.    LazSerial1.WriteData(zzz);
  77.    Edit1.SetFocus;
  78. end;
  79.  
  80. procedure TForm1.Button4Click(Sender: TObject);
  81. begin
  82.    Memo1.Clear;
  83. end;
  84.  
  85. procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: char);
  86. begin
  87.    if Key = #13 then LazSerial1.WriteData(Edit1.Text);
  88. end;
  89.  
  90. procedure TForm1.FormCreate(Sender: TObject);
  91. begin
  92.    KeyPreview := True;
  93. end;
  94.  
  95. end.
  96.  
  97.  

Frolov

  • New member
  • *
  • Posts: 8
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #361 on: March 28, 2021, 07:10:43 am »
Picture for example

Frolov

  • New member
  • *
  • Posts: 8
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #362 on: March 28, 2021, 07:35:06 am »
Friends, how can I send and receive long strings ?

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #363 on: March 28, 2021, 09:12:47 am »
hello,
what is happening when you send this string :
Quote
abcdefghijklmnoprstuvwxyz0123456789
Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Frolov

  • New member
  • *
  • Posts: 8
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #364 on: March 28, 2021, 10:53:48 am »
Everything is hyphenated after 32 characters

Frolov

  • New member
  • *
  • Posts: 8
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #365 on: March 28, 2021, 10:56:12 am »
Jurassic Pork help me out, I will be very grateful !!!

Your library is just great !!!

Frolov

  • New member
  • *
  • Posts: 8
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #366 on: March 28, 2021, 11:07:13 am »
Here is the entire test project

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #367 on: March 28, 2021, 11:10:31 am »
sending a string without terminator (ex CRLF) you are not sure that when you receive the string you have all the characters in one time when you read data (depending of the speed of the serial line) for example in your case your read 32 chrs then 2 chrs with my string. Because you have a :
Code: Pascal  [Select][+][-]
  1.  
  2. xxx:= LazSerial1.ReadData;
  3.  Memo1.Lines.Add(xxx);
you add a first line with  32 chrs then a second line with 2 chrs.
try :
Code: Pascal  [Select][+][-]
  1.  xxx:= LazSerial1.ReadData;
  2.  Memo1.Text := Memo1.Text + xxx;
  3.  

to see if it is that.
to use a terminator  add a terminator to the string sent and when your receive  the string add a memo line only when you detect the terminator (see my demo project in TLazserial)
Friendly, J.P
« Last Edit: March 28, 2021, 11:17:02 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Frolov

  • New member
  • *
  • Posts: 8
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #368 on: March 28, 2021, 02:03:35 pm »
Dear Jurassic Pork on your advice, I did so and everything worked as it should !!!

Code: Pascal  [Select][+][-]
  1.    xxx:= LazSerial1.ReadData;
  2.    Memo1.Text:= Memo1.Text+xxx;
  3.  

Thank you very much !!!

Frolov

  • New member
  • *
  • Posts: 8
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #369 on: March 28, 2021, 02:08:06 pm »
Everything is great !!! Thanks !

LaurentDelaon

  • New Member
  • *
  • Posts: 20
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #370 on: September 29, 2021, 05:56:58 pm »
HI JurassikPork,

I have a pb with SerialRxData;

to illustrate:
msg1 raw:
dst 0 6C02 ldt 88.50 5120
msg1:
dem dst?:dst 0 6C02 <-crc 1rst msg dst
ldt 88.50 5120>7E81<NOKcrc

           crc ldt|       |here add after receive and recalcul crc...
dst is a distance measure.
ldt is lidar temperature.
as you can see lazserial miss a #10 char separator
it's happen when  I do video flux with sdpovideo.

msg2:
dem gps?:gps 0 0 0 0 0 0 0 0 0902
ypr 288.8 -12.3 -5.7 6EC8>1999<NOKcrc


msg gps is follow by ypr mesg. Lose #10 separator. So the two message are not separated...

I think  need to add  a critical section in your program.
It's may do in thread section.
Could you help me ?


thank's JP
Laurent.
« Last Edit: September 29, 2021, 06:01:36 pm by LaurentDelaon »
lazarus 2.2.0
lazarus 2.2.0
fpc 3.2.2
linux x86 gtk2 ubuntu 18.04.6LTS

mas steindorff

  • Hero Member
  • *****
  • Posts: 532
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #371 on: September 29, 2021, 06:05:11 pm »
let me guess, your working in an UNIX OS.
windows 10 &11, Ubuntu 21+ - fpc 3.0.4, IDE 2.0 general releases

LaurentDelaon

  • New Member
  • *
  • Posts: 20
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #372 on: September 29, 2021, 06:51:07 pm »
yes linux ubuntu 18.04
lazarus 2.2.0
lazarus 2.2.0
fpc 3.2.2
linux x86 gtk2 ubuntu 18.04.6LTS

mas steindorff

  • Hero Member
  • *****
  • Posts: 532
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #373 on: September 29, 2021, 07:26:29 pm »
I've been looking in my notes but can find my fix quickly. 
The issue is not with pascal, it with the OS.  The OS removes LF chars from the comm port streams, even binary.  what you need to do is to tell the OS to not filter the stream.  you can probably find the commands faster than I on the web...
windows 10 &11, Ubuntu 21+ - fpc 3.0.4, IDE 2.0 general releases

LaurentDelaon

  • New Member
  • *
  • Posts: 20
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #374 on: September 29, 2021, 07:43:03 pm »
As I said

with no video treatment  this is perfecly working.

with video (charge cpu and threads) it's happens some mistake
message wich are separated before  sending with a chr(10) are not correctly parse/treated...

so this is not the OS.
lazarus 2.2.0
lazarus 2.2.0
fpc 3.2.2
linux x86 gtk2 ubuntu 18.04.6LTS

 

TinyPortal © 2005-2018