Recent

Author Topic: TLazSerial : serial port component for Lazarus (windows and linux).  (Read 272373 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: 963
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: 963
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 !

 

TinyPortal © 2005-2018