Recent

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

lonely_myp

  • New member
  • *
  • Posts: 9
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #105 on: November 19, 2015, 08:04:30 am »
here

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #106 on: November 19, 2015, 05:48:50 pm »
hello,
sorry but i haven't your problem on my system (Ubuntu 14.04)

try this code with only synaser  ( uses synaser ... )  :
Code: Pascal  [Select][+][-]
  1. var
  2.     Timeouts : integer;
  3.     buf : array [0..128] of Byte;
  4.  
  5.     SynaSerComPort: TBlockSerial;
  6.  
  7. begin
  8.   if SynaSerComPort = nil then
  9.  
  10.     SynaSerComPort:= TBlockSerial.Create;
  11.  
  12.   SynaSerComPort.LinuxLock:= False;
  13.   // ignore port locking in Linux
  14.   if not SynaSerComPort.InstanceActive then
  15.  
  16.     SynaSerComPort.Connect('/dev/ttyS1');  // or whatever com port (might be /dev/ttyUSB0 for Linux)
  17.   // add some delays to allow for serial port setup times
  18.  
  19.   sleep(500);
  20.  
  21.   SynaSerComPort.Config(19200, 8, 'N', SB1, False, False);
  22.  
  23.   sleep(300);
  24.  
  25.  
  26.     count:= SynaSerComPort.RecvBufferEx(@buf[0], 128, 500);  //Wait for 500ms per 128 byte packet
  27.     if SynaSerComPort.LastError = ErrTimeout then
  28.  
  29.     begin
  30.  
  31.       Inc(Timeouts);
  32.   // Do some sort of recovery here maybe
  33.     end;
  34. end;
  35.  
« Last Edit: November 19, 2015, 05:51:03 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

lonely_myp

  • New member
  • *
  • Posts: 9
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #107 on: November 23, 2015, 08:41:23 am »
 :(

unit1.pas(23,21) Error: Identifier not found "TBlockSerial"

Error on line - 
Code: Pascal  [Select][+][-]
  1. SynaSerComPort: TBlockSerial;
« Last Edit: November 23, 2015, 08:46:33 am by lonely_myp »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #108 on: November 23, 2015, 10:19:33 am »
hello,
have you added the synaser unit in the uses ?
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

lonely_myp

  • New member
  • *
  • Posts: 9
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #109 on: November 23, 2015, 04:22:12 pm »
Yes.
I find what's wrong, it does not work without Tlazserial component.

Example compile and run without error:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, LazSerial,
  9.   StdCtrls, ExtCtrls, ComCtrls,inifiles,Math, synaser;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.   private
  14.     { private declarations }
  15.   public
  16.     { public declarations }
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.   Timeouts : integer;
  22.   count:longint;
  23.     buf : array [0..128] of Byte;
  24.  
  25.     SynaSerComPort: TBlockSerial;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  begin
  31.   if SynaSerComPort = nil then
  32.  
  33.     SynaSerComPort:= TBlockSerial.Create;
  34.  
  35.   SynaSerComPort.LinuxLock:= False;
  36.   // ignore port locking in Linux
  37.   if not SynaSerComPort.InstanceActive then
  38.  
  39.     SynaSerComPort.Connect('/dev/ttyS1');  // or whatever com port (might be /dev/ttyUSB0 for Linux)
  40.   // add some delays to allow for serial port setup times
  41.  
  42.   sleep(500);
  43.  
  44.   SynaSerComPort.Config(19200, 8, 'N', SB1, False, False);
  45.  
  46.   sleep(300);
  47.  
  48.  
  49.     count:= SynaSerComPort.RecvBufferEx(@buf[0], 128, 500);  //Wait for 500ms per 128 byte packet
  50.     if SynaSerComPort.LastError = ErrTimeout then
  51.  
  52.     begin
  53.  
  54.       Inc(Timeouts);
  55.   // Do some sort of recovery here maybe
  56.     end;
  57.  
  58.  
  59. end.
  60.  


lonely_myp

  • New member
  • *
  • Posts: 9
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #110 on: December 02, 2015, 02:30:54 pm »
You have any ideas?
Why the example for the synaser is working, but not working for TLazSerial?

Bad code:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   LazSerial, synaser;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     BOpen: TButton;
  17.     LazSerial1: TLazSerial;
  18.     procedure BOpenClick(Sender: TObject);
  19.   private
  20.     { private declarations }
  21.   public
  22.     { public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.   Serial: TLazSerial;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.BOpenClick(Sender: TObject);
  36. begin
  37.      Serial.ShowSetupDialog;
  38.      Serial.Open;
  39. end;
  40.  
  41. end.

Good code:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, LazSerial,
  9.   StdCtrls, ExtCtrls, ComCtrls,inifiles,Math, synaser;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.   private
  14.     { private declarations }
  15.   public
  16.     { public declarations }
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.   Timeouts : integer;
  22.   count:longint;
  23.     buf : array [0..128] of Byte;
  24.  
  25.     SynaSerComPort: TBlockSerial;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  begin
  31.   if SynaSerComPort = nil then
  32.  
  33.     SynaSerComPort:= TBlockSerial.Create;
  34.  
  35.   SynaSerComPort.LinuxLock:= False;
  36.   // ignore port locking in Linux
  37.   if not SynaSerComPort.InstanceActive then
  38.  
  39.     SynaSerComPort.Connect('/dev/ttyS1');  // or whatever com port (might be /dev/ttyUSB0 for Linux)
  40.   // add some delays to allow for serial port setup times
  41.  
  42.   sleep(500);
  43.  
  44.   SynaSerComPort.Config(19200, 8, 'N', SB1, False, False);
  45.  
  46.   sleep(300);
  47.  
  48.  
  49.     count:= SynaSerComPort.RecvBufferEx(@buf[0], 128, 500);  //Wait for 500ms per 128 byte packet
  50.     if SynaSerComPort.LastError = ErrTimeout then
  51.  
  52.     begin
  53.  
  54.       Inc(Timeouts);
  55.   // Do some sort of recovery here maybe
  56.     end;
  57.  
  58.  
  59. end.


Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #112 on: December 02, 2015, 06:16:59 pm »
hello,
something is wrong in your project :  SIGSEGV when calling  ShowSetupDialog;

with a new project  : a form with a tlazserial component, and a button to call ShowSetupDialog : no crash ( see attachment )
I need more time to investigate the  problem  %) .     

Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #113 on: December 02, 2015, 06:32:48 pm »
 ;)   i have found your error :   
TLazserial component on the form is Lazserial1 not Serial

Serial is not initialized  and when you call  Serial.ShowSetupDialog; you have a sigsegv
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

AD

  • Newbie
  • Posts: 2
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #114 on: December 05, 2015, 01:10:31 pm »
1.) Thanks for the Lazserial, great work. I wish it would be included in the Laz.distribution package, because the installation needs some hands on. To have it work for me, I needed to point the poject inspector to the location of "LazSerialPort.pas". Now the compiler gives me the warning: "other unit files search path (aka unit path) of... contains: \lararus\components\Lazserial. Maybe my fault, since I am an absolute Lazarus newbie(noob).
Anyway, it works now, thanks alot again for the great piece of software.

2.) I noticed that I am loosing characters on the RS232, whenever "Windows-Defender" is running, regardless of UART configuration/speed/workload/etc... Setup: IntelAtom Win10home-32bit with a RS232/USB converter with FT232 chipset. It's not Lazarus(Serial) fault, but is there a workaround?

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #115 on: December 05, 2015, 01:47:09 pm »
hello AD,

1 - have you used the following guide to install the component ? :

Quote
How to install the component ( lazarus version >=  1.x) : 

1 - Download the file LazSerial.7z (you must be logged in the forum  to see and download the file).

2 - Open the file and uncompress it in the Lazarus/components directory.

3 - Open Lazarus IDE ,  Open the package ( packages/open a package file) LazSerialPort.lpk

4 - Compile

5 - Install

2 - Are you using the last driver from FTDI ?
When you disable windows defender are you loosing characters ?
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

AD

  • Newbie
  • Posts: 2
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #116 on: December 05, 2015, 04:15:17 pm »
Hello JP,
yes, I 'RTFM' ;), that's how I installed it in LZ1.4.2, after that way of installing it, it gave me when compiling a program the first time an "'LazSerialPort' not found error". Sorry, I cant remember what it was exactly. That error message went away, only after using the projectinspector.
I just removed the path from the projectinspector, voila, now it works without the earlier added path and compiles without any warnings. Again, might have been my mistake (maybe because I tried to use synaser additionally in the 'uses' declaration (sometimes mentioned here in the discussion), what I should not have done/needed).

The FT232 drivers I had been using, were from something beginning 2015, which came with Win10-"Out-Of-The-Box". I just checked, and you're right, there are newer ones. I just updated to version 2.8.30.0 dated 08.07.2015. Now it works perfectly, even without tweaking inside the driver setup, not loosing any characters at all, even with heavy system workload on the weak IntelAtom. Thanks for the hint.

Two more question: Right now, I am using only the OnRxData event for receiving chunks of incoming bytes via LazSerial.ReadData. Is there a way to know, if or which of the byte(s) that I read had frame or parity error(s)? Or will the badly transmitted bytes be skipped and only the OnStatus event be raised?
Another thing: When trying to open a none existing COM the debugger raises an exception, when continuing, message says that "pressing Ok might risk data corruption", normal, or how to avoid that?
Is there some detailed documentation (of the (class)interface) of LazSerial somewhere that I havent found, so I would not bother putting up those (dumb) questions?
Thanks again, really appreciated.
Greets, AD
P.S. My native language is also not english ;)

lonely_myp

  • New member
  • *
  • Posts: 9
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #117 on: January 26, 2016, 09:07:23 am »
;)   i have found your error
Oh thank you.
it works now.

for some reason I thought that if I wrote:
Quote
var
  Serial: TLazSerial;
it will be OK.

Thanks again, I will continue my project =)

jiji66

  • Newbie
  • Posts: 1
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #118 on: February 15, 2016, 08:49:31 am »
It could be nice to have that kind of component included in the Lasarus default installation.

jb007

  • Full Member
  • ***
  • Posts: 145
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #119 on: July 18, 2016, 10:36:59 am »
Hi,

 tnx for this Lazarus-forum-item.

Got the whole stuf compiled/installed/Lazarus-rebuild.

My question is:

What do I use/need from all the stuff for just an easy RS232-communication between Lazarus
and a mikrocontroller. I don't need that GPS-example.


By the way, got my Arduino2560 ( using mikroPAscal ) allready usable for RS232.
Using wires: RX and TX.
The PC-mikroPascal-IDE-USARTterminal and my Arduino are allready communicating in both ways
with a native RSR232-port at my PC and a MAX232-convertor-pcb to my Arduino.

LCD at Arduino is displaying the received string from PC-mikroPAscal-IDE-USARTterminal , and sends it back to PC-mikroPascal-IDE-USARTterminal and displays it.
 

Thanks in advance.
Marcel
to DIY or not to DIY

 

TinyPortal © 2005-2018