Lazarus

Programming => Packages and Libraries => Topic started by: Jurassic Pork on April 03, 2013, 03:53:33 am

Title: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on April 03, 2013, 03:53:33 am
TLazSerial          EDIT  (02/2021) :   new version v0.4 in Github here (https://github.com/JurassicPork/TLazSerial)   and OPM
Serial Port Component for Lazarus (windows and linux).
by Jurassic Pork  03/2013
This library is Free software; you can rediStribute it and/or modify it
  under the terms of the GNU Library General Public License as published by
  the Free Software Foundation; either version 2 of the License, or (at your
  option) any later version.

  This program is diStributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; withOut even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  for more details.

  You should have received a Copy of the GNU Library General Public License
  along with This library; if not, Write to the Free Software Foundation,
  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. }

 Based on  :
- SdpoSerial v0.1.4
  CopyRight (C) 2006-2010 Paulo Costa
   paco@fe.up.pt
 
- Synaser library  by Lukas Gebauer
- TcomPort component


Features :
Changed :  baudrate values.
           stop bits  new value : 1.5
new event : onstatus
new property FRcvLineCRLF : if this property is true, you use RecvString
in place of RecvPacket when you read data from the port.

new procedure  ShowSetupDialog to open a port settings form :
the device combobox contain the enumerated ports.
new procedure to enumerate real serial port on linux ( in synaser).

Demo : a simulator of serial port gps + serial port receiver :
you can send NMEA frames ( GGA GLL RMC) to the opened serial port
(start gps simulator). You can change speed and heading.
In the memo you can see what is received from  the opened serial port.
In the status bar you can see the status events.

tested with windows 7 and Ubuntu 12.04
                                       
if you haven't serial ports in your PC you can use virtual ports :
1 - WINDOWS
To simulate  a paired serial ports on  windows : com0com   

2 - Linux
To simulate  a paired serial ports on linux : socat
ex :  socat -d -d PTY: PTY:

To connect to a bluetooth GPS on Linux
echo connection to a  bluetooth GPS(/dev/rfcomm0)

sudo rfcomm bind  0 xx:xx:xx:xx:xx:xx 1

====================================================================
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

====================================================================

Sorry for my poor english but it isn't my natural language.

to be continued if it is usable ....

                    J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: herux on April 03, 2013, 04:54:53 am
yes this is very useful
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Awesome Programmer on May 30, 2013, 05:41:30 pm
 :D :) Yes this is very very very useful tool. Thanks, J.P. for making it available to the Lazarus community.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: vruz on July 07, 2013, 07:22:06 am
Thanks a lot JP, this will be very useful. :D
Cheers!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: marcov on July 07, 2013, 04:16:48 pm
Components under GPL are not ideal.  Usually units/components are LGPL (and preferably with exception, like FPC and Lazarus themselves)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Leledumbo on July 07, 2013, 05:40:28 pm
Quote
Components under GPL are not ideal.  Usually units/components are LGPL (and preferably with exception, like FPC and Lazarus themselves)
Isn't it LGPL already? With different L, if I'm not mistaken...
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BigChimp on July 07, 2013, 06:00:47 pm
Yep, see JP's original post:
Quote
GNU Library General Public License
=LGPL, right?!?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Leledumbo on July 07, 2013, 06:21:58 pm
Quote
=LGPL, right?!?
the real LGPL has L stands for Lesser, not Library
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: marcov on July 07, 2013, 07:54:49 pm
Quote
=LGPL, right?!?
the real LGPL has L stands for Lesser, not Library

(it was my mistake I read over the original).

But afaik it was library originally, and GNU tried to rechristening it to lesser because they wanted to make some point, just like GNU tried to redefine the word free.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on July 08, 2013, 03:00:40 am
hello everybody,
the component has  "GNU Library General Public License"  which is also the  "GNU Lesser General Public License or LGPL"

look at   :o  here :
The GNU Lesser General Public License or LGPL (formerly the GNU Library General Public License)  (http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License)

I am Jurassic, so i use formely licenses  :D

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: serfi-laz on July 17, 2013, 02:37:40 pm
Unfortunately, don't know how to adapt this component for WinCE platform.. Maybe someone has idea how to do it without manual thread-magic?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BigChimp on July 17, 2013, 03:09:23 pm
I am Jurassic, so i use formely licenses  :D
Good motivation - ROFL ;)
(also thanks for clarifying this for people who did not know)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 18, 2013, 09:09:49 pm
Hi, I am new to this board. Where can I download TLazSerial? I can't find it anywhere!! Thanks
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on July 18, 2013, 11:44:10 pm
hello BLL,

you can find the download of TLazSerial in attachments (lazserial.7z) of this message :
http://forum.lazarus.freepascal.org/index.php/topic,20481.msg118267.html (http://forum.lazarus.freepascal.org/index.php/topic,20481.msg118267.html)

You must be logged to see and download attachments in the forum.

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 20, 2013, 05:07:28 pm
Thank you for the reply. I have now downloaded it. In which sub-directory should the files be placed, please?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on July 20, 2013, 05:32:06 pm
you can place the directory lazserial in the components sub-directory of lazarus and install the package.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 20, 2013, 07:59:20 pm
Hi, I have done that and it's a disaster. When trying to open sertest.lpi, I get an error dialogue " unable to find unit of component class TLazSerial" Oh why, oh why can't there be some installation instructions. Not everyone starting out with Lazarus is an expert!! I now have NO IDEA how to proceed! :'(
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on July 20, 2013, 11:41:52 pm
what is your version of lazarus ? Operating system ? have you really installed the package lazserialport ( lazserialport.lpk) ? do you see this package in the installed package list ? the example sertest needs that this package be installed.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 21, 2013, 11:05:43 am
Hi, Thanks for the reply. I have Lazarus 0.9.28.2. I have it on 2 machines. This one is a WinXP machine. I also have a Raspberry Pi with raspbian. I was hoping to get it working on the PC first and then install on the RasPi. In the package list is lazserialport 0.0. When I installed that it asked to recompile Lazarus and it did so. I still get that same error trying to open sertest, so as I say, I am lost! The program I am writing needs to read data from a gps on ttyUSB0 on the Pi.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on July 21, 2013, 01:02:11 pm
sorry, i haven't an old lazarus version to check the package with it. Strange thing is that you say that you have lazserialport 0.0 ? the version of the package is 0.1  ( see attachment)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 21, 2013, 09:43:20 pm
I am on this version of Lazarus because of the RasPi's OS apparently. No idea why it should say 0.0! Could the error message relate to it not finding the path to the file it requires? I have come from CBuilder and there you could set paths for components. It also showed invalid paths by greying them out but I can't find anything like that in Lazarus.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on July 22, 2013, 01:59:47 am
i have tried lazserial with lazarus 0.9.28.2  fpc 2.4.0 on virtualbox ubuntu lucid 10.04   32 bits.

the only error that i had, was with the method "start" of tthread  (put resume for fpc 2.4.0)

then i could compile sertest without errors. So have you errors during this stages  ? :

1 - Open the package ( packages/open a package file) LazSerialPort.lpk ?
2 - Compile
3 - Install

 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 22, 2013, 11:07:52 pm
Steps 1 - 3 go fine. It asks to rebuild Lazarus and does so fine. However, if I close Lazarus and then reopen it, it reloads sertest. If you then do run, you get the error message "unable to find the unit of component class TLazSerial". It gives 3 options, all stop it dead!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on July 23, 2013, 12:27:06 am
Search for  lazserial.ppu and tell me in which folder is this file.

Tell me the complete path where are the ppu files of the units of Lazarus

lazarus/units/????/????/

Have you change in the options of the package lazserialport the target and cpu for your target ?


Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: avra on July 23, 2013, 08:30:19 am
I have Lazarus 0.9.28.2. I have it on 2 machines. This one is a WinXP machine. I also have a Raspberry Pi with raspbian. I was hoping to get it working on the PC first and then install on the RasPi.
You don't have to stick with 0.9.28.2 because of Raspbian. Take a look at this: http://forum.lazarus.freepascal.org/index.php/topic,20803.msg121127.html#msg121127
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 23, 2013, 11:37:23 am
Hi, Thanks for that. I will look into it. My current version was the one I was directed to for the Pi on the Lazarus download site!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 23, 2013, 02:04:57 pm
I have installed Lazarus 1.0.6 on the PC and LazSerial installs fine and the test app works. However, nowhere can I find out clearly how to install 1.0.6 on the Raspberry Pi with Raspbian. apt-get install lazarus gives me the same 0.9.28.2 version, so I seem stuck!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 23, 2013, 04:16:55 pm
Interestingly, I tried installing TLazSerial on the RasPi - not good - 22 errors trying to compile the component! Surely, there must be a way to read the default gps port 2947, which is ttyUSB0 from pascal? It can be done in python, C and C#, but not, apparently, in pascal on the PI!! Talk about frustrating!! :'(
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Rails on July 23, 2013, 04:44:28 pm
I have installed Lazarus 1.0.6 on the PC and LazSerial installs fine and the test app works. However, nowhere can I find out clearly how to install 1.0.6 on the Raspberry Pi with Raspbian. apt-get install lazarus gives me the same 0.9.28.2 version, so I seem stuck!

The Debian Raspbian repository seems to contain only Wheezy (Stable) packages. Apparently, things haven't progressed to the point that they are in a position  to offer Testing or Unstable repos to their users. i386 Testing currently has Laz 1.0.10, while Stable is at 9.30.4.

Perhaps you can build from source?
 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 23, 2013, 05:04:37 pm
I am a newbie to Linux and the RasPi, so I have absolutely no idea how to go about building from source! I can't believe that no-one has found a way to talk to a USB port in fpc on the PI!!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: avra on July 24, 2013, 11:40:38 pm
I have installed Lazarus 1.0.6 on the PC and LazSerial installs fine and the test app works. However, nowhere can I find out clearly how to install 1.0.6 on the Raspberry Pi with Raspbian. apt-get install lazarus gives me the same 0.9.28.2 version, so I seem stuck!
The link I gave says this:
Quote
...you might try to install FPC from repository, and then install Laz 1.0.6 from source (I think that was the last version that could be compiled with FPC 2.6.0)
This means that FPC is installed through apt-get (as you already did), and Lazarus from source as in wiki described here:
http://wiki.lazarus.freepascal.org/Installing_Lazarus#Downloading_Lazarus_Source_Code. You need to have subversion installed first, of course.

This might also help:
http://www.michellcomputing.co.uk/blog/2012/11/lazarus-on-the-raspberry-pi/
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 25, 2013, 06:30:54 pm
Hi, Thanks for that. In the second link, I see that he installs fpc 2.6.0 from the repository, then updates it to 2.7 and then installs Lazarus 1.0.6. He provides 2 scripts to do this but I gather they have mistakes in them! I will give it a try with a fresh installation of Raspbian as soon as I get the time. Thanks for your help. I did also have the thought that the gps daemon makes the gps info available at local port 2947. Is there a function in fpc to open a local port? That saves messing around with USB!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: lu7hz on July 31, 2013, 02:58:26 pm
Likely to be a dumb question, but where I could download TLazSerial from?

I'm in the process to migrate my Delphi stuff into Lazarus and quite not yet familiar with the structure of the different resources.

Thanks in advance! Pedro
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BLL on July 31, 2013, 03:07:06 pm
If you are using a raspi, forget TLazSerial as it won't install. Nor will 5dpo!!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on July 31, 2013, 03:21:28 pm
hello,
if you are on Windows or linux and with Lazarus >= 1.x  , look at the first post of this topic and read the how to install.

Friendly J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: avra on August 01, 2013, 11:26:45 am
If you are using a raspi, forget TLazSerial as it won't install. Nor will 5dpo!!
Try Synaser from synapse.ararat.cz, or just use FPC serial unit instead (search for serial.pp file since that's all docs you will get for it).
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: ireverse on August 10, 2013, 12:13:35 pm
Thanks ever so much, I've been looking for such a component since a year!! nice work. Just installed and tested on CodeTypon 4.41.
MfG.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: wylton on August 20, 2013, 12:46:49 am
i don't have serial port, how can i make port like you use '/dev/pts/5' ? i'm in linuxmint.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on August 20, 2013, 04:04:41 am
hello,

1 - install socat in your linux distro
2 - launch this command in a terminal :
Code: [Select]
socat -d -d PTY: PTY:if it is good you can see in your terminal window something like this :
Quote
2013/08/20 03:41:03 socat[4275] N PTY is /dev/pts/5
2013/08/20 03:41:03 socat[4275] N PTY is /dev/pts/6
2013/08/20 03:41:03 socat[4275] N starting data transfer loop with FDs [3,3] and [5,5]

if you have successfully compiled the example of lazserial  sertest:
1 -  launch sertest
2 - in port settings/port enter your first virtual serial port ( ex for me /dev/pts/5)  don't use combo button because virtual serial ports are not detected)
3 - close the port settings window and click on the open button.

4 - launch another sertest
5 - in port settings/port enter your second virtual serial port ( ex for me /dev/pts/6)
6 - close the port settings window and click on the open button.

7 - in your first sertest check RMC and click on the start simulator button.
8 - if all is good , you can see RMC frames in the memo of the second sertest  like this :
Quote
$GPRMC,035654,A,4851.184,N,00220.977,E,000.5,054.7,200813,020.3,E*71

friendly, J.P



Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: wylton on August 20, 2013, 10:32:54 am
thanks.

other question:
I have a Epson Tm 70 connect to Usb, and have virtual port ESDPRT001, can I use Lazserial to communicate with it?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: freris on October 07, 2013, 09:20:51 pm
Dear friend, have a good day from Athens - Greece.

Can you please provide me the link for the component?

Many many thanks

Panagiotis
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Paul Breneman on October 08, 2013, 05:01:55 am
I'd like to port www.CtrlTerm.com to LazSerial and Lazarus, so if anyone sends me code I will consider publishing it.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: eldonfsr on December 14, 2013, 03:32:53 am
Hi jurassic do you know how to emulate delay line and delay character with synaser, i sow documentation but only one function is  about delay time , sorry for my topic?

thanks.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 on December 14, 2013, 02:12:55 pm
Mr. Pork,
I tried several libs, before getting to this one, and the good thing about is that it really works.
What bothers me is that usually a timeout can be set, but I saw nothing like that in TLazSerial.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: eldonfsr on December 24, 2013, 10:37:31 pm
I tried to compile lazserial on mac and send this error

/Developer/lazarus/componentes/LazSerial/synaser.pas(1959,54) Error: Incompatible types: got "ShortInt" expected "Pointer"
/Developer/lazarus/componentes/LazSerial/synaser.pas(2345,41) Warning: range check error while evaluating constants
/Developer/lazarus/componentes/LazSerial/synaser.pas(2348,36) Hint: Mixing signed expressions and longwords gives a 64bit result
/Developer/lazarus/componentes/LazSerial/synaser.pas(2358,38) Error: Identifier not found "TIOCGSERIAL"
/Developer/lazarus/componentes/LazSerial/synaser.pas(2387) Fatal: There were 2 errors compiling module, stopping
some body compiled that on mac.

best regards.
fernando
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: VTwin on January 29, 2014, 10:47:50 pm
Quote
I tried to compile lazserial on mac and send this error

/Developer/lazarus/componentes/LazSerial/synaser.pas(1959,54) Error: Incompatible types: got "ShortInt" expected "Pointer"
/Developer/lazarus/componentes/LazSerial/synaser.pas(2345,41) Warning: range check error while evaluating constants
/Developer/lazarus/componentes/LazSerial/synaser.pas(2348,36) Hint: Mixing signed expressions and longwords gives a 64bit result
/Developer/lazarus/componentes/LazSerial/synaser.pas(2358,38) Error: Identifier not found "TIOCGSERIAL"
/Developer/lazarus/componentes/LazSerial/synaser.pas(2387) Fatal: There were 2 errors compiling module, stopping
some body compiled that on mac.

best regards.
fernando

I'm having similar problems compiling for Mac. I am currently using Lazarus 1.0.14 on OS X 10.8.5. Anyone have any luck on the Mac? I'd greatly appreciate any assistance on resolving this.

Cheers,
Frederick 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on January 29, 2014, 11:33:16 pm
hello,
look for this patch (https://www.mail-archive.com/synalist-public@lists.sourceforge.net/msg03504.html) for synaser.pas.

Code: [Select]
{$IFDEF DARWIN}
  const // From fcntl.h
    O_SYNC = $0080;  { synchronous writes }
+ { FIOSSIOSPEED is from /System/Library/Frameworks/IOKit.framework/Versions/A/Headers/serial/ioss.h
+   Its definition will be in $FPC/rtl/darwin/termios.inc soon with any luck. For details see:
+   http://lists.freepascal.org/lists/fpc-pascal/2011-August/030025.html }
+   FIOSSIOSPEED = (IOC_IN or (sizeof(culong) and IOCPARM_MASK) << 16) or ((ord('T') << 8) or 2); { 18399.13 }
  {$ENDIF}
.....
+ {$IFDEF DARWIN}
+ { Use FIOSSIOSPEED to assign the baud rate directly. This overides the
+   baud rate assigned via the cfsetXspeed functions above but they must
+   still be called to assign valid control flag values in the termios }
+   SerialCheck(fpIoctl(integer(FHandle), FIOSSIOSPEED, @dcb.BaudRate));
+   ExceptCheck;
+ {$ELSE}
....

and
Code: [Select]
//SerialCheck(fpioctl(FHandle, TCIOflush, TCIOFLUSH));
   SerialCheck(fpioctl(FHandle, TCIOflush,Pointer(PtrInt(TCIOFLUSH))));

i haven't Mac os , i can't verify

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Paul Breneman on January 29, 2014, 11:38:27 pm
The Lazarus port here uses Synapse (SynaSer):
http://ctrlterm.com/ports.htm

I haven't tested that on OS X so I'd appreciate any feedback.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: VTwin on January 31, 2014, 09:48:47 pm
Jurassic Pork,

Many thanks for supplying this code!

I could not get that patch to work on the version of synaser.pas in your LazSerial.7z, however I went through it by hand to apply the patch.

Then I added this:
Code: [Select]
const
  TIOCGSERIAL  = $541E; //// defined in oldlinux.ppp line 1034

In LazSerial I made this change:
Code: [Select]
uses
//// {$IFDEF LINUX}
{$IFDEF UNIX} //// !
  Classes,
{$IFDEF UseCThreads}
  cthreads,
{$ENDIF}
{$ELSE}
  Windows, Classes, //registry,
{$ENDIF}   

I was then able to install LazSerial and get 'sertest' to run. I have not had the opportunity to test it reading data from a port however. I will post on my success, or lack thereof.

If anyone else has worked on this code, I'd appreciate any help. I am no expert serial communications.  :)

Cheers,
Frederick
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: VTwin on January 31, 2014, 10:02:26 pm
Paul,

Thanks!

I see the version of synazer.pas in CtrlTerm is 007.005.005 (2013), so I should have used this instead of 007.005.002 (2011) supplied by Jurasssic. I will see if I can get the CtrlTerm project to compile. Maybe that is a better starting point.

It does not compile as is, but I can see if the patch works for Darwin. If anyone has a patch file for 007.005.005 that would be very helpful. :)

All I need to do is read a stream of bytes from a COM port, which is connected from a counter with a RS-232 to USB converter.

Any suggestions are greatly appreciated.

Cheers,
Frederick
Title: Re: TLazSerial : High CPU?
Post by: bsg55 on February 13, 2014, 09:10:28 am
First off, thanks for LazSerial, excellent work.
Has anyone noticed a high CPU after you open a port with LazSerial? I have been previously using synaser without the high CPU issue, LazSerial seems to be better in terms of controlling read data IMHO.
I have an Atom D425 proc (Acer N281G) and CPU jumps to ~70% and stays there until I close the port....very odd....even with no device connected it does the same. I must be doing something wrong? I am on Lubuntu 14.04 using Lazarus 1.0.10+dfsg-1 and LazSerial v0.1.
Any pointers would be much appreciated.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: JZS on February 13, 2014, 09:35:11 am
Thank you J.P for this component.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Motherjoker on February 15, 2014, 06:16:01 pm
Hi!
I've just successfully installed Lazarus 1.0.10 (from Raspberry's jessie repo) on my Raspberry Pi and I'm trying to compile TLazSerial, but it fails

It gives me these errors
/usr/lib/lazarus/1.0.10/components/LazSerial/synaser.pas(252,22) Error: Identifier not found "B500000"
one for each B* constant higher than 230400

If I remove these lines (I need only 115200) it gives me another error
../lazutils/masks.pas(29,22) Fatal: Can't find unit contnrs used by Masks

What can I do?
Thanks for your help
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: taazz on February 15, 2014, 06:24:11 pm
B500000 it seems like a constant value in hex so it must have a dollar in front ($). If it doesn't then something is wrong with the unit.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Motherjoker on February 19, 2014, 03:13:33 pm
B500000 it seems like a constant value in hex so it must have a dollar in front ($). If it doesn't then something is wrong with the unit.

It compiles correctly the others B* lower than 230400
I can remove these lines, I don't need higher baudrates, but I can't still compile it
../lazutils/masks.pas(29,22) Fatal: Can't find unit contnrs used by Masks
What can I try?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Motherjoker on February 21, 2014, 01:22:50 am
Done!
It wasn't easy, so I'm sharing here my experience
You can do everything in a remote session; on linux you can use
$ ssh -X <username>:<IP>

-- How to install Lazarus 1.0.10 (or newer) on a Raspberry Pi (Raspbian) --

First, get a sudo shell
$ sudo -s

If you want to install the latest version and you have already installed another version, you have to remove it
If not, skip this step
WARNING: THIS WILL NUKE ALSO EVERY CONFIGURATION RELATED TO THESE PACKAGES! CHECK THAT ONLY UNNEEDED PACKAGES ARE GOING TO BE REMOVED

# apt-get purge lazarus-* fpc-* fp-compiler* fp-units-* fp-ide-* fp-utils-*

Now you need to add jessie's repo to sources.list

# echo 'deb http://archive.raspbian.org/raspbian jessie main rpi' >> /etc/apt/sources.list
# echo 'deb-src http://archive.raspbian.org/raspbian jessie main rpi' >> /etc/apt/sources.list
# apt-get update

And now you can install lazarus and fpc from jessie's repo (check that it's installing the right version, at the time of writing it is the 1.0.10)
This will likely update lots of packages, including libc; read carefully what you're updating!

# apt-get -t jessie install fpc lazarus

You haven't finished yet! The 1.0.10 package is broken, you have to fix it manually (change the path if your version isn't the 1.0.10)
Note: with the revision 44182 it works, if you want you can try newer revisions

# apt-get install subversion
# svn export http://svn.freepascal.org/svn/lazarus/trunk/components/leakview/leakview.lpk --revision 44182
# mv leakview.lpk /usr/lib/lazarus/1.0.10/components/leakview/
# svn export http://svn.freepascal.org/svn/lazarus/trunk/components/leakview/dbginforeader.pas --revision 44182
# mv dbginforeader.pas /usr/lib/lazarus/1.0.10/components/leakview/

Now Lazarus should work, but the IDE may complain about a broken ide/version.inc
In this case, just look at the title bar and edit /usr/lib/lazarus/1.0.10/ide/version.inc (I edited mine from '1.0.10+dfsg-1' to '1.0.10+dfsg-1+b1')
Restart Lazarus and everything should work!


-- How to install a package on a Raspberry Pi (Raspbian) --

Download the package, extract it and copy it in the components folder (/usr/lib/lazarus/1.0.10/components/)
Edit owner, group and permissions

$ sudo chown root /usr/lib/lazarus/1.0.10/components/<package>
$ sudo chgrp root /usr/lib/lazarus/1.0.10/components/<package>
$ sudo chmod +r /usr/lib/lazarus/1.0.10/components/<package>
$ sudo chmod +x /usr/lib/lazarus/1.0.10/components/<package>

The Raspberry Pi doesn't have enough memory to recompile the whole IDE, so you need to add a swap
Take an empty USB memory (at least 1GB) and insert it in the Raspberry Pi

$ df

Find which /dev it is (for me it was /dev/sda1)
WARNING: THIS WILL DELETE EVERY FILE ON YOUR USB MEMORY

$ sudo mkswap /dev/sda1
$ sudo swapon /dev/sda1

Now you have a good amount of swap memory; you can check it with

$ cat /proc/swaps

Now start the IDE with root permissions

$ gksudo lazarus-ide

Packages -> Install/Uninstall packages -> select your package on the right -> install selection -> Save and rebuild IDE
After a (long) wait your package will be compiled and installed!


-- Additional steps for LazSerial --

LazSerial's installation may fail with this error
/usr/lib/lazarus/1.0.10/components/LazSerial/synaser.pas(252,22) Error: Identifier not found "B500000"
If you don't need highest baudrates you can remove them: comment/remove these lines
    ,(500000, B500000),
    (576000, B576000),
    (921600, B921600),
    (1000000, B1000000),
    (1152000, B1152000),
    (1500000, B1500000),
    (2000000, B2000000),
    (2500000, B2500000),
    (3000000, B3000000),
    (3500000, B3500000),
    (4000000, B4000000)
and change this
    MaxRates = 30; //UNIX
to this
    MaxRates = 19; //UNIX
If you need them, I don't know... ;)
Now the installation should work
Note that now you can use only baudrates up to 460800


I hope this can help someone! :)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: engkin on February 21, 2014, 03:01:15 am
LazSerial's installation may fail with this error
/usr/lib/lazarus/1.0.10/components/LazSerial/synaser.pas(252,22) Error: Identifier not found "B500000"
If you don't need highest baudrates you can remove them: comment/remove these lines
    ,(500000, B500000),
 ..
    (4000000, B4000000)
and change this
    MaxRates = 30; //UNIX
to this
    MaxRates = 19; //UNIX
If you need them, I don't know...
Obviously you put a lot of effort to achieve this. Thanks for sharing.
B constants are defined in rtl\linux\termios.inc for different CPUs.
To solve this "Error: Identifier not found "B500000""
Add the missing ones somewhere between {$ifdef cpuarm} and {$endif cpuarm}:
Code: Text  [Select][+][-]
  1. {$ifdef cpuarm}
  2. ..
  3.    B500000 = $0001005;
  4.    B576000 = $0001006;
  5.    B921600 = $0001007;
  6.    B1000000= $0001008;
  7.    B1152000= $0001009;
  8.    B1500000= $000100A;
  9.    B2000000= $000100B;
  10.    B2500000= $000100C;
  11.    B3000000= $000100D;
  12.    B3500000= $000100E;
  13.    B4000000= $000100F;
  14. ..
  15. {$endif cpuarm}
  16.  

They are missing for cpusparc as well.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Motherjoker on February 21, 2014, 11:13:48 am
If I edit /usr/share/fpcsrc/2.6.2/rtl/linux/termios.inc it still complains about missing constants; do I have to recompile anything?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: engkin on February 21, 2014, 03:52:06 pm
I should clarify that this is merely a guess.

Make sure that it is added in the right place and the IDE sees it. Use "Find Declaration" on both: a previously working B constant and a newly added one, that should take you to the right file and the right location. From what I see termios.inc structure is as follows:

Quote from: rtl/linux/termios.inc
Const
..

{$ifdef cpupowerpc}
..
{$endif cpupowerpc}

{$ifdef cpui386}
..
{$endif cpui386}

{$ifdef cpusparc}
..
{$endif cpusparc}

{$ifdef cpux86_64}
..
{$endif cpux86_64}

{$ifdef cpuarm}
..
// missing B constants should go in here
{$endif cpuarm}


{$if defined(cpumips) or defined(cpumipsel)}
..
{$endif CPUMIPS}

{$ifdef CPUM68K}
..
{$endif CPUM68K}
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Motherjoker on February 21, 2014, 06:28:00 pm
If I edit termios.inc the IDE can see the constant, but the compiler stills complains
I can compile it replacing each B constant with its value (ex. B500000 with $0001005), but it's not a clean solution (and I didn't tried if it really works)
Those constants aren't defined in the ARM section of termios.inc, maybe they're just not supported on ARM (and sparc)
If someone finds a working method, please let me know!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: engkin on February 21, 2014, 10:59:02 pm
If I edit termios.inc the IDE can see the constant, but the compiler stills complains
The compiler does not know about these changes, yet.

Those constants aren't defined in the ARM section of termios.inc, maybe they're just not supported on ARM (and sparc)
If someone finds a working method, please let me know!
Hardware wise they are supported. Software wise, it might need some changes, and since you replaced the constants with their values and TLazSerial did not complain about it that means it does not support these speeds as well. If you do not need these speeds then you might as well delete the constants as you had done.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: VTwin on March 08, 2014, 06:33:10 pm
Paul,

Thanks!

I see the version of synazer.pas in CtrlTerm is 007.005.005 (2013), so I should have used this instead of 007.005.002 (2011) supplied by Jurasssic. I will see if I can get the CtrlTerm project to compile. Maybe that is a better starting point.

It does not compile as is, but I can see if the patch works for Darwin. If anyone has a patch file for 007.005.005 that would be very helpful. :)

All I need to do is read a stream of bytes from a COM port, which is connected from a counter with a RS-232 to USB converter.

Any suggestions are greatly appreciated.

Cheers,
Frederick

Just an update on my progress. I had no luck compiling CtrlTerm on OS X, and was having some trouble installing LazSerial. I run Lazarus on Windows, OS X, and Linux, and I'm not very familiar with using packages. So I just used synaser 007.005.005 and made this fix:

Code: [Select]
{$IFNDEF FPC}
  FHandle := THandle(Libc.open(pchar(FDevice), O_RDWR or O_SYNC));
{$ELSE}
  FHandle := THandle(fpOpen(FDevice, O_RDWR or O_SYNC or O_NONBLOCK)); //// FWV
{$ENDIF}

I made a wrapper class to open and close the port, and read incoming data. I call it from a timer and have it working on Windows and OS X. Nothing fancy, but it does what I need.

Thanks for the input!

Cheers,
Frederick

 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BigChimp on March 18, 2014, 01:23:21 pm
Please post any (OSX) patches for synaser to the Synapse mailing list [1] so the fixes can be incorporated in the next official Synapse version.

Thanks!
[1] See
http://www.ararat.cz/synapse/doku.php/support
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: vonskie on March 18, 2014, 01:24:37 pm
Paul,

Thanks!

I see the version of synazer.pas in CtrlTerm is 007.005.005 (2013), so I should have used this instead of 007.005.002 (2011) supplied by Jurasssic. I will see if I can get the CtrlTerm project to compile. Maybe that is a better starting point.

It does not compile as is, but I can see if the patch works for Darwin. If anyone has a patch file for 007.005.005 that would be very helpful. :)

All I need to do is read a stream of bytes from a COM port, which is connected from a counter with a RS-232 to USB converter.

Any suggestions are greatly appreciated.

Cheers,
Frederick

Just an update on my progress. I had no luck compiling CtrlTerm on OS X, and was having some trouble installing LazSerial. I run Lazarus on Windows, OS X, and Linux, and I'm not very familiar with using packages. So I just used synaser 007.005.005 and made this fix:

Code: [Select]
{$IFNDEF FPC}
  FHandle := THandle(Libc.open(pchar(FDevice), O_RDWR or O_SYNC));
{$ELSE}
  FHandle := THandle(fpOpen(FDevice, O_RDWR or O_SYNC or O_NONBLOCK)); //// FWV
{$ENDIF}

I made a wrapper class to open and close the port, and read incoming data. I call it from a timer and have it working on Windows and OS X. Nothing fancy, but it does what I need.

Thanks for the input!

Cheers,
Frederick

Your my hero that patch fixed the problem!

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Paul Breneman on March 18, 2014, 02:31:28 pm
I'm glad to know that Synaser is now working on the Mac for  you.  I will try to follow up on the Synapse mailing list to get the change made in Synapse for everyone.

Does the CtrlTerm port for Lazarus compile OK?  If it compiles and runs, does it show the ports that are available?  I'm thinking there are other Synaser changes needed for the Mac to get the ports listed OK.  If you could email me the source code vonskie I'd sure appreciate it.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: avra on March 31, 2014, 03:00:37 pm
@Jurrasic:

Tried to install LazSerial but it has a conflict with Synapse in CT/WinXP. Ignore button did not help. I had to delete units synafpc, synaser and synautil from LazSerial dir and to add synapse to the list of LazSerial required packages. After that compilation has passed and demo seams to work well at first sight (GPS data received at the other end).

Shouldn't borrowed Synapse units have some prefix in filenames and classes to avoid situations like this, if you had to include them? You should take a look at IFDEF changes made by CT to synapse units to support more platforms.

Thanks for your work!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on March 31, 2014, 05:32:52 pm
hello Avra,
i had the same problem with CT. To avoid this, i have renamed all the synaser pascal source code. For example synaser.pas becomes  mysynaser.pas. I have a version with this, but not sure that it works because not use since a long time. You can try it.   

Friendly J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Geoff_S on April 11, 2014, 09:27:46 am
Is there a way to get the current baud rate, as a string ?  There is a property called "BaudRate" but it has a value like "br__110".
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on April 11, 2014, 11:38:55 am
hello
Baudrate of TLazSerial component is an enum :
Code: [Select]
type
  TBaudRate=(br___110,br___300, br___600, br__1200, br__2400, br__4800,
             br__9600,br_14400, br_19200, br_38400,br_56000, br_57600,
             br115200,br128000, br230400,br256000, br460800, br921600);   

to use it in your project  , for example create  const array of something in your project :
Code: [Select]
const
  BaudInt: array[TBaudRate] of integer=(110,
    300, 600, 1200, 2400, 4800, 9600,14400, 19200, 38400,56000, 57600,
    115200,128000,230400,256000, 460800, 921600);
  BaudString: array[TBaudRate] of string=('110',
      '300', '600', '1200', '2400', '4800', '9600','14400','19200','38400','56000',
      '57600','115200','128000','230400','256000', '460800', '921600');   

For example to read baudrate as string of your Serial1 TLaserial component :
Code: [Select]
ShowMessage(BaudString[Serial1.BaudRate]);
Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: arifhannasy3 on April 11, 2014, 01:49:03 pm
Jurrasic Pork,

hey Jurrasic Pork,
why you not submit your serialport component to sorceforge,
so people can download and develop your serialport component,
and bugs can be quickly resolved.

sorry my english is bad. :D
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Momboz on June 05, 2014, 11:23:33 pm
Hi J.P.

I would like also to express my sincere thanks for the good job you have done. I am a fan of the Delphi environment (Embarcadero) and I am starting to use you LazSerial package. I like it very much.

I have tested it under Ubuntu 12.04 LTS and its perfect.

Your English is good and I can understand :-)

Please go ahead improving this wonderful package.

 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 on July 28, 2014, 08:25:26 am
*JurrasicPork, I would ask you to put a link to the current version of TLazSerial in you first post.
Also, here is a function, I find essential for such purposes. Surely writing it would take less time than googling it.


Code: [Select]
//BSD 3-Clause License, СМ630, 2014
function  StringToASCIIStrHexColumned (aString: String): string;
const
  CrLf=#13#10;
var
  i:integer;
begin
  Result:='        │ 00 01 02 03 04 05 06 07 │ 08 09 0A 0B 0C 0D 0E 0F'
  +CrLf+  '────────┼─────────────────────────┼────────────────────────';
  for i:= 0 to Length(aString)-1 do
  if ((i mod 16) = 0)
     then Result:= Result +CrLf + IntToHex(trunc(i/16),8) + '│ ' + IntToHex( (i),2)+' '
        else if ((i mod = 0) then Result:= Result + '│ ' + IntToHex ((i),2)+' '
          else Result:= Result + IntToHex ((i),2)+' ';
end;
Example: Memo.Clear; Memo.Append(StringToASCIIStrHexColumned ('abcdefghijklmnoprstuvwxyz')); or
 Memo.Append (#13#10 +  StringToASCIIStrHexColumned ('abcdefghijklmnoprstuvwxyz'));
Obviously, it can be used with a monospaced font only.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Dr. Console on July 29, 2014, 10:28:08 pm
Hey Jurassic,
could you may provide a little how to or so...i'm not working that often with lazarus, but I need serial com. for my actual project...
So would be cool if you could provide a short example of how to send and receive serial data... i didn't got I it yet from the example.

Thanks and nice greetings from Germany.
Dr. Console
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 on July 30, 2014, 08:03:08 am
Give us some more info what is you project about, we might give you some hints.

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Dr. Console on July 31, 2014, 03:40:04 pm
Well my project are small, easy and cheap pagers for a medical service incl. a software for alarming them.
So the Pagers are based on an arduino at the moment and I need to supply the Keyword, a ID of the Pager and the message to send via Serial port and receive infos about a received ACK or a confirmation send by the pager.
So would be cool if you could it as basic as possible :D

NG
Dr. Console
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Paul Breneman on July 31, 2014, 05:07:09 pm
http://ctrlterm.com/ (http://ctrlterm.com/) might be a good place to learn?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: laskov on September 26, 2014, 09:18:33 am
Hello everybody,

Is it possible to make console application with TLazSerial and if yes,
 1. what must be in Uses? (interfaces, ...)
 2. how to define LazSerial1: TLazSerial; ?

Thanks a lot!
Valentin

PS:
I managed to do it without TLazSerial:
Quote
uses ... , synaser;

type TSerial = class(TBlockSerial)
   end;

var ser: TSerial;

begin
  ser:=TSerial.Create;
...
...
end.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 on October 27, 2014, 07:54:21 am
There is a chain of BUGS, which finally results in lazserialsetup.pas used in Windows XP.
Briefly: if the number of a device to be added is higher than nine (i.e. COM15) it is displayed only as
COM1. More information is given in this thread (http://forum.lazarus.freepascal.org/index.php/topic,26241.0.html). I would like to ask if other people can reproduce the bug (and possibly in other Win versions).
Also, I would ask Jurassic Pork about his opinion. IMHO, bes solution is to contact the developers of Ararat Synapse, but also the GetSerialPortNames function can be duplicated in LazSerial with a bugfix.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BigChimp on October 27, 2014, 08:34:56 am
IMHO, bes solution is to contact the developers of Ararat Synapse,
FYI: If that bug is confirmed: submitting a patch via the synapse mailing list has been a painless process for me both for bug fixes and commenting improvements...
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on October 29, 2014, 01:50:04 am
hello,
my O.S is Windows 7 64 bits, i use Lazarus 1.2.4   32 bits.  I have created two virtual serial ports paired with the software com0com . The names of these ports are COM129 and COM140.  I launch two instances of the example gps simulator sertest of tlazerial component. In the first i can choose and open the COM129 port , in the other the port COM140. When i start the gps simulator on one , i receive the frames on the other.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 on November 05, 2014, 09:42:50 am
my O.S is Windows 7 64 bits, i use Lazarus 1.2.4   32 bits.  I have created two virtual serial ports paired with the software com0com .

Did you check the value of the registry with regedit (as seen from attached image)?  A virtual com port might be created properly, there is a problem with Bluetooth com port installation. I just plugged a USB to Serial adapter, win assigned COM3 to it, then I manually changed the prot number to 41 and it is okay (right picture). But adding COM devices to bluetooth (in Win XP) does not add last two zeroes (left screenshot).
I did the same on another PC with WinXP 32 bit. Bluetooth added COMS the same way. Then I run this source in VB.NET:
Code: [Select]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim readValue As String
  readValue = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", "\Device\BthModem10", Nothing)
  MsgBox("The value is " & readValue)
End Sub
It returned the entire string. So I have nothing else to think, except that there is a bug in the FPC registry implementation, or precisely registry.pp (https://github.com/macek/fpc/blob/master/packages/fcl-registry/src/registry.pp).
Here is their code:
 
Quote
function TRegistry.ReadString(const Name: string): string;

Var
  Info : TRegDataInfo;

begin
  GetDataInfo(Name,Info);
  if info.datasize>0 then
    begin
     If Not (Info.RegData in [rdString,rdExpandString]) then
       Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
     SetLength(Result,Info.DataSize);
     If StringSizeIncludesNull then
       SetLength(Result, Info.DataSize-1)
     else
       SetLength(Result, Info.DataSize);

     GetData(Name,PChar(Result),Info.DataSize,Info.RegData);
   end
  else
    result:='';
end;
In the source of registry.pp I could not find where StringSizeIncludesNull gets its value from, but it always returns true!?!


Edit: I have fixed the code the following way, no it seems to work fine:
Code: [Select]
function TRegistry.ReadString(const Name: string): string;
Var
  Info : TRegDataInfo;
begin
  GetDataInfo(Name,Info);
  if info.datasize>0 then
    begin
     If Not (Info.RegData in [rdString,rdExpandString]) then
       Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
     SetLength(Result,Info.DataSize);
     GetData(Name,PChar(Result),Info.DataSize,Info.RegData);
     FStringSizeIncludesNull:=(RightStr(Result,1)=#0);
     If StringSizeIncludesNull then
       SetLength(Result, Info.DataSize-1)
     else
       SetLength(Result, Info.DataSize);
   end
  else
    Result:='';
end; 
Edit: Reported as bug 27002 (http://mantis.freepascal.org/view.php?id=27002).
Edit: It occurs that the problem was reported 2,5 years ago (http://bugs.freepascal.org/view.php?id=21899), still no resolution.
Jurassic Pork, what about using a custom ReadString  function in your library, until the bug is fixed? Also, do you mean uploading it to SF or somthing similar?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: parcel on November 07, 2014, 08:15:46 am
http://books.google.co.kr/books?id=kVqB5hjNsScC&pg=PA287&lpg=PA287&dq=registry+string+null+terminated&source=bl&ots=19SAsxSUWI&sig=vu1JQKO0yS_rKSm9dUJfkHwbb9M&hl=ko&sa=X&ei=GGdcVLmPL4Hz8QXt04LwBw&ved=0CD4Q6AEwAw#v=onepage&q=registry%20string%20null%20terminated&f=false (http://books.google.co.kr/books?id=kVqB5hjNsScC&pg=PA287&lpg=PA287&dq=registry+string+null+terminated&source=bl&ots=19SAsxSUWI&sig=vu1JQKO0yS_rKSm9dUJfkHwbb9M&hl=ko&sa=X&ei=GGdcVLmPL4Hz8QXt04LwBw&ved=0CD4Q6AEwAw#v=onepage&q=registry%20string%20null%20terminated&f=false)

It describe some registry string has null terminate string in windows 9x, and not in windows nt.
it may check and strip null character at reading.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 on November 10, 2014, 07:36:51 am
The problem is that no one from the FPC team seems to solve problem. I will submit a patch, hopefully s.o. will apply it.
And also, since *Jurassic Pork does not seem to be interested in TLazSerial anymore, maybe I should fork it, since I am willing to make some improvements.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: whoim on December 02, 2014, 09:30:48 am
this component may work on android?)
need bluetouch slave cdc connect to my device
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: brewdos on December 02, 2014, 05:24:05 pm
Thank you very much for your work
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 on December 12, 2014, 08:39:43 pm
Latest info from the bugtracker is that the registry bug is fixed. I hope I will be able to try it soon.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Ferke on February 23, 2015, 07:13:54 pm
Hi,

first of all, thank you for your component.
I have a question.  I would like to use this component on Raspberry Pi 2. Will this work on ARM?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: maxid on June 12, 2015, 02:47:04 pm
can implement datapackets?
how send and receive Records?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on June 13, 2015, 02:04:10 am
hello,
 you can parse packets in the OnRxData event. TComportDataPacket is only an easy way to do this.
if you are on Windows, see Tcomport component for Lazarus.

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: eny on June 13, 2015, 06:06:28 am
can implement datapackets?
how send and receive Records?
By not cross posting and creating a new thread with your question.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: elcomportal on August 12, 2015, 03:37:14 pm
I get at the Com port strings ended with CR LF. Is there any event available when the line is completely received?
best regards
Torsten
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tr_escape on August 12, 2015, 04:02:59 pm
You can use that style:

But you have to check CR and LF chars in this event or in your buffer.

In this case com_some is my buffer.

Code: [Select]
procedure TfrmMain.Lazser1RxData(Sender: TObject);
var
  s : string;
begin
  //
   try
    s := Lazser1.ReadData;
    if s <> '' then
    begin
      wait_comm := False;
      if com_some = '' then
      begin
        LogAdd(mem_Log1, 'RCV<: ' + s);
        LogAdd(mem_Log2, 'RCV<: ' + StrToHex(s));
      end
      else
      begin
        LogAddStr(mem_Log1, s);
        LogAddStr(mem_Log2, StrToHex(s));
      end;
      com_some := com_some + s;
    end;
  except
    // LogAdd(mem_General,'Exp : ' );
  end;
end;
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: bambangfals on October 16, 2015, 02:46:37 am
I have problem use lazserial

I want to send SMS with this AT COMMAND:
Code: Pascal  [Select][+][-]
  1. LazSerial1.WriteData('at+cmgs="PHONENUMBER"'+#13#10);
  2. LazSerial1.WriteData('Some text to send via sms');
  3. LazSerial1.WriteData(#26);

But there is a line break at the beginning of the text that I received.

Character that I received in my phone:
Code: Pascal  [Select][+][-]
  1.  
  2. Some text to send via sms

there "enter" in the beginning of the line.

Please help me for this bug and sory for my poor english.
Thx
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Leledumbo on October 16, 2015, 03:24:01 am
I want to send SMS with this AT COMMAND:
Code: Pascal  [Select][+][-]
  1. LazSerial1.WriteData('at+cmgs="PHONENUMBER"'+#13#10);
  2. LazSerial1.WriteData('Some text to send via sms');
  3. LazSerial1.WriteData(#26);

But there is a line break at the beginning of the text that I received.
You send #13#10, the command expects:
Quote
AT+CMGS=<number><CR><message><CTRL-Z>
You add the #10 intentionally.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: bambangfals on October 16, 2015, 04:00:06 am
I want to send SMS with this AT COMMAND:
Code: Pascal  [Select][+][-]
  1. LazSerial1.WriteData('at+cmgs="PHONENUMBER"'+#13#10);
  2. LazSerial1.WriteData('Some text to send via sms');
  3. LazSerial1.WriteData(#26);

But there is a line break at the beginning of the text that I received.
You send #13#10, the command expects:
Quote
AT+CMGS=<number><CR><message><CTRL-Z>
You add the #10 intentionally.

Thanks leledumbo, I have changed #13#10 into #13 and it work like a charm.
You save my time :D  ;) ;)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: eldonfsr on October 31, 2015, 08:36:46 pm
Can be possible use lazserial as terminal like comport on delphi, cos i need type some commands and also received the respond device....

thanks.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on October 31, 2015, 11:25:12 pm
hello,
eldonfsr, yes it is  normally possible .  Does your device response contains ending characters (ie : CRLF) ?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: eldonfsr on November 08, 2015, 01:37:50 am
Ok my device return that character, the sample i look has two controls 1 for inputs and other for typing outputs but i need in the same control textboxedit can deal intputs and outputs.

thanks.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: lonely_myp on November 17, 2015, 03:57:10 pm
Hi.
I'm starting to learn to program, and I want to use the component.
standard example too complicated, could have that easier?

Just try to open existing port:
Code: Pascal  [Select][+][-]
  1. Serial.device:= '/dev/ttyS1';
  2. Serial.Open;
and got the error: Project raised exception class "External:SIGSEGV"

The standard example is started, but no data is sent or received.
The port is available, if I use the terminal, I can send and receive data.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tr_escape on November 17, 2015, 04:50:38 pm
Hello ,

Maybe this prject helps you:

https://github.com/mehmetulukaya/muterm/blob/master/main.pas (https://github.com/mehmetulukaya/muterm/blob/master/main.pas)

Also I think you are using linux is your account member of dialout?

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on November 18, 2015, 12:40:09 am
hello,
lonely_myp, what kind of project do you want to make ? GUI or console app ? What is your O.S ? Windows, Linux , MAC ?

with  a TlazSerial component on your form try this  : 

Code: Pascal  [Select][+][-]
  1.   Serial.ShowSetupDialog;  
  2.   Serial.Open;    
  3.  

When the dialog setup appears, do you see your port (/dev/ttyS1) in the  choice of the port's combobox ?

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: lonely_myp on November 18, 2015, 09:27:33 am
linux
Yes, account member of dialout, other programs (CuteCom) work with the device.

I want to write a simple GUI program, 2 buttons: "Open Port", "Send Data"
The program must send specific data and display the answer.

When the dialog setup appears, do you see your port
There is no dialogue, there is a window with an error.
exception 'Lazserialsetup.pas' line 211
ComComboBox1.Text: = ComPort.Device


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.  ​
  42.  
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on November 18, 2015, 10:56:28 am
what is your linux ( Ubuntu, Mint, other ?) ? version of your O.S ?
version of Lazarus and free pascal compiler ?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: lonely_myp on November 18, 2015, 11:55:50 am
ALT linux, It was based on Linux-Mandrake.
Lazarus 1.4.4
fpc 2.6.4
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on November 19, 2015, 01:03:01 am
hello,
Quote
exception 'Lazserialsetup.pas' line 211
ComComboBox1.Text: = ComPort.Device

What kind of Exception ?
Debug your program and set a breakpoint at line 211 of Lazserialsetup.   Value of Comport.Device before exception ?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: lonely_myp on November 19, 2015, 08:04:30 am
here
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork 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.  
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: lonely_myp 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;
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on November 23, 2015, 10:19:33 am
hello,
have you added the synaser unit in the uses ?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: lonely_myp 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.  

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: lonely_myp 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.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: lonely_myp on December 02, 2015, 02:41:57 pm
My project: https://drive.google.com/file/d/0B2sGop41unyOWWpOaG1yNkJQdHM/view?usp=sharing
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork 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  %) .     

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork 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
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: AD 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?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork 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 ?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: AD 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 ;)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: lonely_myp 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 =)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jiji66 on February 15, 2016, 08:49:31 am
It could be nice to have that kind of component included in the Lasarus default installation.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 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
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on July 18, 2016, 10:39:50 am
Oh...I',m sorry...wasn't aware that this item was more than just 1 page.

Firts I'm gonna read and studdie the complete item, containing the 8 pages...

All regards!


But..if anyone has a clear answer to my previous post, don't hesitate to post it!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on July 19, 2016, 12:38:42 pm
So far so good!

Based on 'sertest GPS'.
Used the program to sends the pc-time to the Arduino-LCD.

Strange thing is that the Arduino receives 2 extra characters before the actual string.

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on July 19, 2016, 01:38:55 pm

Strange thing is that the Arduino receives 2 extra characters before the actual string.
Cast it to PAnsiChar first. Then the meta-data for length and refcount will be stripped.
A pascal string has that information at a negative offset hence the two extra bytes.


Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on July 20, 2016, 02:16:07 pm
Thanks, Thaddy.

( for the time being, I just removed the 2 first char's at the Arduino/receiver )

Gotta studie moren things. I'm using serial.writedata ()
And there could be more. Like serial.writetext?

Tried to find a overview with all methods/procedures but I dont'get it.
I 'uses' Lazserial and Synaser.

When google I found this, but these are mehods for another Object?
http://synapse.ararat.cz/doc/help/synaser.TBlockSerial.html

Or I'm I making a logic-thinking-failure due of the LazSerial/Synaser I'm using?
Do I mix things up?

All regards.

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on July 29, 2016, 06:30:55 pm
It's improving each time.

First I ixtended the original program "sertest" with some "own" functions:
timer, open, close, send manualy, send automaticly by the timer.

These send the pc-time to the Arduino and it's being displayed ont it's display.

Time after time a removed lot's from the "sertest" till there's only a basic Serial program left over.
( al the gps-stuff, editbox/menu's etc etc have been removed )


Now I got a nice "basis" to work with for my future projects e.g. robotArm etc.

manualy can send an text to my arduino.
the pc-time is send every second (timer).
the scrollbar sends it's value to my arduino and indicatis by a LEDbarGraph.



Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on August 08, 2016, 11:52:25 am
After a break, got some significant progress!

Value of 3 ScrollBars is sended by RS232 to my Arduino.
At 3 LedBars, the values are displayed as (0-255) values.
( gonna be in 0 to 8 led's later as is it showing an audio-level-indicater )

In Lazarus the refresh rate is 10/sec. Only the value of the last changed Scrollbar is sended to Arduino. At my Lazarus INIT al of the 3 wil be sended!




Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on August 08, 2016, 12:05:46 pm
I'm using

1 byte as LedbarNumber and

3 bytes as LedBarValue.

The string 'el' (end-line) is added as delimiter.

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on August 08, 2016, 12:21:33 pm
I'm very happy I got this far programming RS232.

Next step is to controll my robotArm by PC-RS232-Arduino!


Fortunately I got the major part for controlling my robotArm allready
coded in TurbuPascal7.0 and the control is done by ISA/ 82c55a.

The whole ForWard/BackWard-Kinematics, stepperControl and overal mathematics for Interpolation/Integral/Differential for creating a path in 3d.

http://europakade.nl/motion-control-an-robots/robot-arm

https://www.youtube.com/playlist?list=PL7iWs5bvJdxs91kCZUV9P6KuG4mvriLgJ


Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: xinyiman on August 10, 2016, 10:34:50 am
Hi, thank you for the component, which works fine on raspberry, the only flaw is that it must be on a form. Because if I try to use this library. Compiles, but when using it faults.

Code: Pascal  [Select][+][-]
  1. unit Unit_Epson_TM_T70II;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LazSerial;
  9.  
  10.   type
  11.  
  12.       { TEpson_TM_T70II }
  13.  
  14.       TEpson_TM_T70II = class
  15.  
  16.  
  17.       private
  18.             Seriale: TLazSerial;
  19.             procedure Inizializza();
  20.             procedure LineeBianche(numero: integer);
  21.  
  22.  
  23.       public
  24.             constructor Create(Sender: TComponent; device: string);
  25.             function Stampa():boolean;
  26.             destructor  Free();
  27.  
  28.  
  29.       end;
  30.  
  31.  
  32. implementation
  33.  
  34. { TEpson_TM_T70II }
  35.  
  36. procedure TEpson_TM_T70II.Inizializza;
  37. begin
  38.      Seriale.WriteData(Chr(27) + Chr(64));
  39. end;
  40.  
  41. procedure TEpson_TM_T70II.LineeBianche(numero: integer);
  42. begin
  43.      if numero<0 then
  44.         numero:=0;
  45.      if numero>255 then
  46.         numero:=255;
  47.  
  48.      Seriale.WriteData(chr(27) + chr(100) + chr(numero));
  49. end;
  50.  
  51. constructor TEpson_TM_T70II.Create(Sender: TComponent; device: string);
  52. begin
  53.      Seriale:=TLazSerial.Create(Sender);
  54.      Seriale.BaudRate:=br115200;
  55.      Seriale.DataBits:=db8bits;
  56.      Seriale.Device:=device;
  57.      Seriale.FlowControl:=fcNone;
  58.      Seriale.Parity:=pNone;
  59.      Seriale.StopBits:=sbOne;
  60.      Seriale.Active:=true;
  61. end;
  62.  
  63. function TEpson_TM_T70II.Stampa: boolean;
  64. begin
  65.      if Seriale.Active then
  66.      begin
  67.           Self.Inizializza();
  68.           Self.LineeBianche(5);
  69.           result:=true;
  70.      end else begin
  71.        result:=false;
  72.      end;
  73.  
  74. end;
  75.  
  76. destructor TEpson_TM_T70II.Free;
  77. begin
  78.      Seriale.Active:=false;
  79.      Seriale.Free;
  80. end;
  81.  
  82. end.
  83.  
  84.  


Error

TApplication.HandleException Access violation
  Stack trace:
  $003B9F08  TEPSON_TM_T70II__STAMPA,  line 65 of unit_epson_tm_t70ii.pas
  $00077E78  TFORM1__BUTTON1CLICK,  line 41 of unit1.pas
  $0024685C  TCONTROL__CLICK,  line 2711 of ./include/control.inc
  $0027946C  TBUTTONCONTROL__CLICK,  line 54 of ./include/buttoncontrol.inc
  $00279DFC  TCUSTOMBUTTON__CLICK,  line 169 of ./include/buttons.inc
  $00279334  TBUTTONCONTROL__WMDEFAULTCLICKED,  line 20 of ./include/buttoncontrol.inc
  $00043124
  $00234CB0  TWINCONTROL__WNDPROC,  line 5326 of ./include/wincontrol.inc
  $00336EBC  DELIVERMESSAGE,  line 112 of lclmessageglue.pas
  $00347BDC  GTK2WSBUTTON_CLICKED,  line 2435 of gtk2wsstdctrls.pp
  $76921AFC
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on August 10, 2016, 11:54:03 am
hello,
yes xinyiman TLazserial only works on a Gui App  :( . But you can use synaser for your purpose.

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: xinyiman on August 10, 2016, 01:51:00 pm
hello,
yes xinyiman TLazserial only works on a Gui App  :( . But you can use synaser for your purpose.

Friendly, J.P

How?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on August 10, 2016, 01:51:44 pm
[posts crossed. Will post simple example sometime later today]
Yup.
And even with forms, synapse (which nowadays includes synaser) is probably a better choice.
Note synapse comes with classes, not components.
I use it all the time on my RPi's (ranging form 1 to 3)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Paul Breneman on August 10, 2016, 02:46:26 pm
How?

There is a simple synaser console example here: http://turbocontrol.com/simpleserial.htm (http://turbocontrol.com/simpleserial.htm)

There is an easy synapse console example here to send emails (and texts):  http://turbocontrol.com/easyemail.htm (http://turbocontrol.com/easyemail.htm)

I hope to update the second example in the next week as I'm using a newer version of it to send the current temperature in both emails and texts with a Raspberry Pi.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: xinyiman on August 11, 2016, 11:40:31 am
How?

There is a simple synaser console example here: http://turbocontrol.com/simpleserial.htm (http://turbocontrol.com/simpleserial.htm)

There is an easy synapse console example here to send emails (and texts):  http://turbocontrol.com/easyemail.htm (http://turbocontrol.com/easyemail.htm)

I hope to update the second example in the next week as I'm using a newer version of it to send the current temperature in both emails and texts with a Raspberry Pi.

Thank you  ;)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PStechPaul on August 23, 2016, 04:45:35 am
I was able to install the TLazSerial component and build the demo GPS Simulator. I have a USB serial port designed in a custom data acquisition board, and when a Ctrl-T character is sent, it returns a stream of 240 unique character pairs, at 4800 characters per second, on a 57.6 kB connection. I was able to accomplish this with a TEST button and an OnClick handler.

It received and displayed them properly, as far as I can tell, so I'm happy with the component. I previously used SerialNG, but it did not work with Win10. Then I used ComDrv32, which I was able to use in a rather complex project, using Delphi 4 Pro. But I could not get those packages to install in Lazarus.

I am new to Lazarus, having only downloaded it yesterday. I was frustrated by the problems with the serial port components, but now I am happy to find this. I may post more details about my experience later, perhaps in a new thread.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CaptBill on August 23, 2016, 06:26:22 am
TLazSerial is nice if you just want a good, no fuss connection to a com port.
TDataPort looks like the go to if you want more hands on with it. Very complete set of components. Definitely more geared for uC's.

https://github.com/serbod/dataport (https://github.com/serbod/dataport)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on August 30, 2016, 06:57:20 pm
Hi, got a specific question.

What statement do I have to use in Lazarus to find out if there's data ready (received) at the COM (RS232).

At the Arduino site I can check it, see flowchart. This works ok.
At the Lazarus site I just read and display it, but it's not synchrone.

Just by some lucky shots and a value send from Arduino is read and displayed by Lazares on pc-screen. ( This value is ok, has been send by Arduino. )

What 'code'do I need?

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on August 30, 2016, 07:05:09 pm
Extra Info:

Lazarus Send:
serial.WriteData( stOut);      string-OUT: always 6 bytes long.

Lazarus Receive:
stIn:= serial.ReadData;        string-IN: always 6 bytes long (send by Arduino).



I understand, the 'code' will need a time out to prevent endless checking for data.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PStechPaul on August 30, 2016, 10:16:35 pm
Here are some functions that should work:

Code: [Select]
    {:Returns the number of received bytes waiting for reading. 0 is returned
     when there is no data waiting.}
    function WaitingData: integer; virtual;

    {:Returns @True, if you can from read any data from the port. Status is
     tested for a period of time given by the Timeout parameter (in milliseconds).
     If the value of the Timeout parameter is 0, the status is tested only once
     and the function returns immediately. If the value of the Timeout parameter
     is set to -1, the function returns only after it detects data on the port
     (this may cause the process to hang).}
    function CanRead(Timeout: integer): boolean; virtual;

    {:This event is triggered when the communication status changes. It can be
     used to monitor communication status.}
    property OnStatus: THookSerialStatus read FOnStatus write FOnStatus;


These are found in "synaser.pas".
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on August 31, 2016, 09:24:17 am
Tnx,

Sounds good!
Today's evening I'll try it.

I noticed CANread before but I tought it was for can-bus... :D

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: mig-31 on August 31, 2016, 09:51:59 am
You can use Synaser from Synapse and examine serial port buffer for waiting data by method WaitingData>0

Code: Pascal  [Select][+][-]
  1.   SerialPort:=TBlockSerial.Create;
  2.   SerialPort.Connect('/dev/ttyS0');
  3.   SerialPort.Config(9600,8,'N',SB1,False,False);
  4.   //wait for data test Waiting Data
  5.   if SerialPort.WaitingData>0 then SerialPort.RecvString(100);
  6.   FreeAndNil(SerialPort);
  7.  
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 01, 2016, 03:16:17 pm
By the way, still waiting to receive my book Lazaus the complete guide.

Alltought I did some programming in Delphi years ago, I need a good base.
E.q. to get a good understanding between classes, methods, the whole Lazarus-IDE etc.
Programming itself is not the problem. ( I did a lot in Turbo Pascal 7.0 )

Tnx, PSechPaul and mig-31 for your replies!
Gonna work with it.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 01, 2016, 09:16:56 pm
Sorry for my short of knowledge of Lazarus.

All done in Main


Have ad a if/waitingData, makes total:
======================
serial.writeData( stOut ); 

if ( serial.waitingData > 0 ) 
  then  stIn:= serial.readDate;

label4.caption:= stIn;
======================


Results in compile-error: identifier idents no member "waitingData"


So, serial at itself is "known" because serial.writeData and serial.readData are doing ok.


Tried the following:

Placed in interface-section of main: serial: TBlockSerial;

Results againin compile-error:  identifier idents no member "waitingData"

Then I removed 'serial: TBlockSerial;' out of interface-section.

Then placed in interface-section: myTestSerial: TBlockSerial;

And changed in the write-read code:

if ( serial.waitingData > 0 ) 
  then  stIn:= myTestSerial.readDate;

label4.caption:= stIn;


Now, I don't get compile-error!
But the programm hangs imideately, no response, and shows error as in the picture.
I can stop it with the red-stop-button in the LAzarus-IDE.

Anyone a hint for me?

 



Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 01, 2016, 09:19:16 pm
if wanted,i can start a topic for my own 'case' so I don't mess-up this actualy topic

"TLazSerial : serial port component for Lazarus (windows and linux)."
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on September 02, 2016, 03:24:39 am
hello,
waitingdata is a property of synaser tblockserial . So to use with tlazserial component, you must use it with the tblockserial part of tlazserial component (SynSer).

example to send data to a serial line and wait for at least 6 bytes response (Serial1 is a TLazserial component) :
Code: Pascal  [Select][+][-]
  1.   Serial1.WriteData(myData);
  2.    // Waiting for response ( at least 6 bytes)
  3.    While Serial1.SynSer.WaitingData < 6 do
  4.    begin
  5.      Application.ProcessMessages;
  6.      Sleep(10);
  7.    end;
  8.    Edit1.Text := Serial1.ReadData;  

Be carefull, if you don't receive response , you stay  in the loop.  Use a timeout code to prevent the user.
For example :
Code: Pascal  [Select][+][-]
  1. var timeout : integer;
  2. begin
  3.    timeout := 0;
  4.    Serial1.WriteData(mydata);
  5.    // Waiting for response
  6.    While Serial1.SynSer.WaitingData < 6 do
  7.    begin
  8.      Application.ProcessMessages;
  9.      Sleep(10);
  10.      inc(timeout);
  11.      if timeout > 1000 then        // 10 seconds
  12.        begin
  13.             ShowMessage('No response from the device');
  14.             Exit;
  15.        end;
  16.    end;
  17.    Edit1.Text := Serial1.ReadData;
  18. end;                  

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PStechPaul on September 02, 2016, 03:56:53 am
I also noticed a typo in your code:

Code: Pascal  [Select][+][-]
  1. if ( serial.waitingData > 0 )
  2.   then  stIn:= myTestSerial.readDate; //should be readData
  3.  
  4. label4.caption:= stIn;
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 02, 2016, 09:39:12 am
GREAT! Tnx!

After placing using 

serial.synser.waitingData  instead of

serial.waitingdata thing rappidly improved!

Finaly I got:

Code: Pascal  [Select][+][-]
  1.    
  2. stOut:= (stNumberChangedScrollBar +  stTemp + 'el');
  3. serial.WriteData(stOut);
  4.  
  5. while (serial.synser.waitingData < 4)  
  6. {
  7.    6 bytes to Arduino including delimiter 'el'
  8.    4 bytes returned by Ardino, is ok without returning delimiter 'el'.
  9. }
  10.      do
  11.         begin
  12.           application.processMessages;
  13.           sleep(1);
  14.         end;
  15.       stIn:= serial.readData;
  16.       label4.caption:= stIn;
  17.       //FreeAndNil(Serial);

   
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 02, 2016, 10:24:14 am
Finaly got it stable, with:

Code: Pascal  [Select][+][-]
  1.           sleep(1);
  2.           inc(iTimeOut);
  3.           if (iTimeOut > 2) then exit    //  (iTimeOut > 1) is not working
  4.  



As written before: Arduino receives and imidiately sends back:

Code: Pascal  [Select][+][-]
  1. uart3_read_text(stRC, 'el', 7 );
  2. uart3_write_text(stRC);
  3.  


Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 02, 2016, 10:47:34 am
Some explanation about values:

2063 means scrollBar #2 and value 63

Code: Pascal  [Select][+][-]
  1.  
  2. //  0   1   2    3     4     5   6    7  led
  3. //  1   2   4    8    16    32  64  128  bin
  4. //  0   1   3    7    15    31  63  127  dec
  5. //16   48   80  112  144   176 208  240 tres  
  6.  








Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 05, 2016, 07:06:59 pm
Slowly I'm getting more understanding how things in al the units are 'connected' to eachother.

I'm trying to get multiple comports in Lazarus. I allready got 2 Arduino's at my pc and all
the 2 of them are communication well with lazarus, just 1 at a time!

I just changed proporty "device", and start debug/run. In my case: com13/com14.

The goal is to use more com's in the application.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 05, 2016, 07:29:19 pm
Great! It functions!

Wasn't that hard after all... :D

See Lazarus sending to the 2 Arduino's LCD's:
( for the time, no sending to pc )


https://www.youtube.com/watch?v=qC4FIKLXbf8&index=3&list=PL7iWs5bvJdxuc5P3ttOFl8MEpFg4GsRwI


Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 06, 2016, 09:13:16 pm
Played around for a while, but I quess I have to clear/empty a buffer in pc where the incoming data is stored/buffered.

See, the attachment why I came to this issue, Arduino sends:  stOut:= '12345678EL'
But sometimes there's is showing multiple times that string.

I found some different things:


{ Discard all pending input. }
procedure SerFlushInput(Handle: TSerialHandle);


{ Flushes the data queues of the given serial device. DO NOT USE THIS:
use either SerSync (non-blocking) or SerDrain (blocking). }
procedure SerFlush(Handle: TSerialHandle); deprecated;


I didn't manage to get them compiled in my code, to clear input-buffer-com after reading.



Code: Pascal  [Select][+][-]
  1.    
  2.  while (Serial14.synser.waitingData < 10)  // send by Arduino
  3.       do
  4.         begin
  5.           application.processMessages;
  6.           sleep(1);
  7.           inc(iTimeOut);
  8.           if (iTimeOut > 2) then exit
  9.         end;
  10.     stIn:= Serial14.readData;
  11.    
  12.     // after readData: clear/emtpy buffer input com14, how to code?
  13.  
  14.     label4.caption:= stIn;



Finaly my application hangs...





Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PStechPaul on September 06, 2016, 10:34:35 pm
The process of reading data should take care of the buffer if the data can be processed at least as fast as it is received. Here is the readData function:

Code: [Select]
function TLazSerial.ReadData: string;
begin
  result:='';
  if FSynSer.Handle=INVALID_HANDLE_VALUE then
    ComException('can not read from a closed port.');
  if FRcvLineCRLF then
  result:=FSynSer.RecvString(0)
  else
  result:=FSynSer.RecvPacket(0);
end;

The alternate results are implemented as follows:

Code: [Select]
   {:Read all available data and return it in the function result string. This
     function may be combined with @link(RecvString), @link(RecvByte) or related
     methods.}
    function RecvPacket(Timeout: Integer): AnsiString; virtual;

     This method serves for line protocol implementation and uses its own
     buffers to maximize performance. Therefore do NOT use this method with the
     @link(RecvBuffer) method to receive data as it may cause data loss.}
    function Recvstring(timeout: integer): AnsiString; virtual;

Make sure that stIn has enough space for the string or the packet, and see if your data strings are properly terminated if you want to read strings and not packets.

Also, the loop in your code snippet runs only if there are less than 10 bytes of data in the buffer. If >= 10, readData will never be called, and the buffer will just fill up to its maximum capacity and overrun, which should flag an error that you can check for.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 07, 2016, 08:11:45 am
Tnx!

Quote
   If >= 10

Rang me a bell!

Changed it to the right number and thing impoved rappidly.
Things run more smooth now and the ceived string is now displayed started at the first chararcter as it is send bu Arduino!

Just occasionaly 2 times the  the received string is displayed in a row.
Before it was a mess.

What also is clear now is that 2 extra characters are shwon at the end of the string: '8!'
This reminds of a something I red before: about typecasting and Ansistring etc.






Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 07, 2016, 08:38:20 am
Next, I increased the max of iTimeOut:
And tested what the minimum must be to keep things smooth;


Code: Pascal  [Select][+][-]
  1.   const
  2.      cTimeOutMax = 5;
  3.  
  4.  
  5.   // implementation etc...
  6.   -
  7.   -
  8.   -
  9.   if (iTimeOut > cTimeOuMax) then exit
  10.   -
  11.   -
  12.  

Still have to do more investigation, 'cause still there is occasianaly/rarely more than 1 recived string displayed.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 07, 2016, 08:45:04 am
The double strings are receievd independetly !

For testing I coded a swap to the first 2 characters sended by Arduino:
( this makes it more clear to see what's happening )

ab - ba - ab - ba - etc...


The '?' shouldn't be there at all...
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 07, 2016, 09:52:25 pm
So far so good!

For testing and see thing clears I send from Arduino secuently a 27 char string:
( instead of a string filled with 24 'values' ending with 'end')


'N11222333444555666777888end'
N: string with numbers

'Laabbbcccdddeeefffggghhhend'
L: string with letters


Now I can see if a diplayed string on my Lazarus form is from one and the same sended string or an mixed string from 2 sended string!

After a while and lots of coding and 'adjustments' I got a stable displayed string.
( apearently I don't need a delimiter in Lazars, but I DO in mikropAscal Arduino when receving from RS232 )


Next thing I wanted to run the application for a long time and 'catch' wrong strings by just checking: first char is it an 'L' or an 'N' ?
If not: increment and display the errornumber on my form.


As learned the first char in a string is placed at position 0  as in stringIN[0],
but then I found out i had to check stringIN[1]...

See, picture.
Ok, not a big deal but what does it mean?

Still, have to do troubleshouting etc, sometimes the application hangs soon, other times it runs longer...
( could it because of debug-mode instead of runnng it as a 'free' programm ? )

By the way somehow I don't trust the timers, or maybe I have a programm-error/mistake...


I also need some code if there's nog data OR time out, see *CODE
'cause it reads even when there is a time out OR no dataReady


Code: Pascal  [Select][+][-]
  1. var
  2.  iTimeOut: integer = 0;
  3.  stIn: string[27];                                          // final value    
  4. -
  5. -
  6. -
  7. while (Serial14.synser.waitingData < 27)    // final value
  8.     do
  9.         begin
  10.           application.processMessages;
  11.           sleep(1);
  12.           inc(iTimeOut);
  13.           if (iTimeOut > 5) then exit                  // final value
  14.         end;  
  15.  
  16.     *CODE
  17.  
  18.     stIn:= Serial14.readData;
  19.     label4.caption:= stIn;  
  20.  
  21.  
  22.  


For those who are interested: watch test on video:

https://www.youtube.com/watch?v=agE6KGPzXXA&list=PL7iWs5bvJdxuc5P3ttOFl8MEpFg4GsRwI&index=4
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 07, 2016, 10:12:39 pm
Just disabled timer1 (1000ms) to show system time...

So far, things look much better!

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PStechPaul on September 07, 2016, 10:49:21 pm
I see several problems.

(1) The loop will fail to run if there are 27 or more characters in the comm buffer

(2) The timeout value is never reset, so eventually your delay loop will only sleep for 1 mSec and then exit

(3) I don't understand what you are trying to accomplish with the loop, delay, and reading the input while the buffer contains less than 27 characters.

You might want to bypass the dataRead until the buffer has at least the 27 characters that make up the string. So when waitingData >=27, you can do the dataRead which will read the entire string and remove 27 characters from the buffer. There is no need for your timeout loop, as the dataRead will read either a packet or a terminated string. You can check the length of the string to see if it is the expected 27 characters.

Something else to consider is how strings are defined in Pascal and Lazarus. A "short" string has its length (up to 255 characters) in a byte at stIn[0], and a "wide" string uses two bytes to allow up to 65535 characters. There is also a PChar which is a null terminated string. Here is an explanation I got from the comp.lang.pascal.delphi.misc usenet newsgroup:

Code: Pascal  [Select][+][-]
  1. Let's start with the simplest one: ShortString. ShortString storage has a
  2. fixed 256 bytes length. This is why ShortString can't hold more than 255
  3. characters. The first byte is the length of the string. The remaining bytes
  4. are the string characters. The data for "ABC" would be like below (in
  5. hexadecimal) where xx is an undefined byte.
  6.  
  7.   03,41,42,43,xx,xx,...
  8.  
  9. i.e.
  10.  
  11.   ShortStringStorage = record
  12.     StringLength : Byte;
  13.     StringData   : Array [1..255] of Char;
  14.   end;
  15.  
  16. A pointer to a ShortString (e.g. @MyShortString) would point to the first
  17. byte of its storage - to the string length. MyShortString[0] would also
  18. point to the string length - as Char type. And you can modify the string
  19. length by altering the first byte. SizeOf(MyShortString) will always resolve
  20. to 256 if MyShortString was declared as just ShortString. If it was declared
  21. as ShortString[100], SizeOf(MyShortString) would resolve to 101.
  22. Length(MyShortString) will resolve to the string length.
  23.  
  24.  
  25. PChar...
  26. PChar type is just a pointer to a Char type. It doesn't hold any actual
  27. characters. It's equivalent to: ^Char. When used as a string pointer, the
  28. data it points to is expected to be a null-terminated string - to the first
  29. character of the string. SizeOf(MyPChar) would resolve to 4 because it's a
  30. pointer. Length() is not applicable for PChar type. The data for "ABC" would
  31. be like below.
  32.  
  33.  41,42,43,00
  34.  
  35.  
  36. String...
  37. String type is a combination between ShortString and PChar (null terminated
  38. string). The String storage layout is like ShortString except that the
  39. string length is 16-bit instead of 8-bit. The data for "ABC" would be like
  40. below.
  41.  
  42.  03,00,41,42,43,00
  43.  
  44. i.e.
  45.  
  46.  (*
  47.  StringStorage = record
  48.    StringLength : Word;
  49.    StringData   : Array [1..n] of Char;
  50.  end;
  51.  Where n is variable. i.e. variable field size
  52.  *)
  53.  
  54. The type itself works similar to PChar (i.e. a pointer), but it points to
  55. the first character of the string instead to the string length. i.e. to the
  56. third byte. SizeOf(MyString) would also resolve to 4 just like PChar.
  57. Length(MyString) would resolve to the string length. You can't use
  58. MyString[0] to access the string length. It's not allowed because the string
  59. length is 16-bit. You'll have to use Length() instead.
  60.  
  61.  
  62. Typecasting to PChar...
  63. String can be safely typecasted to PChar, but not a pointer to ShortString
  64. (PShortString). This is because ShortString is not a null terminated string.
  65. If you need to typecast PShortString to PChar, you'll need to have a null
  66. character following the string data (not the string storage). But be sure
  67. the string length plus the null character doesn't exceed 255 characters.
  68. e.g.
  69.  
  70.   procedure Example;
  71.   var MyShortString : ShortString;
  72.   var MyString      : String;
  73.   var MyPChar       : PChar;
  74.   begin
  75.     MyShortString := 'ABC';
  76.     if Length(MyShortString) < 255 then
  77.     begin
  78.       (* Append null character without changing string length *)
  79.       MyShortString[Length(MyShortString)+1] := #0;
  80.       MyPChar := @MyShortString[1];
  81.     end
  82.     else
  83.     begin
  84.       MyString := MyShortString;
  85.       MyPChar := PChar(MyString);
  86.     end;
  87.     Application.MessageBox(MyPChar, 'Dialog', MB_OK);
  88.   end;
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 07, 2016, 11:04:01 pm
Tnx!

(2)

the code is part of the timer2 procedure;

iTimeOut is declared each time when entering the procedure:

var
  iTimeOut: integer = 0;
  stIn: string[27];

Sorry, I wasn't clear.


(1) (3) will be investigated, tnx.

For the test I'm always sure to send a 27 character string.
( later gonna use data, but I'm sure they are send as complete length of 27 ( 8x3 + 3 )
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PStechPaul on September 08, 2016, 02:36:31 am
I think I see what you are trying to do. I assume that timer2 is an ISR that runs at a certain rate to poll the serial port and display the string. So you have a loop that runs until there are at least 27 characters in the buffer, or timeout occurs. If there is a timeout then it exits the ISR and waits for another timer2 interrupt.

It seems that it would be better to use the "FOnRxData: TNotifyEvent;" and code an event handler to process the data. And you might want to read the serial port one byte at a time so you can detect the start character and build the string until the last character is received, and then display the result. If the strings are being sent at a comfortably readable rate (up to 5/sec), you should be able to see the data change. You might also want to display the strings in a TMemo box so you can observe the sequential strings.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 08, 2016, 09:45:51 pm
Yes, Paul!

Timer2 sends to Arduino and Arduino repsonses immidiately with following code:
( by the way, I removed timer1 that indicated the system time each 1000ms )

I understand I have to change the Lazarus code and I need top learn more en get more understanding.

Next week, gonna work and use your suggestions from your previous posts! Tnx in advance!

Here my Arduino mikroPascal code
( only the main-code and procedure. Not the init etc )
After receiving/reading the string coming from Lazarus, the Arduino imidiately responds!

Just used the Usart Terminla and that shows that the string coming from Arduino are sends 100% Ok.
Defenitly I have to work on the lazarus part!



Code: Pascal  [Select][+][-]
  1. program MyProject;
  2. var
  3.   stRC: string[6];                    // in mikroPascal you MUST give a lenght in declaration!
  4.  
  5. // main
  6. begin
  7.   initCombi();
  8.  
  9. //wait for PC
  10.   while ( uart3_data_ready = 0 )
  11.     do //nothing
  12.  
  13. //mainLoop
  14.   while true do                      // Lazarus sends each 100ms
  15.     begin                               // string: '1234el'
  16.       uart3_read_text(stRC, 'el', 7 );
  17.         sendRS232();
  18.         while ( uart3_data_ready = 0 )
  19.         do; //nothing
  20.     end;
  21. end.
  22.  


procedure sendRS232 sends 1 string at a time!

It alternates between following strings when called, like a flip-flop:

'Laabbbcccdddeeefffggghhhend'       27char     

'N11222333444555666777888end'  27char

This makes it very clear to see what string is displayed or if it is a combination of 2 DIFFERENT sended string.
Sending each time the same string, doesn't make this clear to see.

For the moment, have a nce weekend, y'all!
Ciau!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Willempie on September 26, 2016, 12:58:10 pm
TLazSerial v0.1   
Serial Port Component for Lazarus (windows and linux).
by Jurassic Pork  03/2013
This library is Free software; you can rediStribute it and/or modify it
  under the terms of the GNU Library General Public License as published by
  the Free Software Foundation; either version 2 of the License, or (at your
  option) any later version.

  This program is diStributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; withOut even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  for more details.

  You should have received a Copy of the GNU Library General Public License
  along with This library; if not, Write to the Free Software Foundation,
  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. }

 Based on  :
- SdpoSerial v0.1.4
  CopyRight (C) 2006-2010 Paulo Costa
   paco@fe.up.pt
 
- Synaser library  by Lukas Gebauer
- TcomPort component


Features :
Changed :  baudrate values.
           stop bits  new value : 1.5
new event : onstatus
new property FRcvLineCRLF : if this property is true, you use RecvString
in place of RecvPacket when you read data from the port.

new procedure  ShowSetupDialog to open a port settings form :
the device combobox contain the enumerated ports.
new procedure to enumerate real serial port on linux ( in synaser).

Demo : a simulator of serial port gps + serial port receiver :
you can send NMEA frames ( GGA GLL RMC) to the opened serial port
(start gps simulator). You can change speed and heading.
In the memo you can see what is received from  the opened serial port.
In the status bar you can see the status events.

tested with windows 7 and Ubuntu 12.04
                                       
if you haven't serial ports in your PC you can use virtual ports :
1 - WINDOWS
To simulate  a paired serial ports on  windows : com0com   

2 - Linux
To simulate  a paired serial ports on linux : socat
ex :  socat -d -d PTY: PTY:

To connect to a bluetooth GPS on Linux
echo connection to a  bluetooth GPS(/dev/rfcomm0)

sudo rfcomm bind  0 xx:xx:xx:xx:xx:xx 1

====================================================================
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

====================================================================

Sorry for my poor english but it isn't my natural language.

to be continued if it is usable ....

                    J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 29, 2016, 11:05:31 pm
Hi,

after a break, started again!

Took antoher direction...with succes!

Keep in mind:

- Lazarus sends a string each 'delta-seconds', in my code: 200ms.
- There's only 1 timer in the code.

- Arduino waits for string to receive and IMMEDIALETY ( the smallest response-time ) returns a string after receiving
  what switches between Labcdend and N1234end  (  like a flip-flop )

Therefore I can do this in Lazarus:
( later it will be more sophisticated, due time-outs and more string-error-checking etc )

Still, the code is far from ok and isn't free from hanging, but now allmost each received string by pc is ok.
And now I don'ts have that strange acting from stringlenght.
( still have to investigate the comment about PAnsiChar etc )

And in case of a hang, this is after a much longer time.

( basicly the code: )
Timer:

Code: Pascal  [Select][+][-]
  1.  
  2.     sleep(3);
  3.       stIn:= serial.readData;
  4.       label4.caption:= stIn;
  5.       Memo.text:= Memo.text + stIn + '-';
  6.  
  7.  


sleep(2) instaed of sleep(3) results in sigificant much errors.

Strings are separeated by '-'.



Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 29, 2016, 11:07:02 pm
picture
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on September 30, 2016, 12:09:59 am
hello,
jb007, are you using event or sequential serial port read ?
Can you put your lazarus source code in a zip file in attachment to have a look to your code ?

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on October 01, 2016, 08:17:50 pm
Hi,

gonna to that monday-evening.

Regards.

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on October 05, 2016, 10:17:15 pm
Some more patience please....

Did some modifications.

More to come...



Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on October 06, 2016, 08:56:27 pm
Things're getting better.

See the picture added.

All string received perfect, no errors.

From time to time I delete the field of incoming strings, by clicking in the field ( memobox).
Just to be sure, I don't know much text it can contain.

In the code I've modified some thing but another major thing is that I now use the onboard RS232 port.
I had some strange acting with the extern-USB-hub with the USB-to-serial-pcbs. Dont's knowe exactly
where the problem is, but from time to the the pc messaged hardware connected/disconnected You know when you're in decive manager and thing begin to pop when connecting/disconnecting hardware. In my case that was COM 4 ( via the USB-hub...usb_to_serial etc etc )

Going to find out what the problem is, later.

Soon I'll strip my code to RS232 comucication only: remove the slide bars etc etc..to get short and clear code
and will post it here in zipp. as asked.

As next i gonna remove the texwritng in the left box, it's been tested, so don't need to see it...

send/receive each 250ms:








Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on October 06, 2016, 09:01:18 pm
AAajjj...there it is... a hang up during debugging in Lazarus.

Mousepointer can get no reaction on whatever on my form.

After a while next message apeared.

At t he time the hang up occured, I was doing more work on my pc than before...

I was posting my previous comment....

Gonna investigate!

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on October 06, 2016, 10:48:13 pm
Started new run, without displaying the incoming string. Only displaying errors.
The 1 error is deu of strat u my Arduino.

Ruuning allready for about 100 minutes...
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PStechPaul on October 06, 2016, 11:42:25 pm
About the USB serial problems, I found that some USB cables (perhaps most) have unreliable connection of the shell to the shield. The shell is just crimped to the shield over the jacket and eventually the connection becomes unreliable. Measure resistance from one end to the other, while wiggling the cable near the connector. The gold-flashed cables seem to be the best.

Also, some USB-serial adapters do not do well for closely spaced bytes of data, due to timeout issues. My communication device sends two 8 bit + 1 start + 1 stop bit as a packet, 2400 per second, at 57.6 kB. So that is 20 bits x 2400 = 48 kB, and only a short period of time between packets.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on October 07, 2016, 02:57:32 pm
Tnx!

Me too!

Now the pc-to-Arduino-RS232 is going by the pc-on-board-RS232-port.
Programming the Arduino goes via a USB-cable with a virtula-pc-serial-port.
( I had some strange 'reseting'of the Arduino, proberly  caused by a cable...


But things deffinitely have improved. No wrong strings received  :D and just occasianly I had an application-hang-up ( in both in Lazarus-Debug-Mode and in Free-Running )
Needs more investigation....

More info:

Arduino: 115200kbaud/kbps, non-parity, one stopbit.

Lazarus: 115200kbaud/kbps, non-parity, one stopbit.

At this moment, pc-sends 6 bytes, Arduino sends 28 bytes:

( say: 8 bits/byte + 1, we  round it to 10 )
115200 / 28x10 = aprox 411

Time of 1 send-period = 1 /  411 = aprox 2,4ms

SendingReceiving is done 4 times a second ( delta-T = 250ms )

All regards.

I'm very happy I'm this far ow with the whole stuf!

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on October 07, 2016, 03:34:33 pm
Measured my 4 cables included within the Arduino's...

From end to end the shield/base:

1) 44 Ohm
2) 30 Ohm
3) no Ohm at all...
4) no Ohm at all...



Grr.... >:(



Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tr_escape on October 25, 2016, 04:22:20 pm
Hello,

I have an experience about TLazSerial in that procedure:

Code: Pascal  [Select][+][-]
  1. procedure TLazSerial.DeviceClose;
  2. begin
  3.   // flush device
  4.   if FSynSer.Handle<>INVALID_HANDLE_VALUE then begin
  5.     FSynSer.Flush;
  6.     FSynSer.Purge;
  7.   end;
  8.  
  9.   // stop capture thread
  10.   if ReadThread<>nil then begin
  11.     ReadThread.FreeOnTerminate:=false;
  12.     ReadThread.MustDie:= True;
  13.     while not ReadThread.Terminated do begin
  14.       try
  15.         Application.ProcessMessages;
  16.       except
  17.         Break;   // I added this and try except block
  18.       end;
  19.     end;
  20.     ReadThread.Free;
  21.     ReadThread:=nil;
  22.   end;
  23.  
  24.   // close device
  25.   if FSynSer.Handle<>INVALID_HANDLE_VALUE then begin
  26.     FSynSer.Flush;
  27.     FSynSer.CloseSocket;
  28.   end;
  29. end;
  30.  

I have got 6 com ports and each port has diffrent configuration like as baud and protocol.
When I attempt to Close all ports sometimes my software locking and I had to close forcibly.

What whould be happen in this line?

I create a break point in that case but I couldn't catch any problem.






Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on October 26, 2016, 02:02:19 am
hello,
tr_escape, the deviceClose procedure of TLazserial comes from 5dposerial . The MustDie property of the ReadThread must stop the loop.
Code: Pascal  [Select][+][-]
  1. procedure TComPortReadThread.Execute;
  2. begin
  3.   try
  4.     while not MustDie do begin
  5.       if Owner.FSynSer.CanReadEx(100) then
  6.         Synchronize(@CallEvent);
  7.     end;
  8.   finally
  9.     Terminate;
  10.   end;
  11.  
  12. end;

Where are you when your software is locked ?

Maybe you can try this :
Code: Pascal  [Select][+][-]
  1. procedure TLazSerial.DeviceClose;
  2. begin
  3.   // flush device
  4.   if FSynSer.Handle<>INVALID_HANDLE_VALUE then begin
  5.     FSynSer.Flush;
  6.     FSynSer.CloseSocket;
  7.  //   FSynSer.Purge;
  8.   end;            

Close the port before the Mustdie.

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Mi-Ki on November 05, 2016, 05:35:13 pm
Hello.
I have a raspberry - raspbian-jessie and Lazarus 1.2.4
Why not compile LazSerial?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on November 05, 2016, 05:44:34 pm
hello,
Mi-ki, What is the error message ? 
tr_escape , have you always your problem ?

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tr_escape on November 05, 2016, 05:56:59 pm
hello,
tr_escape , have you always your problem ?

Hello,

My problem is solved there was some hardware issue. ( Usb multiplexer's power problem)
I roll backed my changes.

Thanks a lot.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Mi-Ki on November 06, 2016, 07:56:00 am
I unwrapped LazSerial.7z to /home/pi/Downloads/
Package - open package file(.lpk)
Open LazSerialPort.lpk
Compile pakage
Code: Pascal  [Select][+][-]
  1. /home/pi/Downloads/LazSerial/synafpc.pas(80,28) Hint: Parameter "Module" not used
  2. /home/pi/Downloads/LazSerial/synafpc.pas(80,48) Hint: Parameter "Buffer" not used
  3. /home/pi/Downloads/LazSerial/synafpc.pas(80,63) Hint: Parameter "BufLen" not used
  4. /home/pi/Downloads/LazSerial/synautil.pas(609,51) Warning: Symbol "TimeSeparator" is deprecated
  5. /home/pi/Downloads/LazSerial/synautil.pas(679,27) Hint: Local variable "x" does not seem to be initialized
  6. /home/pi/Downloads/LazSerial/synautil.pas(1922,3) Note: Local variable "BackStop" is assigned but never used
  7. /home/pi/Downloads/LazSerial/synautil.pas(2062,43) Warning: Symbol "ShortMonthNames" is deprecated
  8. /home/pi/Downloads/LazSerial/synautil.pas(2063,42) Warning: Symbol "ShortMonthNames" is deprecated
  9. /home/pi/Downloads/LazSerial/synautil.pas(87,22) Hint: Unit "synafpc" not used in synautil
  10. /home/pi/Downloads/LazSerial/synaser.pas(252,22) Error: Identifier not found "B500000"
  11. /home/pi/Downloads/LazSerial/synaser.pas(252,22) Error: Illegal expression
  12. /home/pi/Downloads/LazSerial/synaser.pas(253,21) Error: Identifier not found "B576000"
  13. /home/pi/Downloads/LazSerial/synaser.pas(253,21) Error: Illegal expression
  14. /home/pi/Downloads/LazSerial/synaser.pas(254,21) Error: Identifier not found "B921600"
  15. /home/pi/Downloads/LazSerial/synaser.pas(254,21) Error: Illegal expression
  16. /home/pi/Downloads/LazSerial/synaser.pas(255,23) Error: Identifier not found "B1000000"
  17. /home/pi/Downloads/LazSerial/synaser.pas(255,23) Error: Illegal expression
  18. /home/pi/Downloads/LazSerial/synaser.pas(256,23) Error: Identifier not found "B1152000"
  19. /home/pi/Downloads/LazSerial/synaser.pas(256,23) Error: Illegal expression
  20. /home/pi/Downloads/LazSerial/synaser.pas(257,23) Error: Identifier not found "B1500000"
  21. /home/pi/Downloads/LazSerial/synaser.pas(257,23) Error: Illegal expression
  22. /home/pi/Downloads/LazSerial/synaser.pas(258,23) Error: Identifier not found "B2000000"
  23. /home/pi/Downloads/LazSerial/synaser.pas(258,23) Error: Illegal expression
  24. /home/pi/Downloads/LazSerial/synaser.pas(259,23) Error: Identifier not found "B2500000"
  25. /home/pi/Downloads/LazSerial/synaser.pas(259,23) Error: Illegal expression
  26. /home/pi/Downloads/LazSerial/synaser.pas(260,23) Error: Identifier not found "B3000000"
  27. /home/pi/Downloads/LazSerial/synaser.pas(260,23) Error: Illegal expression
  28. /home/pi/Downloads/LazSerial/synaser.pas(261,23) Error: Identifier not found "B3500000"
  29. /home/pi/Downloads/LazSerial/synaser.pas(261,23) Error: Illegal expression
  30. /home/pi/Downloads/LazSerial/synaser.pas(262,23) Error: Identifier not found "B4000000"
  31. /home/pi/Downloads/LazSerial/synaser.pas(262,23) Error: Illegal expression
  32. /home/pi/Downloads/LazSerial/synaser.pas(765,1) Fatal: There were 22 errors compiling module, stopping
  33.  
In Windows it works
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on November 06, 2016, 08:18:38 am
That's because the consts for the baudrate are missing.
Code: Pascal  [Select][+][-]
  1. const
  2.     B0  = 0;
  3.   etc...
  4.  
Seems a bug in synaser.

[edit] found the cause. That is a libc dpendency. You don't need that. Just copy these consts:
The consts are in btermiosh.inc or here, just add before the first const in synaser.pas:
Code: Pascal  [Select][+][-]
  1. const
  2.    VINTR = 0;
  3.    VQUIT = 1;
  4.    VERASE = 2;
  5.    VKILL = 3;
  6.    VEOF = 4;
  7.    VTIME = 5;
  8.    VMIN = 6;
  9.    VSWTC = 7;
  10.    VSTART = 8;
  11.    VSTOP = 9;
  12.    VSUSP = 10;
  13.    VEOL = 11;
  14.    VREPRINT = 12;
  15.    VDISCARD = 13;
  16.    VWERASE = 14;
  17.    VLNEXT = 15;
  18.    VEOL2 = 16;
  19.  
  20.   IGNBRK    = $0000001;
  21.   BRKINT    = $0000002;
  22.   IGNPAR    = $0000004;
  23.   PARMRK    = $0000008;
  24.   INPCK     = $0000010;
  25.   ISTRIP    = $0000020;
  26.   INLCR     = $0000040;
  27.   IGNCR     = $0000080;
  28.   ICRNL     = $0000100;
  29.   IUCLC     = $0000200;
  30.   IXON      = $0000400;
  31.   IXANY     = $0000800;
  32.   IXOFF     = $0001000;
  33.   IMAXBEL   = $0002000;
  34.  
  35.   OPOST     = $0000001;
  36.   OLCUC     = $0000002;
  37.   ONLCR     = $0000004;
  38.   OCRNL     = $0000008;
  39.   ONOCR     = $0000010;
  40.   ONLRET    = $0000020;
  41.   OFILL     = $0000040;
  42.   OFDEL     = $0000080;
  43.  
  44.   NLDLY     = $0000040;
  45.   NL0       = $0000000;
  46.   NL1       = $0000100;
  47.   CRDLY     = $0000600;
  48.   CR0       = $0000000;
  49.   CR1       = $0000200;
  50.   CR2       = $0000400;
  51.   CR3       = $0000600;
  52.   TABDLY    = $0001800;
  53.   TAB0      = $0000000;
  54.   TAB1      = $0000800;
  55.   TAB2      = $0001000;
  56.   TAB3      = $0001800;
  57.   BSDLY     = $0002000;
  58.   BS0       = $0000000;
  59.   BS1       = $0002000;
  60.   FFDLY     = $0080000;
  61.   FF0       = $0000000;
  62.   FF1       = $0010000;
  63.  
  64.   VTDLY     = $0004000;
  65.   VT0       = $0000000;
  66.   VT1       = $0004000;
  67.  
  68.   XTABS     = $0001800;
  69.  
  70.   CBAUD     = $000100F;
  71.   B0        = $0000000;
  72.   B50       = $0000001;
  73.   B75       = $0000002;
  74.   B110      = $0000003;
  75.   B134      = $0000004;
  76.   B150      = $0000005;
  77.   B200      = $0000006;
  78.   B300      = $0000007;
  79.   B600      = $0000008;
  80.   B1200     = $0000009;
  81.   B1800     = $000000A;
  82.   B2400     = $000000B;
  83.   B4800     = $000000C;
  84.   B9600     = $000000D;
  85.   B19200    = $000000E;
  86.   B38400    = $000000F;
  87.  
  88.   EXTA      = B19200;
  89.   EXTB      = B38400;
  90.  
  91.   CSIZE     = $0000030;
  92.   CS5       = $0000000;
  93.   CS6       = $0000010;
  94.   CS7       = $0000010;
  95.   CS8       = $0000030;
  96.   CSTOPB    = $0000040;
  97.   CREAD     = $0000080;
  98.   PARENB    = $0000100;
  99.   PARODD    = $0000200;
  100.   HUPCL     = $0000400;
  101.   CLOCAL    = $0000800;
  102.  
  103.   CBAUDEX   = $0001000;
  104.  
  105.   B57600    = $0001001;
  106.   B115200   = $0001002;
  107.   B230400   = $0001003;
  108.   B460800   = $0001004;
  109.   B500000   = $0001005;
  110.   B576000   = $0001006;
  111.   B921600   = $0001007;
  112.   B1000000  = $0001008;
  113.   B1152000  = $0001009;
  114.   B1500000  = $000100A;
  115.   B2000000  = $000100B;
  116.   B2500000  = $000100C;
  117.   B3000000  = $000100D;
  118.   B3500000  = $000100E;
  119.   B4000000  = $000100F;
  120.  
  121.   CIBAUD    = $100F0000;
  122.   CRTSCTS   = $80000000;
  123.  
  124.   ISIG      = $0000001;
  125.   ICANON    = $0000002;
  126.  
  127.   XCASE     = $0000004;
  128.  
  129.   ECHO      = $0000008;
  130.   ECHOE     = $0000010;
  131.   ECHOK     = $0000020;
  132.   ECHONL    = $0000040;
  133.   NOFLSH    = $0000080;
  134.   TOSTOP    = $0000100;
  135.  
  136.   ECHOCTL   = $0000200;
  137.   ECHOPRT   = $0000400;
  138.   ECHOKE    = $0000800;
  139.   FLUSHO    = $0001000;
  140.   PENDIN    = $0004000;
  141.  
  142.   IEXTEN    = $0010000;
  143.  
  144.  
  145.  
  146.   TCOOFF = 0;
  147.   TCOON = 1;
  148.   TCIOFF = 2;
  149.   TCION = 3;
  150.   TCIFLUSH = 0;
  151.   TCOFLUSH = 1;
  152.   TCIOFLUSH = 2;
  153.   TCSANOW = 0;
  154.   TCSADRAIN = 1;
  155.   TCSAFLUSH = 2;
  156.  
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on November 06, 2016, 11:22:25 am
hello,
Mi-Ki you can also see here (http://forum.lazarus.freepascal.org/index.php/topic,20481.msg141721.html#msg141721) (at the end of the message) and here (http://forum.lazarus.freepascal.org/index.php/topic,20481.msg141726.html#msg141726) .

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on November 06, 2016, 11:53:54 am
Yeah, because the length of the thread I overlooked that. Still my answer touches on where to really find it and the answer should really be a bug report to LG.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Mi-Ki on November 09, 2016, 10:14:17 am
It succeeded, thank  :D
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on November 09, 2016, 10:25:39 am
All three correct answers are correct  8-) O:-) :P
Works everywhere, btw.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Mi-Ki on November 09, 2016, 02:06:28 pm
Has anyone tried the raspberry Lazarus communication with Arduino?
Reading and writing.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on November 09, 2016, 05:41:26 pm
Has anyone tried the raspberry Lazarus communication with Arduino?
Reading and writing.
Any problems? I can test it, if you want. RS232 communications over USB works,
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on November 14, 2016, 07:37:56 pm
Things have been been improved, significant!

Removed the small USB-hub's and placed a PCI-to-4xRS232 ( about 15 USD )in my pc.

From time to time, running in Lazarus-Debug-mode, the stuff hangs for few seconds and continieus again, but again: much less than before.

The send/received data is ok, no wrong characters or drop-outs!

Gonna debug-Run again  but ow with no other programm's open like internet and my mikropascal-IDE for Arduino.

To be continued.

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on November 14, 2016, 08:32:02 pm
Things have been been improved, significant!

Removed the small USB-hub's and placed a PCI-to-4xRS232 ( about 15 USD )in my pc.

From time to time, running in Lazarus-Debug-mode, the stuff hangs for few seconds and continieus again, but again: much less than before.

The send/received data is ok, no wrong characters or drop-outs!

Gonna debug-Run again  but ow with no other programm's open like internet and my mikropascal-IDE for Arduino.

To be continued.



Something else had more effect!


Briefly, the 'code':

In Lazarus I send the same sting ( just 6 characters) to Arduino 'A' and Arduino 'B'.
A and B receive, check and respond with a given string ( 30 characters ).
Lazarus DOES read and check the string from 'A'.
lazarsus DOES NOT read ( and check ) the string from 'B'.

When I just entered a read 'B' code in Lazarus things improved.

I gues: the data NEEDS to be read. When read, this does something to the pc/Lazarus/RS232-buffer etc...


I know in the Arduino is something happening like that:
The Arduino takes care of the incoming data.
'You'r code' checks for data and reads these data.
After that reading, something is set/reset in the UART of the Arduino )

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on November 15, 2016, 07:50:52 pm
Here you can see what acuately happens.


- pc-Lazarus sending to Arduino-mikroPascal -

- Arduino-mikroPascal sending to pc-Lazarus -

Now everythings is working pretty fine, there's no problem to set the timer on 25ms ( sending 40x per second ).



Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on November 15, 2016, 07:51:49 pm
Zoom:
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on November 15, 2016, 07:52:29 pm
By the way: can I ( and how ) to post multiple pictures in 1 comment?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on November 17, 2016, 09:40:58 pm
YES!

Got the 8 ADC-values on pc-screen!

Took some time, had a big fight handling strings... :D

Nice and smooth now, 10bit values, refresh rate 4/sec.

Have to programm hysteresis for each channel.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on November 17, 2016, 09:41:20 pm
Screenshot:

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on November 17, 2016, 09:45:28 pm
Next thing to do is to extend these 'Playstation-2 joysticks' with extra function.

Original they contain:
- potmeter for X
- potmeter for Y
- push button


Gonna ad a potmeter on the lever under the button, so you can move in X and Y AND at the same time you can rotate the button itself.

 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: krolikbest on December 08, 2016, 12:03:22 pm
Hello,

I have RPi3 and PC with winXP. Try to send and receive datas via serial port. Connected GPIO via "shifter 3.3v" to PC. On Pc hyperterminal and on RPi3 form with button_connect, button_send, memo and one LazSerial1. In method RxData of LazSerial1 simply
<code>
str:=LazSerial1.ReadData;
memo1.Lines.Add(str);
</code>
After connection I click on button_send where is only: "LazSerial1.WriteData('aaa')"
and in hyperterminal I received 'aaa', so it works. But when I try to send something from hyperterminal to RPi3 then I get only something like empty line(no one visible sign), but every time I send from hyperterminal I notice that scrollbar of memo1 becomes smaller......
The same program in lazarus but compiled on win32 works well on PC.
Transmission:9600, 8,N,1, no flowcontrol.

Martin


Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on December 08, 2016, 12:14:47 pm
run "sudo raspi-config", choose "advanced" choose  "A8 serial" and enable it. It is disabled by default. It says it is for a shell, but in fact you also need it to run software over serial. It is the serial interface!

Plz report back if it doesn't work. I personally use a patched synaser (from synapse distro) for serial work on RPi3
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: krolikbest on December 08, 2016, 09:59:23 pm
Hi,

I have it already enabled, i'm sending from RPi to PC machine, but still can't receive any text from hyperterminal on PC.. I wonder maybe something is wrong with settings of hyperterminal, but why in this case two PC machines work well (I mean one have my program and second hyperterminal)?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on December 08, 2016, 11:01:04 pm
hello,
are you sure that Hyperterminal doesn't send a CRLF when you send something ? Unix doesn't like so much a CRLF. 
try to use a lazarus program with tlazserial or another windows serial program (teraterm for example) on your XP PC.

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: krolikbest on December 09, 2016, 12:59:54 pm
Hi,

firstly thank you for your interest in this problem.
And secondly ;)

I've tested yesterday on PC hyperterminal and RPi3 with installed minicom. And it works but very very slow... I send few signs form PC hyperterminal e.g. 'www' (set local echo ON in order to see what should be sent) but minicom received only one 'w'. What else I have noticed, that during sending from PC to RPi both diodes of "shifter 3.3" (based on max3232) blinked, while from RPi to PC only one diode. Maybe it should be.
Connection looks like http://www.savagehomeautomation.com/projects/raspberry-pi-rs232-serial-interface-options-revisit.html (http://www.savagehomeautomation.com/projects/raspberry-pi-rs232-serial-interface-options-revisit.html).
The problem seems to be beyond Lazarus. I will test what you described Jurassic Pork.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: krolikbest on December 09, 2016, 09:10:07 pm
It was really beyond Lazarus and the solution my young padawans 8) isdescribed there:
1.http://www.hobbytronics.co.uk/raspberry-pi-serial-port (http://www.hobbytronics.co.uk/raspberry-pi-serial-port)

but it can be that by accident you own RPi3 where there is NOT /etc/inittab
and than you should in shell simply write:
sudo systemctl stop serial-getty@tty<YOUR SERIAL>.service
where <YOUR SERIAL> I have S0, so the whole MY line looks like:
sudo systemctl stop serial-getty@ttyS0.service
Now everything works. <SOLVED>
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on December 15, 2016, 11:12:10 am
Hi!

Got my RS232 running pretty smooth and the bottom-message shows 'ReadCount : 25'.




From time time to it shows 'Can Read : '

I noticed that this happens at least as I scroll the mouse to scroll internet page.
After this, there apears the 'ReadCount : 25'.

Can someone explain th apearing of that 'CanRead : '?
 

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on December 16, 2016, 02:30:08 pm
hello,
if you have the message canread in the status bar of your program (if you use the same thing that in the sertest example) it is because you have a canread event :
Code: Pascal  [Select][+][-]
  1. procedure TFMain.SerialStatus(Sender: TObject; Reason: THookSerialReason;
  2.   const Value: string);
  3. begin
  4.   case Reason of
  5.     HR_SerialClose : StatusBar1.SimpleText := 'Port ' + Value + ' closed';
  6.     HR_Connect :   StatusBar1.SimpleText := 'Port ' + Value + ' connected';
  7.     HR_CanRead :   StatusBar1.SimpleText := 'CanRead : ' + Value ;
  8.     HR_CanWrite :  StatusBar1.SimpleText := 'CanWrite : ' + Value ;
  9.     HR_ReadCount : StatusBar1.SimpleText := 'ReadCount : ' + Value ;
  10.     HR_WriteCount : StatusBar1.SimpleText := 'WriteCount : ' + Value ;
  11.     HR_Wait :  StatusBar1.SimpleText := 'Wait : ' + Value ;
  12.   end ;            

if you want  to know why ,  look at in the synaser file    synaser.pas .  Or comment the line :
Code: Pascal  [Select][+][-]
  1.  HR_CanRead :   StatusBar1.SimpleText := 'CanRead : ' + Value ;

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on December 17, 2016, 12:45:59 pm
Hi, Jurassic Pork!

 tnx, gonna check that next week.

Still working on my RS232, slowly...


But I recognized some things recarding to 'hang-ups'!

For example I got significant more hang-ups
by timer2.interval:= 250 [ms] in comparision to timer2.interval:= 200ms.

Now I experimentate with different lower intarvals, thing look to improve.

( Of course, I'm sure that the  sending/receiving-time + other-code-time-like Arduino-ADC, is safely short in comparision to the
  interval, otherwise you get problems.

Now it's running at interval:= 50ms...


For now, have a nice weekend!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on December 22, 2016, 09:35:03 pm
Now I have placed on each a mini joystick a pottie.

So eacht stick has now X,Y,rotate and pushbutton.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on January 11, 2017, 10:20:51 am
Hi,

working fine!


About my RS232 code: I don't like the delay in Laz, coded due of waiting for response/answer Arduino.
Even when Arduino's response is immidiately! ( Arduino's ADC-data ect.. allready processed and ready for Laz )

Gonna take another aproach: if a delay is needed, than better in the Arduino!



Timer50ms:
begin
1) read data from Arduino 
2) send to Arduino
3) 'process received data'
end;


//Other code:
procedure 'proces received data'


Before entering Timer for the first time, gonna do  ' 2) send to Arduino ' once, by  using kinda  boolean: bFirstEntering etc...   


Regards.










Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on January 11, 2017, 10:40:08 am
DSR/DSL? Timing is arbitrary, the device will signal.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on January 13, 2017, 11:26:12 am
Hi, Thaddy.

Thank you and others for advice!

My Laz-RS232-code, definitely needs to be more sophisticated.
It works, no hangups etc, but it's jus not...you know!


At this moment, both pc-Lazarus and Arduini-mikroPascal are without delay.
Works fine!

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: pieterroos on January 16, 2017, 10:27:54 am
Hi
I am new to this forum, so excuse me if I do something wrong. I used TSdposerial component, but it is limited in the sense that it can only receive data in a string format. This is very annoying for me, as I use the component to create an interface between a PC and embedded systems. I often have to transfer binary data and the moment the embedded system transmit a 0x00 character, the data stream gets terminated on the PC side. So this morning I searched for a new serial port component and found LasSerial component. But it seems to work exactly the same as Tsdposerial component. Are there any way to receive binary data from the serial port without a 0x00 character interfering?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on January 16, 2017, 05:45:20 pm
hello,
with the sertest example of TLazserial if i replace the     procedure SerialRxData by this :

Code: Pascal  [Select][+][-]
  1. procedure TFMain.procedure TFMain.SerialRxData(Sender: TObject);
  2. var S,HexaS : string;
  3.     i : integer;
  4. begin
  5.   S := Serial.ReadData;
  6.   for I := 1 to Length(S) do begin
  7.     HexaS := HexaS + InttoHex(Ord(S[I]),2)+ ' ';
  8.   end;
  9. Memo.lines.Add(HexaS);

if i send this  (hexa bytes comma delimited) :  4B,4C,4D,4E,4F,50,51,52,53,54,55,56,57,58,59,5A,00
to the received port of Tlazserial component  I can see this in the received window of sertest :
Quote
4B 4C 4D 4E 4F 50 51 52 53 54 55 56
57 58 59 5A 00


Friendly J.P

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on January 17, 2017, 07:06:54 am
hello,
version with temp buffer :
Code: Pascal  [Select][+][-]
  1. // global variables
  2. var  CurPos : integer;
  3.   FTempStr: String;        
  4. // ========================================
  5. procedure TFMain.SerialRxData(Sender: TObject);
  6. var S,HexaS : string;
  7.     i : integer;
  8. begin
  9.     S :=  Serial.ReadData;
  10.        CurPos := Pos( Char(0) ,S);
  11.        if CurPos = 0 then begin
  12.     // Wait for end of frame ( 0x00 )
  13.     // Data put in temp String Buffer FTempStr
  14.           FTempStr := FTempStr + S;
  15.        end
  16.       else begin
  17.     // End of frame :  FTempStr contains the whole frame
  18.          FTempStr := FTempStr + Copy( S, 1, CurPos-1);
  19.     // code to display in hexa the received frame
  20.       for I := 1 to Length(FTempStr) do begin
  21.            HexaS := HexaS + InttoHex(Ord(FTempStr[I]),2)+ ' ';
  22.        end;
  23.       Memo.Lines.BeginUpdate;
  24.       Memo.Lines.Add(HexaS);
  25.       Memo.Lines.EndUpdate;
  26.       Memo.SelStart := Length(Memo.Lines.Text)-1;
  27.       Memo.SelLength:=0;
  28.       // data after the end of frame are put in the buffer
  29.       FTempStr := Copy(S,CurPos +1, Length(S) - CurPos);
  30.       end;
  31. end;                              
  32.  

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: ddimov007 on January 20, 2017, 07:38:31 pm
Hello guys,

I can't get the expected baud rates when using LazSerial on a Raspberry pi hardware with Jessy and with some code modification on my side.
I can't figure out what it could be wrong. Please HELP:

prerequisites:
-I am very new to programming on RPi and I haven't got too much knowledge about the actual UART hardware that is behind ttyAMA0. I am not even sure if this is released by RPi foundation.
-running RPi 3
-full and latest update of the whole system
- download and installed compiled latest Lazarus 3.1.1.
- fixed the missing coutbegin.o coutend.o links (now no warnings when compiling)
- enabled com port
- swapped and returned back the two serial ports (for some reason LazSerial only wants to talk to ttyAMA0)
- disabled console
- disabled Bluetooth to allow communication to be directed to IO port pins
- changed uart clock: "init_uart_clock=64000000"
- hooked a trusty modern 140Mpoints scope to the TX pin

 
Tested all the above with minicom:  "minicom -b 4000000 -o -D /dev/ttyAMA0"
I must say it works beautifully!

Now, my application with Lazarus: Lazarus itself works great, at least I have no doubts about the installation and compiling yet.
I modified LazSerial component to include baud rates 1000000, 2000000, 3000000 and 4000000.
The result is quite poor: I get 500Kbps when setting 1Mbit (please check the table of results below). If I initialise the port through minicom @4Mbps and only send data through my application then I get the 4Mbps out of the TX pin (for some reason both minicom and my application can share the serial port without conflicts).

I modified again LazSerial component to remove the definitions for baud rates. Now I can set any integer baud rate instead of selecting one of several populated in the ComboBox of the component.
In the process of doing that I also removed some code that was checking for out of range baud rate values.

Below is a table of what I am setting and what I get:
Set baud rate | Measured baud rate
1Mbps           |  500 Kbps
2Mbps           |  588.2 Kbps
3Mbps           |  952.4 Kbps
4Mbps           |  1Mbps

The low baud rates are also messed up.

My aim is to get the 1-4Mbps working.

I suspect there is some variable which overflows.

Has anybody got any idea where in the code of LazSerial and/or any required packaged I should look for the problem?

Some of the code I came across was written by "Jurassic Pork".
Jurassic Pork, do you have any ideas?

I will be happy to share the code if required. Just let me know.

Many thanks in advance!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on January 21, 2017, 11:25:52 am
hello,
there is a new version of TLazSerial    :
Quote
V 0.2  01/2017 : BaudRates for UNIX fixed - synaser files units renamed (with laz prefix)
 scan port for linux improved

TLazserial is now in Github    here (https://github.com/JurassicPork/TLazSerial)
the 0.2 version is the master version (in progress)

Be careful ! someone (zbyna) has created another version of TLazserial in github with the version 0.1 of TLazserial . It is not the official version !!!!

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: ddimov007 on January 22, 2017, 09:39:20 am
Thanks 10x JP!
I will test this first thing on Monday.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: avra on January 22, 2017, 04:25:39 pm
-running RPi 3
- enabled com port
- swapped and returned back the two serial ports (for some reason LazSerial only wants to talk to ttyAMA0)
- disabled console
- disabled Bluetooth to allow communication to be directed to IO port pins
- changed uart clock: "init_uart_clock=64000000"
RPi 3 behaves different then RPi 1 and 2. If you have older Pi available then test if it works. Read this: http://www.briandorey.com/post/Raspberry-Pi-3-UART-Overlay-Workaround. If you search the net for "Raspberry Pi 3B UART BT problems" you will see that there are a lot of problems, especially that UART speed is tied to clock which can change dynamically. Try to have some low fixed speed and turn off all power savings. Old Pi had UART0 as serial interface, but in Pi3 UART0 is used for Bluetooth so without a workaround UART1 on GPIO14 & 15 should be used. The reason why this was changed is that UART0 was influenced by the core_freq and that's important for BT. However nothing stops you to try some other Linux flavor like Arch or TinyCore, or bare metal like Ultibo, and see if something is different or fixed. See also http://raspberrypi.stackexchange.com/questions/45570/how-do-i-make-serial-work-on-the-raspberry-pi3 and http://raspberrypi.stackexchange.com/questions/45143/how-to-disable-dma-when-using-uart-on-the-raspberry-pi-2.

Quote
- hooked a trusty modern 140Mpoints scope to the TX pin
Are you measuring directly on Pi header pin or later from some RS232 voltage levels? Do you send a single char or thousands in your tests (FIFO is just 8 bytes)?

Quote
Tested all the above with minicom:  "minicom -b 4000000 -o -D /dev/ttyAMA0"
I must say it works beautifully!
Can you try to send some big file with nothing else but thousands of 'U' characters directly to port with redirection from command line without using minicom and report if you still find that it works as good as in minicom. Then try to send the same file from minicom and report if it behaves exactly the same. Btw, are your tests from Pi booted to console, or you are running some desktop and window manager? Can you retest your Lazarus application just from console, before any desktop is booted?

Quote
I modified LazSerial component to include baud rates 1000000, 2000000, 3000000 and 4000000.
The result is quite poor: I get 500Kbps when setting 1Mbit (please check the table of results below). If I initialise the port through minicom @4Mbps and only send data through my application then I get the 4Mbps out of the TX pin (for some reason both minicom and my application can share the serial port without conflicts).
Can you take a look into minicom sources to see how it does the port setup? Can you show the simplest code you use for testing? How do you initialize port from LazSerial? Maybe your modifications are not enough. You can try some other serial library like Platform eXtended Library (PXL), or directly latest trunk version of Synapse SynaSer. You can also try to setup port from command line before use in your application. If that works then you can call script or external sh process from your application.

Additional info you might be interested in:
https://www.raspberrypi.org/forums/viewtopic.php?t=57845&p=438417
https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=17559
https://github.com/hzeller/rpi-gpio-dma-demo
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: ddimov007 on January 23, 2017, 05:40:52 pm
JP,

Can you share your definitions for thermios.inc?




hello,
there is a new version of TLazSerial    :
Quote
V 0.2  01/2017 : BaudRates for UNIX fixed - synaser files units renamed (with laz prefix)
 scan port for linux improved

TLazserial is now in Github    here (https://github.com/JurassicPork/TLazSerial)
the 0.2 version is the master version (in progress)

Be careful ! someone (zbyna) has created another version of TLazserial in github with the version 0.1 of TLazserial . It is not the official version !!!!




Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on January 24, 2017, 06:16:24 am
Hello,
JP,
Can you share your definitions for thermios.inc?

Why ? I haven't changed the file termios.inc
The file termios.inc for linux is in the folder  Lazarus/fpc/3.0.0/source/rtl/linux

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: ddimov007 on January 24, 2017, 10:45:41 am
Hi JP,

My termios.inc doesn't have the definitions for the baud rates, used in the latest version of  Lazserial V0.2 (B2000000, B4000000...).
At least I don't have the correct one on my system. Without the constant definitions in termios.inc Lazserial would not compile without modifications.

However, because I only need one baud rate I figured by testing and guesswork what the constant is for 4Mbps and now it works well for that baud rate.
Others would probably benefit from having termios.inc too.


I take the opportunity to thank you for your help and also Avra: Apologies I didn't reply to Avra - there was a lot of food for though in his post and plenty of resources to look at.


Many thanks!

Hello,
JP,
Can you share your definitions for thermios.inc?

Why ? I haven't changed the file termios.inc
The file termios.inc for linux is in the folder  Lazarus/fpc/3.0.0/source/rtl/linux

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Migrant on February 11, 2017, 04:29:56 pm
Dear Antico Porco,

Many thanks for updating this essential package, which should be part of the standard Lazarus distribution.

I used the original spdoserial code, with some difficulty.

However, using your ReadData function, lines greater than 64 characters have a CR/CRLF inserted, which corrupts my incoming packets.
--------------------------------
($.A539738020202020000FC1800009C40ED44C7CE257812BD3B0002010100098
DF237)
--------------------------------

I have added the RecvTerminated function into your LazSerial.pas file, from the original sdposerial.pas.

---------------------------------------
function TLazSerial.RecvTerminated(timeout: integer; const EndTerm: ansistring): string;
begin
  result:='';
  if FSynSer.Handle=INVALID_HANDLE_VALUE then
    ComException('can not read from a closed port.');
  result:=FSynSer.RecvTerminated(timeout,EndTerm);
end;
---------------------------------------

This now works beautifully; would you consider adding this function into your release package please?

Thanks again for your efforts.

Migrant
 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 12, 2017, 05:14:25 am
hello,
Migrant i can add your function in TLazSerial  component but before i want to understand why you have a problem with readdata function.

1 - What is your serial port baudRate ?
2 - What is your Terminator String ?
3 - What is your data frame length ?
4 - When you use Readdata , do you use a temp Buffer like this ? :
Code: Pascal  [Select][+][-]
  1.  procedure TFMain.SerialRxData(Sender: TObject);    
  2. var Str : string;
  3. begin
  4.   Str :=  Serial.ReadData;
  5.   CurPos := Pos( Char(10) ,Str);
  6.   if CurPos = 0 then begin
  7.     FTempStr := FTempStr + Str;
  8.   end
  9.   else begin
  10.     FTempStr := FTempStr + Copy( Str, 1, CurPos-1);
  11.     Memo.Lines.BeginUpdate;
  12.     Memo.Lines.Add(FtempStr);
  13.      Memo.Lines.EndUpdate;
  14.     Memo.SelStart := Length(Memo.Lines.Text)-1;
  15.     Memo.SelLength:=0;
  16.     AnalyseTrames(FtempStr);
  17.     FTempStr := Copy(Str,CurPos +1, Length(Str) - CurPos);
  18.   end;    
  19.  end;

 I have tried to use the RecvTerminated function like this :
 
Code: Pascal  [Select][+][-]
  1. procedure TFMain.SerialRxData2(Sender: TObject);      
  2.  var Str : string;
  3. begin
  4.   Str :=  Serial.RecvTerminated(1000,Chr(13)+Chr(10));
  5.   if Serial.SynSer.LastError = 0 then
  6.   begin
  7.     Memo.Lines.BeginUpdate;
  8.     Memo.Lines.Add(Str);
  9.      Memo.Lines.EndUpdate;
  10.     Memo.SelStart := Length(Memo.Lines.Text)-1;
  11.     Memo.SelLength:=0;
  12.   end
  13.   Else
  14.     begin
  15.        Memo.Lines.Add('Error : ' + Serial.SynSer.LastErrorDesc);
  16.     end;
  17.   end;  

it's OK but if you receive data without terminator string the program can freeze. 

Readdata use recvpacket function of synaser :
 
Quote
Read all available data and return it in the function result string.
 
never freeze the program.

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on February 12, 2017, 08:28:53 am
Hm yes, that nasty terminator. On raw data you can avoid it easily by using RcvStreamSize procedure  and WaitingData function. No string terminator.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Migrant on February 12, 2017, 11:41:31 am
Dear JP,
Thanks for your swift response.

1 - What is your serial port baudRate ?  115200baud
2 - What is your Terminator String ?       STARTC='('; ENDC=')'
3 - What is your data frame length ?      Variable
4 - When you use Readdata , do you use a temp Buffer like this ? : See below

Code: Pascal  [Select][+][-]
  1. procedure TConsole.LazSerial1RxData(Sender: TObject);
  2. var
  3.   indata : string;
  4.   data   : string;
  5.   x,l    : integer;
  6. begin
  7.   if (LazSerial1.Active=TRUE) and (LazSerial1.DataAvailable=TRUE) then
  8.   begin
  9. //    LazSerial1.WriteData(XOFF);  //Stall for time....
  10. //    indata:=LazSerial1.ReadData;
  11.     indata:=LazSerial1.RecvTerminated(0,ENDC);
  12.     l:=Length(indata);
  13.     if (MAXPKTSIZE>l) then
  14.     begin
  15.       if (l>1) then
  16.       begin
  17.         x:=pos(STARTC,indata);
  18.         data:=Copy(indata, x, l);
  19.         if (data[1]=STARTC) then
  20.         begin
  21.             PktRdy:=true;
  22.           Console.mRx.Lines.Add(data+ENDC);
  23.           Console.ImageList1.GetBitmap(GRNLED,Console.RxLED.Picture.Bitmap);
  24.           Console.RxLEDTimer.Enabled:=FALSE;
  25.           Console.RxLEDTimer.Interval:=100;
  26.           Console.RxLEDTimer.Enabled:=true;
  27.           Packets.BreakPkt(data);
  28.         end;
  29.       end;
  30.     end;
  31.     LazSerial1.WriteData(XON);
  32.   end;
  33. end;  
  34.  


Migrant
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 12, 2017, 04:54:55 pm
hello,
i have tried to simulate data like you  have  and  using readdata to read the data with a temp Buffer. It seems to be OK  (at speed 9600 and 115200) .

Data send  every 2 seconds :
Quote
(00112233445566778899abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)
Global variable :
Code: Pascal  [Select][+][-]
  1.  CurPos : integer;
  2.   FTempStr: String;

the procedure   

Code: Pascal  [Select][+][-]
  1. procedure TFMain.SerialRxData2(Sender: TObject);
  2. var Str : string;
  3. begin
  4. Str := Serial.Readdata;
  5. CurPos := Pos(')' ,Str);
  6.   if CurPos = 0 then begin
  7.      // put data in buffer string if no terminator
  8.      FTempStr := FTempStr + Str;
  9.    end
  10.   else
  11.   begin
  12.     FTempStr := FTempStr + Copy( Str, 1, CurPos-1);
  13.     ;
  14.     if FtempStr[1] = '(' then
  15.          begin
  16.            // remove first chr  
  17.            delete(FtempStr,1,1);
  18.            // display data in a memo
  19.            Memo.Lines.BeginUpdate
  20.            Memo.Lines.Add(FtempStr);
  21.            Memo.Lines.EndUpdate;
  22.            //scroll
  23.            Memo.SelStart := Length(Memo.Lines.Text)-1;
  24.            Memo.SelLength:=0;
  25.          end;    
  26.       FTempStr := Copy(Str,CurPos + 1, Length(Str) - CurPos);
  27.   end;
  28.   end;  

Result in attachment

Friendly, J.P

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Migrant on February 12, 2017, 06:39:35 pm
Dear JP,

I incorporated your code and I still get a wrapped line; see ReadData.png
The Rx memo is directly displaying the buffer from ReadData.

Code: Pascal  [Select][+][-]
  1. procedure TConsole.LazSerial1RxData(Sender: TObject);
  2. var Str : string;
  3. begin
  4. Str := LazSerial1.Readdata;
  5. Console.mRx.Lines.Add(Str);  
  6.  
  7.  

The correct handling is shewn in RecvTerminated.png

The next thing to do is to OutHex the buffer contents to find the inserted character(s).

BTW, I'm developing under 64-bit Windows-7 and porting to a Raspberry Pi 3 target.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Migrant on February 12, 2017, 09:51:31 pm
Okay, I've dumped the same packet using both methods; the one labelled "BAD" is the ReadData method.
There are two bytes in error, should be $91, but is instead $FB
I'm rightly getting checksum errors and therefore no data!


 (  $  .  A  5  3| E  8| 3  8| 0  5| 0  5| 0  5| 0  2| F  B| E  D| 0  0| 0  0  0  0  0  0  0  3  E  8  E  B  8  5  C  7  A  F  0  0  6  4  0  0  0  A  0  8  0  2  0  5  0  1  0  1  0  0  0  9  A  D  F  2  2  3  )
28/24/2E/41/35/33/45/38/33/38/30/35/30/35/30/35/30/32/46/42/45/44/30/30/30/30/30/30/30/30/30/33/45/38/45/42/38/35/43/37/41/46/30/30/36/34/30/30/30/41/30/38/30/32/30/35/30/31/30/31/30/30/30/39/41/44/46/32/32/33/29/BAD
28/24/2E/41/35/33/45/30/33/38/30/35/30/35/30/35/30/32/39/31/45/44/30/30/30/30/30/30/30/30/30/33/45/38/45/42/38/35/43/37/41/46/30/30/36/34/30/30/30/41/30/38/30/32/30/35/30/31/30/31/30/30/30/39/31/37/46/32/36/36/29/GOOD
 (  $  .  A  5  3| E  0| 3  8| 0  5| 0  5| 0  5  0  2  9  1  E  D  0  0  0  0  0  0  0  0  0  3  E  8  E  B  8  5  C  7  A  F  0  0  6  4  0  0  0  A  0  8  0  2  0  5  0  1  0  1  0  0  0  9  1  7  F  2  6  6  )
                                                       ^  ^
                                                       91 is correct


Time for a beer.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: allan.brito on March 08, 2017, 04:02:07 pm
Hello Everybody,

I'm using LazSerial and it's very useful, but I'm getting some trouble because I want to receive 15 bytes from a barCode Scanner and I can't get it. In Java I get it because i put that I'm receiving 15 bytes. Can anyone help me in this case? Thanks in Advance.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on March 08, 2017, 04:49:27 pm
Well. There still isn't an overloaded function ReadData(Size) for that. It is still string instead of buffer of byte, with length... (That's why I don't use it!)
Since "//    function ReadBuffer(var buf; size: integer): integer;"  is not available....
Why? Dunno, I simply ignore LazSerial and use synaser direct. Lazserial is a bit of a hoax anyway.  It hardly adds anything useful. (I am opiniated  ;D :D,don't take that too serious )
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: allan.brito on March 08, 2017, 05:35:49 pm
No problem, I'm new in this language and LazSerial had helped me so much. And Thanks everybody, I get it... I had to disable the RcvLineCRLF and worked well. Thanks.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Stan17 on April 06, 2017, 10:05:16 am
Is it supposed to be working under Win 7 64 Lazarus 1.6.4 64?
When I am trying to install the package, I am getting notorious
"CPort.pas(28,1) Fatal: Syntax error, "identifier" expected but "TYPE" found"
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on April 08, 2017, 03:48:09 am
hello,
Strange !   :-\  because cport.pas belongs to the comport library not lazserial.

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on August 28, 2017, 06:19:36 pm
Still working at my RS232.

Just got aware that the first position of a char in a Lazarus string is not  [ 0 ]  but  [ 1 ]...

( have done and still do some other languages... :D...so, no wonder... )

Ocasional things went somehow 'semi-ok' but other times totaly messed-up.


Things are improving rappidly and are now stable at all!





Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on August 28, 2017, 07:56:37 pm
hello,
jb007, are you using event or sequential serial port read ?
Can you put your lazarus source code in a zip file in attachment to have a look to your code ?

Friendly, J.P

Tnx.

Past time, I concentraded on learning/coding the Atmega2560 using mikroPascal AVR.

Recently started again at Lazarus RS232. ( in combination with the Arduino 2560 )

I hope to send you the code in a couple of days.

First I want to strip down the code of all unneeded code, to get a better view etc.

Kind regards!












Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on September 01, 2017, 10:29:17 pm
For you all: a good weekend!

Cheers!




Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jlopez on October 15, 2017, 06:38:57 am
I am working with TLazSerial to collect data from weight indicators. I had to change the property  RcvLineCRLF: Boolean, for RcvLineTerminated: String, to use this component. There are devices that use another termination like LF, not CRLF, or EOT, or whatever. Obviusly i had to change this too:
Code: Pascal  [Select][+][-]
  1. function TLazSerial.ReadData: string;
  2. begin
  3.   result:='';
  4.   if FSynSer.Handle=INVALID_HANDLE_VALUE then
  5.     ComException('can not read from a closed port.');
  6.   if FRcvLineTerminated = EmptyStr then
  7.   result:=FSynSer.RecvPacket(0)
  8.   else
  9.   result:=FSynSer.RecvTerminated(0, FRcvLineTerminated);
  10. end;
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: esvignolo on October 17, 2017, 02:13:33 am
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
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: bobihot on January 28, 2018, 07:21:50 pm
I need to can manually set Baud rate. With USB-TTL converter I use successfully 2Mbs speed. New frequency are whole nums, not power of 9600. Like 11,920MHz system.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on January 28, 2018, 09:25:13 pm
I need to can manually set Baud rate. With USB-TTL converter I use successfully 2Mbs speed. New frequency are whole nums, not power of 9600. Like 11,920MHz system.
That's a power of 745, anyway it is non-standard for rs232 comm. Synapse comes with sources. If you need exotics : build exotics. IOW adapt the sources to your needs. Some people call that programming.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: JJJ on May 29, 2018, 12:43:08 pm
Hi,

I'm trying to read data from serial port without any success.
I then made simple script to send a test string to serial port.

It will send "123A" where "A" is delimitter
I use following code for parsing:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.LazSerial1RxData(Sender: TObject);
  2. var Str : string;
  3. begin
  4.   Str :=  LazSerial1.ReadData;
  5.   CurPos := Pos('A' ,Str);
  6.   if CurPos = 0 then begin
  7.     FTempStr := FTempStr + Str;
  8.   end
  9.   else begin
  10.     FTempStr := FTempStr + Copy( Str, 1, CurPos-1);
  11.  
  12.     memo1.Lines.Add(FtempStr);
  13.     memo1.Lines.Add('X');
  14.  
  15.  
  16.     FTempStr := Copy(Str,CurPos +1, Length(Str) - CurPos);
  17.   end;        
  18.  

It should write "123" to memo and add "X" between every string.
Howerever, the result is:
Code: Pascal  [Select][+][-]
  1. 123A123A123A123
  2. X
  3. 123A123A123
  4. X
  5. 123A123A123A123
  6. X
  7. 123A123A123A123
  8. X
  9. 123A123A123A123
  10. X
  11. 123A123A123A123
  12. X
  13. 123A123A123A123
  14. X
  15. 123A123A123A123
  16. X
  17. 123A123A123
  18. X
  19. 123A123A123A123
  20. X
  21. 123A123A123A123
  22. X
  23.  

What I'm doing wrong?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tr_escape on May 29, 2018, 02:22:23 pm
I think your device sending all the time when you trying to parse what before received.

What kind device have you got?

The event can be overload and your data might be not ready or has missed parts.

In this case I would try to parse for only successful datas.

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: JJJ on May 29, 2018, 02:41:21 pm
Thanks, you're right.
Actually I'm trying to read a sensor data from AVR. That example is just a test script and it works when I add a delay between packets.

It seems that I'm not able to use Lazserial because of the slowness.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tr_escape on May 29, 2018, 02:55:34 pm
It seems that I'm not able to use Lazserial because of the slowness.

Because Rs232 has limits , actually 115200 ~ about 230000bps good enough for a lot of operations.

Maybe you can use another bus system like as ethernet.

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on May 29, 2018, 03:49:02 pm
Because Rs232 has limits , actually 115200 ~ about 230000bps good enough for a lot of operations.
That's not correct. The standard is a protocol, not a speed limitation< grumpy, very grumpy  >:D >:D >
before you answer make sure your facts are correct. https://en.wikipedia.org/wiki/RS-232
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: JJJ on May 29, 2018, 03:53:54 pm
I am using 115200 bps. I have an old software made with CVI and it works. I tested this with Delphi 7 and it worked as well. For some reason I have to add more than 10ms delay between the packets if I am reading the data in Lazarus. Weird.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on May 29, 2018, 06:30:28 pm
hello,
JJJ, you can try to use the recvTerminated  function :
Quote
function RecvTerminated(Timeout: Integer; const Terminator: AnsiString): AnsiString; virtual;
This method waits until a terminated data string is received. This string is terminated by the Terminator string. The resulting string is returned without this termination string! If no data is received within the Timeout (in milliseconds) period, LastError is set to ErrTimeout.

with something like that :
Code: Pascal  [Select][+][-]
  1. procedure TFMain.SerialRxData2(Sender: TObject);      
  2.  var Str : string;
  3. begin
  4.   // you must adjust the timeout value for your case
  5.   Str :=  Serial.RecvTerminated(100,'A'));
  6.   if Serial.SynSer.LastError = 0 then
  7.   begin
  8.     Memo.Lines.BeginUpdate;
  9.     Memo.Lines.Add(Str);
  10.      Memo.Lines.EndUpdate;
  11.     Memo.SelStart := Length(Memo.Lines.Text)-1;
  12.     Memo.SelLength:=0;
  13.   end
  14.   Else
  15.     begin
  16.        Memo.Lines.Add('Error : ' + Serial.SynSer.LastErrorDesc);
  17.     end;
  18.   end;

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: JJJ on May 29, 2018, 08:23:30 pm
Thanks J.P!! It works.

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tr_escape on May 30, 2018, 07:31:23 am
Because Rs232 has limits , actually 115200 ~ about 230000bps good enough for a lot of operations.
That's not correct. The standard is a protocol, not a speed limitation< grumpy, very grumpy  >:D >:D >
before you answer make sure your facts are correct. https://en.wikipedia.org/wiki/RS-232

Yes, thank you for your correction... I mean today's devices has got some limits thats what I said :)

If your device designed to capture the square waves you may speed up to nearly light speed.

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on May 30, 2018, 11:27:50 am
Hi, have been away for a while...


Just installed Lazarus again and installed the TLazSerial-master.

With a quick test by compiling/running/debugging the orginal aplication 'sertest' ( that G{S Simulator 2.0 ).
No errors while compiling!

But my own aplication, gives compile error: 





















Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on May 30, 2018, 11:41:48 am
Her you can see the directeries:

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tr_escape on May 30, 2018, 12:14:52 pm
Maybe some packages missing? Did you try to add laz_synapse in the project inspector?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on May 30, 2018, 02:32:44 pm
hello,
Hi, have been away for a while...
Just installed Lazarus again and installed the TLazSerial-master.

With a quick test by compiling/running/debugging the orginal aplication 'sertest' ( that G{S Simulator 2.0 ).
No errors while compiling!
But my own aplication, gives compile error:

if your application was written with the old version of  the component TLazserial 0.1 , something  has changed in the new version, it is lazsynaser (customized version  of  synaser  for tlazserial include in the package 0.2) in  place of synaser unit which is used.
Code: Pascal  [Select][+][-]
  1. unit Main;
  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,lazsynaser;    
Friendly  J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: jb007 on May 31, 2018, 10:00:41 am
Thanks, that rings a bell, that whole package story!
Gonna contineu tonight.

Off topic, things have been gone pretty nice, screenshot of my latest ( months ago ) running ".exe file":





Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: dimonsky on July 01, 2018, 11:22:18 am
When I install LazSerial on my raspberry, I get a warning:
"The package LazSerialPort 2.0 was marked for installation. Currently Lazarus only supports static linked packages. The real installation needs rebuilding and restarting of Lazarus.
Do you want to rebuild Lazarus now?"
If I press Yes, it tries to compile IDE by itself, but failes in Lazarus.pp, line 150:
"debugln('Lazarus END - cleaning up...');"

WHat I am doing wrong?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on July 01, 2018, 01:31:55 pm
I do not use lazserial (because it is not visual component and synaser us easier to use from code) but I am installing it now from the online repository. Will Report back.
[back:]
yes it fails big time. Suggest to use the synapse code from 4.1 and write it in code. (That's how I do it all the time. Not that LazSerial is a folly, but my opinion is such things should not be a component and since it is not supported by the author of synapse rather useless except for screen drawers)
You can file a bug report.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: bobihot on August 24, 2018, 01:53:33 pm
Because now USB-RS TTL/485 converters can to work at high speed, I need possibility to enter directly communication frequency. Because of this I cant find this frequencies in component, but I successfully make transfer of 1-2Mbps. It's good to can choose old standard freq, but and to can enter each desired in style: csDropDown. With Synaser can.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: seliman on September 16, 2018, 03:31:38 pm
Hi , My name is Ramiro , sorry my English   I m from Argentina , please can you help me ? .

I try to use the serial component , I send datos from arduino , and I needing to know when this datos its not present , For example

procedure TForm1.SerialRxData(Sender: TObject);

  begin
             
                 str := serial.ReadData;
                 str := AnsiReplaceStr(str, #10, '' ); //saca nueva linea
                 str := AnsiReplaceStr(str, #13, '' );   //saca retorno de carro
                 str := AnsiReplaceStr(str, #32, '' );  // saca linea espacio
             
 
   end;

I needing to know when not have trafic in port , then str = ' '

Thanks in advance
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on September 17, 2018, 06:38:24 am
hello,
with a timer ?  see here (http://forum.lazarus.freepascal.org/index.php/topic,42566.msg297308.html#msg297308)
Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: att2 on October 09, 2018, 03:05:04 pm
Hello,
We have a large program that compiles perfectly with Lazarus 1.8.4 "stable" and FPC3.2.0 "fixes". Perfectly, that is, IF you select as Target OS=Linux and Target CPU=Intel (x64). If you select Target CPU=ARM, you get errors in the serial component :

Quote
Hint: (11030) Start of reading config file /home/arm1/fpc2/fpc/bin/x86_64-linux/fpc.cfg
Hint: (11031) End of reading config file /home/arm1/fpc2/fpc/bin/x86_64-linux/fpc.cfg
Free Pascal Compiler version 3.2.0-beta-r20:39835 [2018/10/08] for arm
Copyright (c) 1993-2018 by Florian Klaempfl and others
(1002) Target OS: Linux for ARMHF
(3104) Compiling LazSerialPort.pas
(3104) Compiling lazserial.pas
(3104) Compiling lazsynaser.pas
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(255,15) Error: (5000) Identifier not found "B1000000"
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(255,23) Error: (3203) Illegal expression
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(256,15) Error: (5000) Identifier not found "B1152000"
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(256,23) Error: (3203) Illegal expression
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(257,15) Error: (5000) Identifier not found "B1500000"
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(257,23) Error: (3203) Illegal expression
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(258,15) Error: (5000) Identifier not found "B2000000"
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(258,23) Error: (3203) Illegal expression
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(259,15) Error: (5000) Identifier not found "B2500000"
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(259,23) Error: (3203) Illegal expression
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(260,15) Error: (5000) Identifier not found "B3000000"
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(260,23) Error: (3203) Illegal expression
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(261,15) Error: (5000) Identifier not found "B3500000"
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(261,23) Error: (3203) Illegal expression
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(262,15) Error: (5000) Identifier not found "B4000000"
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(262,23) Error: (3203) Illegal expression
/home/arm1/fpc2/config_lazarus/onlinepackagemanager/packages/LazSerial/lazsynaser.pas(765,1) Fatal: (10026) There were 16 errors compiling module, stopping
Fatal: (1018) Compilation aborted
Error: /home/arm1/fpc2/fpc/bin/x86_64-linux/ppcrossarm returned an error exitcode


Can you help me to fix these errors ? It must be the component's fault.......     %)   %)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: af0815 on October 09, 2018, 03:17:59 pm
This speeds are not defined in linux for arm by fpc. You can fix this in synaser or in fpc. I dont know WHO is responsible for this. FPC Team or Maintainer of synapse.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: kasko on October 09, 2018, 05:00:08 pm
First of all, thank you for the LazSerial component!

I'm trying to make a program on the Rasperry Pi 3 and I'm using LazSerial version 0.2, but I get some problems. I woul be very grateful if anyone could give me som hints to get on... here is my problem:

I'm trying to use LazSerial, version 0.2, on a Raspberry Pi 3 with Raspian (Debian adaption for RPi). Just a simple test program with one button. When clicking the button, I want the Serial setup dialog to show up. Just using "LazSerial.ShowSetupDialog". The call results in an error "File not open". If clicking "OK" to ignore, and clicking once more on the button, the Setup Dialog appears. I have compiled the source code on the Raspberry Pi 3. The Helpscreen shows this configuration:

Raspberry Pi - #1
Lazarus version # 1.6.2 + dfsg-2
Date: 2018-10-05
FPC version 3.0.0
SVN revision Debian package 1.6.2 dfsg-2 arm-linux.gtk 2

I have another Raspberry Pi 3 with the following configuration:

Raspberry Pi - #2
Lazarus version # 1.6 + dfsg-4
Date: 2016-08-08
FPC version 3.0.0
SVN revision Debian package 1.6.4 dfsg-2 arm-linux.gtk 2

The LazSerial is version 0.1 and the message "File not open" does not show up, and everything workes nice!

When running in debugging mode, a debugger exception notification occur with the message "Project "Test" raised exception class 'RunError(103)'. In file "lazlogger.pas' at line 548. Pressing "Continue" result in the same message again. A new click on "Continue" results in the "normal" error message "File not open".

Does anyone have this problem too?

By the way, this does not occur in Windows....

Best regards
Karl
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on October 09, 2018, 05:22:25 pm
hello,
We have a large program that compiles perfectly with Lazarus 1.8.4 "stable" and FPC3.2.0 "fixes". Perfectly, that is, IF you select as Target OS=Linux and Target CPU=Intel (x64). If you select Target CPU=ARM, you get errors in the serial component :
you can try to put the code of engkin (see here (https://forum.lazarus.freepascal.org/index.php/topic,20481.msg141726.html?PHPSESSID=2mro6nahaegf3ikvg726fumvc5#msg141726))  :
Code: Pascal  [Select][+][-]
  1. {$ifdef cpuarm}
  2.    B1000000= $0001008;
  3.    B1152000= $0001009;
  4.    B1500000= $000100A;
  5.    B2000000= $000100B;
  6.    B2500000= $000100C;
  7.    B3000000= $000100D;
  8.    B3500000= $000100E;
  9.    B4000000= $000100F;
  10. {$endif cpuarm}
just before this :
Code: Pascal  [Select][+][-]
  1.   {$IFDEF UNIX}
  2.     ,(500000, B500000),
  3.     (576000, B576000),
  4.     (921600, B921600),
  5.     (1000000, B1000000),
  6.     (1152000, B1152000),
  7.     (1500000, B1500000),
  8.     (2000000, B2000000),
  9.     (2500000, B2500000),
  10.     (3000000, B3000000),
  11.     (3500000, B3500000),
  12.     (4000000, B4000000)
  13.   {$ENDIF}
at the beginning of the file lazsynaser.pas
Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on October 09, 2018, 05:25:41 pm
Which is about the answer I gave very much earlier?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on October 09, 2018, 05:39:27 pm
kasko what is your code , have you tried to run your program as superuser ?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: kasko on October 09, 2018, 06:39:48 pm
I will try with superuser...
the code is very simple. Just a form with a button, and when clicking the button the "LazSerial.ShowSetupDialog" is executed, that's all

Karl
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: kasko on October 09, 2018, 07:03:25 pm
Hi again!
Just tried with sudo, same error.
But.....
My original program is rather big, so I just compiled a very simple from as I described in my previous mail. This is working ok!!! So, there must be something with my big program. I think it has to do with a configuration file or something around this. I have to have a closer look. I'm not familiar with Linux, but I get help for this. I want to use the same source code to mak an executable for both Windows and Raspberry Pi...

Thanks for using your time on my problem!

Karl
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: att2 on October 18, 2018, 08:55:08 pm
Hello "Jurassic Pork",
Thanks for your kind advice, but it did not work as described.
My boss, an extremely pro Delphi coder, finally fixed it with changing the "termios.inc" file, like so:

At Line numbers 1398 ff. :

Quote
{c_cflag bits}
   CBAUD   = $000100F;
   B0      = $0000000;
   B50     = $0000001;
   B75     = $0000002;
   B110    = $0000003;
   B134    = $0000004;
   B150    = $0000005;
   B200    = $0000006;
   B300    = $0000007;
   B600    = $0000008;
   B1200   = $0000009;
   B1800   = $000000A;
   B2400   = $000000B;
   B4800   = $000000C;
   B9600   = $000000D;
   B19200  = $000000E;
   B38400  = $000000F;
   EXTA    = B19200;
   EXTB    = B38400;
   CSIZE   = $0000030;
     CS5   = $0000000;
     CS6   = $0000010;
     CS7   = $0000020;
     CS8   = $0000030;
   CSTOPB  = $0000040;
   CREAD   = $0000080;
   PARENB  = $0000100;
   PARODD  = $0000200;
   HUPCL   = $0000400;
   CLOCAL  = $0000800;
   CBAUDEX = $0001000;
   B57600  = $0001001;
   B115200 = $0001002;
   B230400 = $0001003;
   B460800 = $0001004;
   B500000 = $0001005;
   B576000 = $0001006;
   B921600 = $0001007;
   B1000000 = $0001008;   // this line was added!
   B1152000 = $0001009;  // this line was added!
   B1500000 = $000100A;  // this line was added!
   B2000000 = $000100B;  // this line was added!
   B2500000 = $000100C;  // this line was added!
   B3000000 = $000100D;  // this line was added!
   B3500000 = $000100E;  // this line was added!
   B4000000 = $000100F;  // this line was added!

   CIBAUD  = $100F0000;
   CMSPAR  = $40000000;
   CRTSCTS = $80000000; 



The lazsynaser looks like this at line 220 ff.  :

Quote
const
{$IFDEF UNIX}
  {$IFDEF DARWIN}
  MaxRates = 18;  //MAC
  {$ELSE}
   MaxRates = 30; //UNIX
  {$ENDIF}
{$ELSE}
  MaxRates = 19;  //WIN
{$ENDIF}
  Rates: array[0..MaxRates, 0..1] of cardinal =
  (
    (0, B0),
    (50, B50),
    (75, B75),
    (110, B110),
    (134, B134),
    (150, B150),
    (200, B200),
    (300, B300),
    (600, B600),
    (1200, B1200),
    (1800, B1800),
    (2400, B2400),
    (4800, B4800),
    (9600, B9600),
    (19200, B19200),
    (38400, B38400),
    (57600, B57600),
    (115200, B115200),
    (230400, B230400)
{$IFNDEF DARWIN}
    ,(460800, B460800)
  {$IFDEF UNIX}
    ,(500000, B500000),
    (576000, B576000),
    (921600, B921600),
    (1000000, $0001008),
    (1152000, $0001009),
    (1500000, $000100A),
    (2000000, $000100B),
    (2500000, $000100C),
    (3000000, $000100D),
    (3500000, $000100E),
    (4000000, $000100F)
  {$ENDIF}
{$ENDIF}
    );
{$ENDIF}

{$IFDEF DARWIN}
const // From fcntl.h
  O_SYNC = $0080;  { synchronous writes }
{$ENDIF}         

BOLD are the additions to the LazSynaser file.

THEN, and only then, the large project compiled. I'm happy to see it working under Linux/Intel-32bit, Linux/Intel-64bit, Linux/ARM-32bit, Linux/ARM-64bit (aarch), and even Windows if we wanted to.   ;D

Title: TLazSerial: onStatus dealing with rising and falling CTS
Post by: keyman on December 01, 2018, 11:01:51 am
Hey all,
first of all: thank you for LazSerial! it made my live easier so ofter and i really like how easy and good it works. really loving it!
the last days i fall over a problem i was not able to find a solution for myself.
i have a device which sends data and in parallel it notifies via CTS that a chip is in front of a reader.
what i wanted to achive is, to have a marker in the software when a chip is present. so far so good - i just used onStatus and it is signaling a rise of CTS. (read ready)
here comes my problem: as far is i got it onStatus is not called when CTS is falling. but i need that signal too.... how could i achive that?
as a fix a am reading the CTS-pin in a timer event now - but its not that clean i wanted it to be. is there any chance to get this to work? all i found was "on a change of the communication status" the function called.
can you help me with that?  ::)

thanks!
jan

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: mas steindorff on December 03, 2018, 07:53:07 pm
hi Keyman,
i do not have a fix for you but it would be useful to know what your target baud rate is.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: darthvader on December 08, 2018, 12:44:12 pm
Hi  :D
At First , thanks for this component !!
I just have a question about TX.
How can i know when the TX buffer is empty ?
I have to check this before i send new data or i get something like communication collision and the serial port freeze for some second , it's a little annoying because the sent data's are piloting Servo's and when it unfreeze some movement step for the servos are gone and the movement can be very rubbish  ;D
For info i use Latest Lazarus on win10
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: keyman on December 09, 2018, 07:11:28 pm
i do not have a fix for you but it would be useful to know what your target baud rate is.
Hey,
its running with "9600,8,n,1" (baud,data,parity,stop)
thanks for wrapping your head around my problem; it's still unsolved.
jan
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi on December 15, 2018, 05:23:42 pm
Hi

I'm going crazy trying to speak to an Alicat mass flow controller.  I write to it and the whole program (which is a big one, with three LazSerial components) locks up.  It does not return from the write statement.  The machine responds, for example when I set a flow rate, so it IS getting the message.   Then it locks.   I send it a string which is the instruction followed by a CR.  There's not a lot more to say!  The baud rates etc are matched but I have no information on data bits etc.  Current Baud is 19200, on LazSerial and device, over a USB.  I tried a serial cable and it behaves the same.  I tried the three flow control options.

Here is the chunk of code:

procedure TForm1.TestAlicatClick(Sender: TObject);
var tStr : string ;
 begin
  tStr :=  Edit1.text ; //Edit1.text contains 'A2222'  (Alicat expects integer 0..64000) A is the device ID
  Lazali.SynSer.Flush ;
  Lazali.WriteData(tStr + chr(13) ); //Add CR - and I've tried 2 of them
  exit ;  //Never gets to here
  try
   sleep (10) ;
   if Lazali.DataAvailable then
    tStr := Lazali.ReadData else exit ;
  except
   on  e: Exception do
    begin
     ShowMessage ('Sorry - an exception was generated and the program must close!') ;
     Application.Terminate;
    end ;
  end; 

Is there a parameter to timeout during a write?  I'm really desperate to get this to work as I am in Michigan and have to go back to Australia in two days!

Incidentally I know that the Alicat RS232 protocol is strange - it uses 0-5 volts instead of -5 to +5, but I'm using their serial interface box which presumably provides a compatible face to the outside world.

Thanks

Frustrated Hil
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on December 15, 2018, 07:01:03 pm
Don't you mean a linefeed instead of a carriage return? i.e. #10?. Also you can code chr(13) better as #13... e.g. astring+#13
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi on December 15, 2018, 08:10:54 pm
Hi

Nope - the documentation states to use a carriage return.  I tried a line feed just now and the device doesn't respond.

Ha ha!  I like to smatter chr() and # randomly through my code!  I suppose that I'm hoping that the compiler is smart enough to turn them into the same thing!

Thanks!

Hil
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on December 15, 2018, 11:26:56 pm
hello BeaglePI,
What is your O.S ?  because of this :
Quote
procedure Flush; virtual;
Waits until all data to is sent and buffers are emptied. Warning: On Windows systems is this method returns when all buffers are flushed to the serial port controller, before the last byte is sent!
Have you tried to remove the flush operation ?

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi on December 16, 2018, 12:34:58 am
Hi J.P.

Yup, I only put flush in because I saw that somebody else had used it, but I took it out. 

I tried creating a tiny app just to find a basic case.  It worked when I have only one Lazserial component in the job.  So it looks like three are too many!

Interestingly (?) it only locks when it speaks to the device.  If I format the command wrongly then it doesn't lock up!  So it should be a2000#13 for example, but if I leave off the #13 then it doesn't set the flow or lock up. 

The machine returns 40 characters or something after a successful command so maybe it is the return that is creating problems.

Thanks

Hil
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi on December 16, 2018, 12:36:59 am
Oh - OS is Windows 7 Pro.
Title: Unusual baud rate (28800) required
Post by: PaulRowntree on December 17, 2018, 08:25:02 am
I have had great success with tLazSerial and connecting to several lab instruments, working with several Windows versions from XP on to Win10.  Thank for this code!One of my systems is a mass spectrometer from Stanford Research Systems.  It comes with a stand alone program that works well, and I have had success with LabView. I need to move to Lazarus/FP, however, the mass spec has a fixed 28,800 baud rate, which is not one of the TLazSerial options.
Am I out of luck on this?Thanks for any help you can provide!Cheers!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Phemtik on December 17, 2018, 09:47:11 am
@PaulRowntree
Maybe you need to extend the TLazSerial  code with your specific baud rate.
If TLazSerial don't support it at all, you could use VISA. You have already used LabVIEW, so you have the Driver already installed.

If you have already written your program with TLazSerial, i think  it would be faster to modify TLazSerial than rewrite to use VISA instead.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: avra on December 17, 2018, 10:02:23 am
It worked when I have only one Lazserial component in the job.  So it looks like three are too many!
Do those three components connect to the same machine through the same PC port? Can you go back to a single LazSerial component? How do you connect at all if 28800 is not supported?

There are alternatives for serial communication which you can also try:
http://wiki.freepascal.org/Hardware_Access#Serial_Communication
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PaulRowntree on December 17, 2018, 02:32:48 pm
@PaulRowntree
Maybe you need to extend the TLazSerial  code with your specific baud rate.
If TLazSerial don't support it at all, you could use VISA. You have already used LabVIEW, so you have the Driver already installed.

If you have already written your program with TLazSerial, i think  it would be faster to modify TLazSerial than rewrite to use VISA instead.
My LabVIEw code was compiled, and we don't have access to the compiler any more.  It sent the mass spec data back to a Delphi program via DDE, and I really wanted to get away from that system to allow future interfaces. 
It doesn't look like I can extend TLasSerial in an OOP way, it would take recoding a few lines in the unit, and perhaps Synaser as well.  I would like to avoid private forks.  The really odd part is that the Win10 device manager doesn't even list 28800 as an option ...Thanks!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Phemtik on December 17, 2018, 03:38:45 pm
@PaulRowntree
Maybe you need to extend the TLazSerial  code with your specific baud rate.
If TLazSerial don't support it at all, you could use VISA. You have already used LabVIEW, so you have the Driver already installed.

If you have already written your program with TLazSerial, i think  it would be faster to modify TLazSerial than rewrite to use VISA instead.
My LabVIEw code was compiled, and we don't have access to the compiler any more.  It sent the mass spec data back to a Delphi program via DDE, and I really wanted to get away from that system to allow future interfaces. 
It doesn't look like I can extend TLasSerial in an OOP way, it would take recoding a few lines in the unit, and perhaps Synaser as well.  I would like to avoid private forks.  The really odd part is that the Win10 device manager doesn't even list 28800 as an option ...Thanks!

Well, LabVIEW and VISA are two different things. If you have LabVIEW once installed and used VISA with it, you could use VISA64.dll / VISA.dll direct over Lazarus.
For newer Versions you need to update over National Instruments, because the VISA version from NI is most likely the reference implementation on Windows, but you don't need LabVIEW to use it.
It is an industry standard from the IVI Foundation and NI is only a vendor for it.

I use it for my daily work and wrote a few Programs for measuring and control with it.
Even on Linux over NI-VISA (openSUSE).
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on December 17, 2018, 05:54:37 pm
hello,
i have modified 3 files of the TLazSerial package to add the 28800 baud rate choice on Windows.
1 - Replace the 3 files by the files in the attachment file.
2 - Recompile the package
I don't know if it is OK but you can try.

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PaulRowntree on December 17, 2018, 06:11:44 pm
hello,
i have modified 3 files of the TLazSerial package to add the 28800 baud rate choice on Windows.
1 - Replace the 3 files by the files in the attachment file.
2 - Recompile the package
I don't know if it is OK but you can try.

Friendly, J.P
Thanks JP, I really appreciate this.  Will try tonight!pr
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PaulRowntree on December 17, 2018, 06:54:21 pm
@PaulRowntree
Maybe you need to extend the TLazSerial  code with your specific baud rate.
If TLazSerial don't support it at all, you could use VISA. You have already used LabVIEW, so you have the Driver already installed.

If you have already written your program with TLazSerial, i think  it would be faster to modify TLazSerial than rewrite to use VISA instead.
My LabVIEw code was compiled, and we don't have access to the compiler any more.  It sent the mass spec data back to a Delphi program via DDE, and I really wanted to get away from that system to allow future interfaces. 
It doesn't look like I can extend TLasSerial in an OOP way, it would take recoding a few lines in the unit, and perhaps Synaser as well.  I would like to avoid private forks.  The really odd part is that the Win10 device manager doesn't even list 28800 as an option ...Thanks!

Well, LabVIEW and VISA are two different things. If you have LabVIEW once installed and used VISA with it, you could use VISA64.dll / VISA.dll direct over Lazarus.
For newer Versions you need to update over National Instruments, because the VISA version from NI is most likely the reference implementation on Windows, but you don't need LabVIEW to use it.
It is an industry standard from the IVI Foundation and NI is only a vendor for it.

I use it for my daily work and wrote a few Programs for measuring and control with it.
Even on Linux over NI-VISA (openSUSE).
I didn't appreciate that ... thanks for the info!  JP modified his LazSerial codes, so I will try that route first.Cheers!pr
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PaulRowntree on December 21, 2018, 07:27:36 am
hello,
i have modified 3 files of the TLazSerial package to add the 28800 baud rate choice on Windows.
1 - Replace the 3 files by the files in the attachment file.
2 - Recompile the package
I don't know if it is OK but you can try.

Friendly, J.P
Works like a charm JP, thank you!pr
Title: Still problems with multiple LazSerial components
Post by: BeaglePi on February 18, 2019, 04:23:52 am
Hi - I'm back ...

I tried three  LazSerial components in my program and it would not run. 

So then I went to two: one communicates with the laser and the other with the Arduino.   I then speak to the other devices by serial from the Arduino.

All good ... but occasionally the program stops for seconds to minutes.  I tried putting profilers all over the place and the result is that NONE of the calls from my program are freezing.  The problem is happening between my timer clicks and the resulting actions.  BUT the windows task manager shows my program as the culprit for bogging down the processor.

Finally in desperation I deleted a serial component (and all the references) and simply fed a string in with the required data in the timer click event.  And the program runs smooth as butter.  And that includes the dialog box problem that I had as well.

So my experience is definitely that more than one LazSerial component can cause problems.  Or is there something in Windows 7 that might cause a conflict?

Should I try a Synaser for one serial?  Or can anybody suggest another option?  It's funny because I saw a previous post regarding two components and the conclusion was that they should be fine.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: six1 on February 18, 2019, 07:01:28 am
maybe the problem occours only by compiling in debug mode?
Did you try to compile in release mode?

best, michael
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi on February 18, 2019, 07:44:41 am
I did try that some time ago - but it could be worth another try!

I'd wondered whether I could set active to false after using the component and then set it to true again before the next read, but it doesn't work.  The component then fails at the Application.processMessages line.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi on February 18, 2019, 11:09:16 am
But looking at the code I see that it processes messages while waiting for the thread to terminate.  Maybe I should just have a small delay after closing it.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi on February 18, 2019, 09:00:17 pm
Given that the problem often occurs between my calls to DataAvailable , i.e. when I am not knowingly using the component, it must be that the software running to trigger the RX event is competing for a resource.  Can I tell it only to run when I request DataAvailable and not to trigger the RX event?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: JoeJ on February 22, 2019, 06:05:42 pm
Hi,

the package LazSerial Version 0.2 can't be compiled under Raspian Stretch. Reason: The file "lazsynaser.pas" in lines 252..262 references undefined constants. They should be defined in file 'termios.inc'. In other operating systems and/or Lazarus versions they are, but not in Lazarus 2.0 under Raspbian Stretch, Nov 2018 edition.

As a quick and very dirty intermediate fix I replaced the constants in these lines with literal expressions. This worked, but of course that's no tidy solution.


Regards --  Joe

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Thaddy on February 22, 2019, 06:25:35 pm
I did the same and reported it. But anyway: components are not the way to go here, simply use synaser in a non-visual manner. That would skip any incompatibilities caused by the component author and is much easier in the end. No "sleur en pleur" (dutch) or "drag and dump" "programming" involved. Keep components to the visual parts of your application is my personal opinion. Always has been.

It's an opinion, so feel free do digress...
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi on February 23, 2019, 04:09:41 am
Problem reconnecting to Arduino - I'm desperate!

OK, so I reduced myself to one Lazserial component by connecting an Arduino Mega and hooking up to the extra serial channels to that.

The problem is that when I fire up the Lazarus program it has difficulty connecting to the Arduino.  The receive light on the Arduino flashes to show that I am interrogating it but the transmit light stays off.  And LazSerial states that no data are available.  Even when I program the Arduino to echo every char.

On the other hand I do NOT have that problem when I interrogate it from the Arduino monitor - it responds immediately and correctly.

So it looks as though LazSerial may not be turning on Rx?

I could really use some help here!  I'm ready to burn it.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi on February 23, 2019, 09:32:30 am
I'll try to post some code and see if that inspires any interest:

Sorry that it's not properly formatted.

Here's the Arduino:

void loop()
//Code borrowed and modified from Robin 2 on Arduino forum.
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '@';
    char endMarker = '!';
    char rc;
 
    while (Serial.available() > 0 && newData == false)
    {
        rc = Serial.read();

       //Serial.write (rc) ;

        if (recvInProgress == true)
        {
         if (rc != endMarker)
          {
           receivedChars[ndx] = rc;
           ndx++;
           if (ndx >= MAXSTRLEN)
            {
             ndx = MAXSTRLEN - 1;
            }
          }
            else
            {
             receivedChars[ndx] = '\0'; // terminate the string
             recvInProgress = false;
             ndx = 0;
             newData = false;
          //   Serial.println (receivedChars) ;
             translateSerialRequest () ;
            // memset (receivedChars, '\0', MAXSTRLEN) ;
            }
        }

        else if (rc == startMarker)
         {
          recvInProgress = true;
         }
    }
}

It eventually falls through into a command parser.  When the echo is turned on, nothing comes back after connection .

and a tiny part of the Pascal code:

 procedure LazWrites(StringOut: string);
   begin
    Form1.Timer1.Enabled:= false ;//Drive query and screen update
    Form1.LazSerialArduino.WriteData (stringOut) ;
    form1.LblQueryOut.Caption := stringOut ;
    RegisterStateConstant (CS_ARDUINOQUERYSENDING, false ) ;
    sleep(30) ;

    LazReads ;

    ClearAnswers ; //Checks for unanswered questions
   end;

  //Read from LazSerial and process the answer, then delete it from the stack
  //Only called when ArduinoQueryActive but not ArduinoQuerySending
  procedure LazReads;
   var
    readStr,
    workStr   : string ;
    Ido,
    Counter,
    endPos   : integer ;
   begin
     try

    form1.timer1.Enabled:= true ;

    if form1.LazSerialArduino.DataAvailable then
      readStr := form1.LazSerialArduino.ReadData else exit ;
      holdStr := holdStr + readStr ;   


LazWrites accepts a string that was popped from the query stack.  It might look like:
@V233!       -     rotate the valve to position 3.  Check in as query 23.  @ and! are start and end characters.

So this is running on Serial3 on the Mega at 9600 Baud.

@E34! queries the laser on Serial2 which returns a string of info 112 characters long, etc.

The point is, that if I send @V235! from the Arduino monitor, there is a buzz and the valve switches to position 5 and returns @V|23|Valve to pos 5|0!

When I start the Lazarus program and send the same command, nothing happens.  The Rx light on the Arduino flashes but there is no flash of Tx or a return.  It never sees data available and exits after
 if form1.LazSerialArduino.DataAvailable then ...

If I put a break point on that line and the two following and step through them repeatedly, then eventually the serial starts up and everything flows.

Any help very gratefully received!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: FedCo on June 15, 2019, 02:07:46 pm
Hello.

I ask for help.
In my program, there are delays of 30 seconds, sometimes often, sometimes rarely. Delays occur only when the program is connected to the COM port. after the hang, the program continues to work normally.
I use the LazSerial library.
The duration of delays is always the same.
Why do these delays occur? How to fix that they were not?
Code: Pascal  [Select][+][-]
  1. unit TenU;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, LazSerial, Forms,StdCtrls, ExtCtrls, LazSynaSer,dos;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   { TTenesi_Creator }
  15.  
  16.   TTenesi_Creator = class(TForm)
  17.     ConBut: TButton;
  18.     deviceList: TComboBox;
  19.     Label1: TLabel;
  20.     Label10: TLabel;
  21.     Label13: TLabel;
  22.     Label14: TLabel;
  23.     Label15: TLabel;
  24.     Label16: TLabel;
  25.     Label2: TLabel;
  26.     Label3: TLabel;
  27.     Label4: TLabel;
  28.     Label5: TLabel;
  29.     Label6: TLabel;
  30.     Label7: TLabel;
  31.     Label9: TLabel;
  32.     Tenesi: TLazSerial;
  33.     Timer1: TTimer;
  34.     Timer2: TTimer;
  35.     procedure ConButClick(Sender: TObject);
  36.     procedure deviceListDropDown(Sender: TObject);
  37.     procedure FormCreate(Sender: TObject);
  38.     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  39.     procedure Timer1Timer(Sender: TObject);
  40.     procedure Timer2Timer(Sender: TObject);
  41.  
  42.   private
  43.  
  44.   public
  45.  
  46.   end;
  47.  
  48. var
  49.   Tenesi_Creator: TTenesi_Creator;
  50.   ModeFly:byte;
  51.   Bat,Lat,Lon,Alt,AltG,Cog,GPSVSI,Sat,Speed,VSI,Curs:double;
  52.   Pitch,Roll:integer;
  53.  
  54.  
  55. implementation
  56.  
  57. {$R *.lfm}
  58.  
  59. { TForm1 }
  60.  
  61. procedure TTenesi_Creator.deviceListDropDown(Sender: TObject);
  62. begin
  63.  deviceList.Items.CommaText:=LazSynaSer.GetSerialPortNames;
  64. end;
  65.  
  66. procedure TTenesi_Creator.FormCreate(Sender: TObject);
  67. begin
  68. end;
  69.  
  70. procedure TTenesi_Creator.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  71. begin
  72.  If Tenesi.Active then Tenesi.Close;
  73. end;
  74.  
  75. procedure TTenesi_Creator.Timer1Timer(Sender: TObject);
  76. Var comanda,s:string;
  77. begin
  78.  if Bat<21 then Bat:=25.2
  79.            else bat:=bat-0.1;
  80.  if Curs>360 then Curs:=Curs-360
  81.              else Curs:=Curs+1;
  82.  Lat:=56.1234567;
  83.  Lon:=35.7654321;
  84.  if alt>1000 then alt:=-100
  85.              else alt:=alt+0.3;
  86.  ModeFly:=2;
  87.  VSI:=435.67;
  88.  
  89.  str(Pitch:4,s);          Label2.Caption:= 'Pit '+s;
  90.  str(Roll:4,s);           Label9.Caption:= 'Rol '+s;
  91.  str(Bat:2:2,s);          Label10.Caption:='Bat '+s;
  92.  str(Lat:3:7,s);          Label6.Caption:= 'Lat '+s;
  93.  str(Lon:3:7,s);          Label13.Caption:='Lon '+s;
  94.  str(AltG:5:2,s);         Label5.Caption:= 'AlG '+s;
  95.  str(Alt:5:2,s);          Label14.Caption:='Alt '+s;
  96.  str(Curs:4:2,s);         Label15.Caption:='Crs '+s;
  97.  str(Speed:4:2,s);        Label3.Caption:= 'Spe '+s;
  98.  Label16.Caption:='Модель ПК A2';
  99.  Label4.Caption:='Fly Mode GPS';
  100.  
  101.  Label1.Caption:='111111111111';
  102.  if Tenesi.Active
  103.   then
  104.    begin
  105.     Label1.Caption:='222222222222';
  106.     Comanda:='PK_A2,';
  107.     comanda:=comanda+'Mode: ';
  108.     case ModeFly of
  109.      0:comanda:=comanda+' MAN,';
  110.      1:comanda:=comanda+' ATT,';
  111.      2:comanda:=comanda+' GPS,';
  112.     end;
  113.     str(Bat:2:2,s);      comanda:=comanda+' Bat: '+s+#13#10;
  114.     Tenesi.WriteData(Comanda);
  115.     str(Lat:2:7,s);      comanda:='Lat: '+s+',';
  116.     str(Lon:2:7,s);      comanda:=comanda+' Lon: '+s+',';
  117.     str(AltG:4:2,s);     comanda:=comanda+'GPS alt: '+s+',';
  118.     str(Cog:3:2,s);      comanda:=comanda+'COG: '+s+',';
  119.     str(Speed:2:2,s);    comanda:=comanda+'Speed: '+s+',';
  120.     str(GPSVSI:3:2,s);   comanda:=comanda+'GPS VSI: '+s+',';
  121.     str(Sat:2:2,s);      comanda:=comanda+'Sat: '+s+#13#10;
  122.     Tenesi.WriteData(Comanda);
  123.     str(Alt:3:2,s);      comanda:='Alt: '+s+',';
  124.     //str(VSI:3:0,s);      comanda:=comanda+'VSI: '+s+',';
  125.     str(Curs:3:2,s);     comanda:=comanda+' Heading: '+s+#13#10;
  126.     Label1.Caption:='333333333333';
  127.     Tenesi.WriteData(Comanda);
  128.     Label1.Caption:='444444444444';
  129.    end;
  130.  Label1.Caption:='555555555555';
  131. end;
  132.  
  133. procedure TTenesi_Creator.Timer2Timer(Sender: TObject);
  134. Var HH,MM,CC,KK:word;
  135.     s,Comand:string;
  136. begin
  137.  Label1.Caption:='66666666666';
  138.  GetTime(HH,MM,CC,KK);
  139.  str(HH:2,s);
  140.  Comand:='Date/Time: 05.07.19 '+s+':';
  141.  Label7.Caption:=Comand;
  142.  str(MM:2,s);Comand:=Comand+s+':';
  143.  str(CC:2,s);Comand:=Comand+s;
  144.  Label7.Caption:=Comand;
  145.  Comand:=Comand+#13#10;
  146.  Label1.Caption:='77777777777';
  147.  If Tenesi.Active then Tenesi.WriteData(Comand);
  148.  Label1.Caption:='88888888888';
  149. end;
  150.  
  151. //Выполняется по нажатию на кнопку Подключение Устройства 1
  152. procedure TTenesi_Creator.ConButClick(Sender: TObject);
  153. begin
  154.  Tenesi.Device := deviceList.Text;
  155.  Tenesi.BaudRate:= LazSerial.br115200;
  156.  if Not Tenesi.Active  then Tenesi.Open
  157.                     else Tenesi.Close;
  158.  if Tenesi.Active
  159.   then ConBut.Caption:='Отключить'
  160.   Else ConBut.Caption:='Подключить';
  161. end;
  162.  
  163. end.  
  164.  
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: avra on June 15, 2019, 02:35:10 pm
Why do these delays occur? How to fix that they were not?
Your application does everything in the main thread, including message processing. When that main thread is blocked with something as slow as serial communication, windows messages do not get processed and your application is not responding looking frozen until communication is finished. Sometimes when chunks of communication are not that long you can fix this by putting Application.ProcessMessages in comm loops or by putting it right after one serial communication and before next one is started. More often you need to do it the proper way, by introducing separate communication thread and synchronizing that with your application and GUI. To do that you need a lot of learning. Search the docs, forum and wiki on the topic.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: FedCo on June 15, 2019, 03:33:38 pm
The solution was found !!!!
In the inspector of the objects of the library Lazserial there is a parameter Device. SynSer. DeadlocktimeOut, which is not updated in the inspector of objects, it must be registered in the program itself. The default value is 30000, you need to set it to the value you need, I set 100 for myself. Everything worked without any hangs.

Device. SynSer. DeadlocktimeOut:=100;
Write this line after opening the port.

Thank you all for your help !!! ))))))))).
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: avra on June 15, 2019, 03:58:33 pm
In the inspector of the objects of the library Lazserial there is a parameter Device. SynSer. DeadlocktimeOut, which is not updated in the inspector of objects, it must be registered in the program itself. The default value is 30000, you need to set it to the value you need, I set 100 for myself.
Synapse SynaSer is the father of TLazSerial and for DeadlockTimeout property documentation at http://synapse.ararat.cz/doc/help/synaser.TBlockSerial.html#DeadlockTimeout says:
Quote
This timeout value is used as deadlock protection when trying to send data to (or receive data from) a device that stopped communicating during data transmission (e.g. by physically disconnecting the device). The timeout value is in milliseconds. The default value is 30,000 (30 seconds).
It smells like you have communication issues on a physical wire level or with device it self. Your application might behave better, but source of the problem still exists. If you use RS485 then check for proper resistor termination on both ends of the cable. If you use RS232/422/485 then check for proper shielding. If you use RS232 then max cable length for 9600bps in ideal conditions should not exceed 30m, in less ideal conditions even less. With 115200 do not go over 10m if you want stable communication. You can use oscilloscope to see how clean your signal is. Avoid energetic cables whenever you can with your communication cable, especially if heavy consumers and motors are powered by them. Keep distance of at least 30cm from them, and if you must cross them then cross at 90 degree angle (even when having a proper distance). Check grounding on both sides. Find shortest possible communication cable and let your laptop be the only master to your device, disconnecting other devices if there are any. If problems go away, wiring is guilty. If they persist then device is guilty. If device allows then lowering communication speed can help sometimes.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: FedCo on June 15, 2019, 04:06:16 pm
There are no devices.
Made virtual connected com ports.
And after I changed the value of 30,000 to 100, everything began to work fine. No data loss was noticed, the program was already running for more than an hour and there were no stops.
Before changing the parameter, the stops occurred 10-20 times in 5 minutes.
After changing the parameter, I even reduced the execution time of the program procedure twice, and still everything works fine!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: avra on June 15, 2019, 04:31:53 pm
There are no devices.
Made virtual connected com ports.
And after I changed the value of 30,000 to 100, everything began to work fine. No data loss was noticed, the program was already running for more than an hour and there were no stops.
Stops are still there. They just now last 100ms instead of 30s so it is harder to notice them. There are many virtual comm port implementations, and some are buggy. You should try another one.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PaulRowntree on September 13, 2019, 11:31:19 pm
Thank you to avra and FedCo for giving solid tips on my own 30 sec freeze problem!
Here is another issue : my Win10 machine, with 64 compilation on Laz 1.8 uses the {$H+} option which should (I think) force AnsiStrings throughout the code.  However, my received messages in LazSerial were getting clipped to 255 characters.  The problem was solved by adding {$H+} to the LazSerial unit, as well as my own units that subclassed the base component to my wn needs.
Is this the expected behaviour?  I assumed that the {$H+} in the Options dialog would cover everything ..
Thanks again avra & FedCo!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: mas steindorff on March 05, 2020, 03:11:13 am
FYI: I use synaser as a unit in it's own thread running at 921,600 baud.  The end device streams binary data to my program using DMA so the spacing between bytes is as small as possible (2 or 3 bit times).  synaser works well for me here.  The (my) program is is responsive where other comm programs will lock up until there is a pause in the data stream.  Tested both Realterm and TaraTerm with the same results.  The big difference is they try to show each byte where I only display a summery.
IMHO you will find the display update is your bottle neck unless your using something like OpenGL.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on May 01, 2020, 10:45:23 am
hello,
a new version (0.3)  of the component is available here (https://github.com/JurassicPork/TLazSerial)

 new in v0.3 version
 Add conditional macros for cpuarm rpi in lazsynaser.pas
 Hide Active property from IDE Object inspector

checked on Windows 10 Lazarus 2.0.8    and   Linux Centos 8  Lazarus 1.8.2 

wp,  you can put this update in your online package manager.

Friendly, J.P         
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: wp on May 01, 2020, 10:46:51 am
wp,  you can put this update in your online package manager.
Please contact GetMem. I don't have access to the OPM repo.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on May 01, 2020, 10:50:11 am
oops sorry  :-\    the message
Quote
you can put this update in your online package manager.
is for GetMem

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: balazsszekely on May 01, 2020, 11:48:28 am
Quote
you can put this update in your online package manager.
Done. Thank you!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BosseB on May 08, 2020, 09:59:59 am
Probably stupid question, but:
Can LazSerial be used with Delphi 2007 in some way?

I am trying to prepare a D2007 service project for porting to FPC/Lazarus by identifying stuff that relies on external components and the like and converting these to somewhat native Delphi or else FPC type units.
I have already moved a lot of stuff I could understand myself to no longer rely on the external units, but the serial comm is not there yet. I use the Turbo Async Pro serial component for the original code and I want to exclude this before using the Lazarus Delphi converter since otherwise it will bring in so many of the Async Pro units...

And today I just flashed a thought:
Maybe LazSerial can be used already in Delphi 2007? That would simplify the porting a lot since LazSerial is what I intend to use in the final solution.
But I must make sure the prepared project in D2007 still builds and works the same as before...

Note:
In the project all components are created in code, there is no "drop on form" automatic handling of them, so I know exactly where they are actually handled.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on May 10, 2020, 12:35:16 am
hello,
Probably stupid question, but:
Can LazSerial be used with Delphi 2007 in some way?
No.

Quote
In the project all components are created in code, there is no "drop on form" automatic handling of them, so I know exactly where they are actually handled.

Use Synaser library.

Friendly, J.P

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Mark20 on June 02, 2020, 12:47:44 pm
Hello,
just installed the useful TLazSerial and was wondering how enumerate the serial ports available in the system (Win or RPi)...
Also looking for a blocking function which read all until received a specific char or Timeout...
In the past posts I see references to a synaser object but do not understand how use it....
Can you Help ?
Regards
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on June 02, 2020, 05:46:14 pm
hello,
have a look to the RecvTerminated function
Quote
function RecvTerminated(Timeout: Integer; const Terminator: AnsiString): AnsiString; virtual;
This method waits until a terminated data string is received. This string is terminated by the Terminator string. The resulting string is returned without this termination string! If no data is received within the Timeout (in milliseconds) period, LastError is set to ErrTimeout.

to access to this function from for example myLazSerial  TLazserial component :
myLazSerial.SynSer.RecvTerminated

Friendly, JP
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Mark20 on June 02, 2020, 11:53:50 pm
Thank you very much JP !
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BosseB on July 22, 2020, 10:38:15 am
I ran into a difficult problem with LazSerial when I integrated it as a replacement for a Delphi-only serial port component into a Delphi -> Lazarus conversion.
Originally when I tested LazSerial for this purpose I was using a GUI project and then I received help here to make it build on both Windows10 and Linux (Raspbian).

But now when I am using it in a console program which will run as a systemd service on Linux I cannot get the project to build!

I can do quick compile and it succeeds but as soon as I do a build to get the executable it fails in the linking step with a large number of error messages like these:
Code: Text  [Select][+][-]
  1. wsmenus.pp(263,1) Error: undefined reference to `WSRegisterMenu'
  2. wsmenus.pp(263,1) Error: undefined reference to `WSRegisterPopupMenu'
It seems like it is bringing in GUI dependencies into the project and since it is a console program this is a no-no...
I googled and found basically the same issue in a thread here named "Using LazSerial in console application (https://forum.lazarus.freepascal.org/index.php?topic=21998.0)" from 2013!

Unfortunately a solution is described that I feel is not really working, so I need some advice here on what to do.
I have looked over all of my own source files and removed all GUI-related stuff including units in uses clauses that reference GUI related items.
The application compiles successfully using "Quick Compile" but when building it fails in the final linking step and spews out all these errors like in the linked post.

Question:
How can I use LazSerial in a non-gui console application on Linux?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on July 23, 2020, 01:21:12 am
hello,
TLazSerial is a component for GUI application. For console application use synaser.
Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BosseB on July 23, 2020, 07:38:02 am
UPDATE:
In the unit where LazSerial is referenced I added an extra uses item
like this:

Code: Pascal  [Select][+][-]
  1.   {$IFDEF FPC}
  2.     interfaces, //Needed for LazSerial to work in a Console program
  3.     LazSerial,  //The serial component
  4.   {$ELSE} //Delphi

When I now build the project the linker does not trigger any
complaints about missing Menu related identifiers and the build
succeeds!

Why this happens I don't know and also if it is still going to work, so far I have yet to check the functionality of LazSerial. For that I need some hardware devices attached to the RPi4B unit, which I don't have available where I am now.
But now I can continue working on other parts of the application without being stopped by the linking error from LazSerial.  :)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: PascalDragon on July 23, 2020, 09:33:54 am
Code: Pascal  [Select][+][-]
  1.   {$IFDEF FPC}
  2.     interfaces, //Needed for LazSerial to work in a Console program
  3.     LazSerial,  //The serial component
  4.   {$ELSE} //Delphi

When I now build the project the linker does not trigger any
complaints about missing Menu related identifiers and the build
succeeds!

The Interfaces unit links in the GUI widgetset of the LCL which is not really what you want for a command line application. Do as Jurassic Pork (and Michael on the mailing list) suggested and use the serial component of Synaser directly (TLazSerial is "simply" a GUI wrapper for that).
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BosseB on July 28, 2020, 06:25:57 pm
Code: Pascal  [Select][+][-]
  1.   {$IFDEF FPC}
  2.     interfaces, //Needed for LazSerial to work in a Console program
  3.     LazSerial,  //The serial component
  4.   {$ELSE} //Delphi

When I now build the project the linker does not trigger any
complaints about missing Menu related identifiers and the build
succeeds!

The Interfaces unit links in the GUI widgetset of the LCL which is not really what you want for a command line application. Do as Jurassic Pork (and Michael on the mailing list) suggested and use the serial component of Synaser directly (TLazSerial is "simply" a GUI wrapper for that).

Back again...
The trick with adding interfaces to the uses clause just before LazSerial "seemed" to work.

But that was because I was running my console app inside a terminal window in Raspbian Buster on an RPi4.
Today I tried to run it inside a PuTTY SSH shell window connected to that same RPi4.
The result was that I got this error:
Code: Text  [Select][+][-]
  1.     $ ./SSRemoteServerLx
  2.  (SSRemoteServerLx:5753): Gtk-WARNING **: 14:39:10.439: cannot open display:

Apparently there are GUI dependencies that are not met in a "real" console and stops the application from even starting up.
Since the program must in the end run as a Systemd service on an RPi4 server with noone logged on it must not behave this way...

So now I am coming back to this problem once more, how can I remove the GUI dependencies from LazSerial?
Or how can I use SynaSer directly, as has been suggested, when it is blocking and the code (rather big) I am porting is using an event driven concept for receiving data?

As far as I can see the Synaser serial component uses blocking reads rather than events to signal arrival of data to read...
Do you know of any Synaser adaptation adding an OnRxData() event such that it can fire as the event on LazSerial does but does not bind in GUI dependencies?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork 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 (https://forum.lazarus.freepascal.org/index.php/topic,36603.msg244108.html#msg244108)
Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: brochagdl 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.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: MarkT1993 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 (https://wiki.freepascal.org/Forum))
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BosseB 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.  
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: MarkT1993 on September 22, 2020, 01:54:37 pm
Brilliant thanks BosseB thats sorted it now.
Thanks for the tip on Code tags too.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: TopCat on January 09, 2021, 05:54:53 pm
I would appreciate help understanding how to install the TLazSerial components under newly installed Lazarus 2.0.0 running on Raspbian Pi OS. I have successfully downloaded the TLazSerial files. I have edited LazSynaser.pas to comment out the UNIX specific baud rates and changed the value of MaxRates from 30 to 19 to avoid compile errors. When I attempt to Install the package I get the message "The package 'LazSerialPort-0.2.pas' was marked for installation. Currently Lazarus only supports static linked packages. The real installation needs rebuilding and restartng of Lazarus.". Attempts to rebuildLazarus are met with a dialog showing ""Cannot find fpdebug used by Lazarus".
Apologies if this is an issue with Lazarus rather than LazSerial but I'd be very grateful for any guidance members can offer to a Linux / Lazarus newbie.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: hansotten on January 09, 2021, 07:12:25 pm
I would appreciate help understanding how to install the TLazSerial components under newly installed Lazarus 2.0.0 running on Raspbian Pi OS. I have successfully downloaded the TLazSerial files. I have edited LazSynaser.pas to comment out the UNIX specific baud rates and changed the value of MaxRates from 30 to 19 to avoid compile errors. When I attempt to Install the package I get the message "The package 'LazSerialPort-0.2.pas' was marked for installation. Currently Lazarus only supports static linked packages. The real installation needs rebuilding and restartng of Lazarus.". Attempts to rebuildLazarus are met with a dialog showing ""Cannot find fpdebug used by Lazarus".
Apologies if this is an issue with Lazarus rather than LazSerial but I'd be very grateful for any guidance members can offer to a Linux / Lazarus newbie.
Use the Pacakage manager, no need to update.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BosseB on January 09, 2021, 11:57:52 pm
I would appreciate help understanding how to install the TLazSerial components under newly installed Lazarus 2.0.0 running on Raspbian Pi OS.
How come you are installing such an old version of Lazarus?
It is at version 2.0.10 now...
Quote
I have successfully downloaded the TLazSerial files.
How did you "download the files"?
What you should do is to use the OnLine PackageManager available as menu Package/OnLine Package Manager.
Here you will find the LazSerial package, just select it and use the Install button on the bottom and it will work right away.

As always with these GUI style components you need to "install" them into Lazarus, which means that Lazarus is rebuilt in the process. Fully normal...
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: TopCat on January 10, 2021, 12:14:58 pm
Many thanks for the feedback. I downloaded the TLazSerial zip file pointed to from https://forum.lazarus.freepascal.org/index.php?topic=20481.0 and (almost) followed the instructions. Thanks Bo for highlighting the menu items "Package / Online Package Manager. That part worked up to the point where the recompile failed with "Cannot find fpdebug used by Lazarus". I sense that is a different problem and unrelated to to TLazSerial. The old versions of  fpc and Lazarus are the versions installed by Raspbian OS using Preferences | Add / Remove programs or sudo apt-get install fpc and sudo apt-get install lazarus.
Seems I need to work out how to install the current versions of fpc and lazarus before attempting to install LazSerial again. That will be a new learning opportunity for me.
Many thanks for you help and understanding.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BosseB on January 10, 2021, 03:32:07 pm
Thanks Bo for highlighting the menu items "Package / Online Package Manager.
That part worked up to the point where the recompile failed with "Cannot find fpdebug used by Lazarus".
I sense that is a different problem and unrelated to to TLazSerial.
The old versions of  fpc and Lazarus are the versions installed by Raspbian OS using Preferences | Add / Remove programs or sudo apt-get install fpc and sudo apt-get install lazarus.
Seems I need to work out how to install the current versions of fpc and lazarus before attempting to install LazSerial again.
That will be a new learning opportunity for me.
Many thanks for you help and understanding.
I have created a blogpost on my server (https://blog.boberglund.com/) where I describe how to install Fpc/Lazarus on Raspberry Pi using sources from Subversion.
I have scripts there, which I always use when installing on new devices.
Please have a look!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: TopCat on January 10, 2021, 03:51:52 pm
In case it helps others, I've solved my problem and successfully installed TLazSerial in Lazarus 2.0.10 running under Raspbian OS.
I used Raspbian Preferences | Add / Remove programs to remove the previous 2.0.0 version installed by Rasbian OS by default. I kept the Raspbian installed 3.0.4 version of fpc (Free Pascal Compiler). I then followed the instructions at <https://wiki.freepascal.org/Installing_Lazarus_on_Linux#Build_Lazarus_from_Source> to install Lazarus 2.0.10.
I had to use the Update option on a dialog when trying to run Lazarus as it seems Raspbian had not deleted the previous version of Lazarus (This is probably down to me not getting the uninstall correct).
From the Lazarus main menu I used Package |  Online Package Manager to install LazSerial. This time, after a successful installation of LazSerial, Lazarus did a successful compile to install LazSerial into the IDE.
Next task is to do a clean install of Raspbian OS and install current versions of fpc, Lazarus and LazSerial to avoid any potentially remaining issues.
MANY THANKS to previous contributors who helped get me here!
Should it be useful to others, here is the code I used to test that I had successfully installed LazSerial. It uses two buttons, a memo component and the all important TLazSerial component to read a device.
+++++++++++++++++++++++++++++++++++++
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
  Classes, SysUtils, LazSerial, Forms, Controls, Graphics, Dialogs, StdCtrls
  , LazSynaSer;
type
  { TForm1 }
  TForm1 = class(TForm)
    btnOpen: TButton;
    btnClose: TButton;
    LazSerial1: TLazSerial;
    Memo1: TMemo;
    procedure btnCloseClick(Sender: TObject);
    procedure btnOpenClick(Sender: TObject);
    procedure LazSerial1RxData(Sender: TObject);
  privateremaining
  public
  end;
var
  Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.btnOpenClick(Sender: TObject);
Begin
  LazSerial1.ShowSetupDialog;
  LazSerial1.Open;
  Memo1.Clear;
end;
procedure TForm1.btnCloseClick(Sender: TObject);
begin
  LazSerial1.Close;
  Close;
end;
procedure TForm1.LazSerial1RxData(Sender: TObject);
begin
  Memo1.lines.Add(LazSerial1.ReadData);
end;
end.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: TopCat on January 10, 2021, 04:00:22 pm
BosseB,
I've just seen your latest reply. It looks to be very helpful. I'll try that with a fresh install of Raspbian OS, though using scripts will be a new experience for me. Life is full of opportunities ;-).
Thanks again for your support.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CJ on February 17, 2021, 01:37:54 pm
Hi, I am porting a working PCDIMMER Delphi program to Lazarus in particular replacing the ComDrv32 comportdriver with LazSerial. I used the instruction of TopCat in his post. Thanks for sharing your experience.
TopCat
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #325 on: January 10, 2021, 03:51:52 pm »

LazSerial is now in the Lazarus IDE.
compilation of PCDIMMER.PAS at  PCDIMMER.PAS(241,46) Error: Duplicate identifier "Action". I don’t see something wrong in the code and this module was giving no problems in the past. It is a mystery to me. I have included the erroneous Lazarus version.
Many thanks in advance,
Chris
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 17, 2021, 02:15:13 pm
hello,
try to change the name of your variable for the tCloseAction argument. For example :
Code: Pascal  [Select][+][-]
  1.  procedure FormClose(Sender: TObject; var ActionClose: TCloseAction);

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CJ on February 17, 2021, 05:43:29 pm
Hi JP. the correction makes compilation go a bit further. I am now replacing the calls from ComDrv32 into LazSerial ones. The first try: replace comport.senddata(@b,1);  into comport.WriteBuffer(@b,1); gives already troubles. The compiler complains with: PCDIMMER.PAS(322,33) Error: Can't assign values to an address. I am new in Pascal but I thought that @b means “the address of byte b” and that is a pointer. The WriteBuffer is declared as : function WriteBuffer(var buf; size: integer): integer; I don’t see the problem but I don’t understand the meaning of Pointer(@buf) in the body of the function. What does it means?


Here the ComDrv32 function
function TCommPortDriver.SendData( DataPtr: pointer; DataSize: dword ): dword;
var nToSend, nsent,t1: dword;
//    t1: longint;
   // dd:TdateTIME;
begin
  // DD:=DATE;
 //   IF DD>STRTODATE('99-07-01') THEN SHOWMESSAGE('ASDFASDFASDFSADFASDF');///


  { 0 bytes sent }
  Result := 0;
  { Do nothing if not connected }
  if not Connected then
    exit;
  { Current time }
  t1 := GetTickCount;
  { Loop until all data sent or timeout occurred }
  while DataSize > 0 do
  begin
    { Get output buffer free space }
    nToSend := OutFreeSpace;
    { If output buffer has some free space... }
    if nToSend > 0 then
    begin
      { Don't send more bytes than we actually have to send }
      if nToSend > DataSize then
        nToSend := DataSize;
      { Send }
      WriteFile( FComPortHandle, DataPtr^, DataSize, nsent, nil );
      { Update number of bytes sent }
      Result := Result + abs(nsent);
      { Decrease the count of bytes to send }
      DataSize := DataSize - abs(nsent);
      { Get current time }
      t1 := GetTickCount;
      { Continue. This skips the time check below (don't stop
        trasmitting if the FOutputTimeout is set too low) }
      continue;
    end;
    { Buffer is full. If we are waiting too long then
      invert the number of bytes sent and exit }
    if (GetTickCount-t1) > FOutputTimeout then
    begin
      Result := -Result;
      exit;
    end;
  end;
end;

Here the TLazSerial function
function TLazSerial.WriteBuffer(var buf; size: integer): integer;
begin
//  if FSynSer.Handle=INVALID_HANDLE_VALUE then
 //   ComException('can not write to a closed port.');
  result:= FSynSer.SendBuffer(Pointer(@buf), size);
end;

Is there an example of code available to learn more about the use of LazSerial?
The program itself is the user interface of a 16-port dimmer steered by a serial link. It is not a complicated thing, it needs to open, close the port and send data to it.
Thanks for the help,
CJ

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on February 22, 2021, 10:32:23 pm
I have a simple application using TLazSerial. So far, I am reading data from the device using the button - the reading event will take place only once. But using the button increases the CPU load to 25%, even though the application theoretically no longer does anything. The load drops after the Serial.Close event. Windows7, Lazarus v 2.0.10, LazSerialPort 0.3.
Excuse my English - I use a Goggle translator.
Does anyone know what I'm doing wrong?
Here is the reading procedure:

procedure TForm1.BtDataClick(Sender: TObject);
var Str : string;
begin
  Str :='#APP:cw:data?' + #13 + #10;   //Request to send data
  try
    Serial.WriteData(Str);
    Str :=  Serial.ReadData;
    Memo1.Append(Str);
    Serial.SynSer.Flush;
  except
    On E :Exception do
    begin
      ShowMessage(  E.Message);
    end;
  end;
end; 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 22, 2021, 11:27:17 pm
hello,
TLazSerial is an event-driven component
don't use Serial.ReadData in a procedure or function.
With TLazSerial there is a thread that listens the serial port. When some data come to the serial port , they are read in the SerialRxData procedure. See how it works in the demo project of Lazserial.


Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on February 23, 2021, 07:51:24 am
Thank you for the quick information. Unfortunately, I will not get to the device with which the application works until Thursday. I will redesign the application and announce the result.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on February 25, 2021, 12:33:02 pm
Behavior of the SerTest sample application included with TLazSerial:
My configuration: Windows7, Lazarus v 2.0.10, LazSerialPort 0.3., Profilic USB-COM1 - HW connection of pins 2 and 3.
- Connection COM1 OK, Start simulator OK - reading and writing data OK, processor load approx. 0-3%
- Stop simulator - OK, CPU load approx. 0%
- COM closing, application termination - CPU load 25% (!!!), COM can no longer be opened, application cannot be terminated
- application cannot be terminated, SerialRXData thread apparently blocks COM and prevents execution of Application.Terminate

Some ideas?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 25, 2021, 12:56:07 pm
hello,
Behavior of the SerTest sample application included with TLazSerial:
My configuration: Windows7, Lazarus v 2.0.10, LazSerialPort 0.3., Profilic USB-COM1 - HW connection of pins 2 and 3.
- Connection COM1 OK, Start simulator OK - reading and writing data OK, processor load approx. 0-3%
- Stop simulator - OK, CPU load approx. 0%
- COM closing, application termination - CPU load 25% (!!!), COM can no longer be opened, application cannot be terminated
- application cannot be terminated, SerialRXData thread apparently blocks COM and prevents execution of Application.Terminate
Some ideas?

Strange  %)  i have no problem on windows 10  with two FTDI USB-COM ports.  Have you another software using your port ? Have you added code to sertest project ?

Friendly,  J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on February 25, 2021, 01:07:13 pm
COM1 is separate, not occupied by other SW (windows would not even allow it).
I did not interfere with the app. sertest
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 25, 2021, 01:24:51 pm
have you connected your serial device to your usb serial port ?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on February 25, 2021, 01:38:29 pm
I tried SerTest on another computer with Win7 and native COM1. Everything OK, no problem.
On the same computer with profilic USB-COM (COM16) the same behavior as on my computer.
So the problem is caused by the USB-COM profile converter. But to this day no problem with other applications.
Is it possible to influence the behavior of SerialRXData in any way?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 25, 2021, 01:59:59 pm
i have tried to connect an USB-COM with prolific  chip :    i can't connect to it   too old !    (see attachment)
with  FTDI USB-COM  i have no problem.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: MarkMLl on February 25, 2021, 02:09:08 pm
i have tried to connect an USB-COM with prolific  chip :    i can't connect to it   too old !    (see attachment)
with  FTDI USB-COM  i have no problem.

Are you aware that Prolific has always had a massive problem with counterfeits? A substantial proportion of Prolific-badged chips in cheap serial converters are actually generic microcontrollers programmed to emulate the basic Prolific functionality... if you want something reliable than buy something with an FTDI chip in it from a reputable source.

MarkMLl
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: hansotten on February 25, 2021, 04:33:06 pm
i have tried to connect an USB-COM with prolific  chip :    i can't connect to it   too old !    (see attachment)
with  FTDI USB-COM  i have no problem.
Even the non-counterfeit version of the Prolifics, fucntioning well, are treated as 'too old' by the latest drivers.
Get an old version of the driver: http://retro.hansotten.nl/other-retro-articles/serial-usb-adapters-testing/ search for Prolific, and get the archive from there.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: hansotten on February 25, 2021, 04:36:25 pm
i have tried to connect an USB-COM with prolific  chip :    i can't connect to it   too old !    (see attachment)
with  FTDI USB-COM  i have no problem.

Are you aware that Prolific has always had a massive problem with counterfeits? A substantial proportion of Prolific-badged chips in cheap serial converters are actually generic microcontrollers programmed to emulate the basic Prolific functionality... if you want something reliable than buy something with an FTDI chip in it from a reputable source.

MarkMLl
I  have one counterfeit FTDI IC in a Mega2560. The Windows driver by FTDI bricks it, unbricked it in Linux and now works fine in Linux. I regularly read people still getting a counterfeit FTDI in a cheap USB serial.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: MarkMLl on February 25, 2021, 05:02:04 pm
I  have one counterfeit FTDI IC in a Mega2560. The Windows driver by FTDI bricks it, unbricked it in Linux and now works fine in Linux. I regularly read people still getting a counterfeit FTDI in a cheap USB serial.

Which is why I used the words "reputable source": this has been a problem with Prolifics for a /long/ time... quite a few years before FTDI had their patience tested beyond endurance.

The Linux FTDI utility allows you to do things like writing a serial number to the chip: does that work properly, or it there some other easy way of detecting an FTDI counterfeit?

MarkMLl
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 25, 2021, 05:35:31 pm
i have tried to connect an USB-COM with prolific  chip :    i can't connect to it   too old !    (see attachment)
with  FTDI USB-COM  i have no problem.
Even the non-counterfeit version of the Prolifics, fucntioning well, are treated as 'too old' by the latest drivers.
Get an old version of the driver: http://retro.hansotten.nl/other-retro-articles/serial-usb-adapters-testing/ search for Prolific, and get the archive from there.
thanks hansotten for the driver, now i can connect to my prolific USB-COM, transferring some data between this USB-COM and a FTDI USB-COM , close the port but i have the same problem than Joek -> i can't close the sertest application (by the cross) i need to kill it.   This problem does'nt come with FTDI USB-COM.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on February 25, 2021, 07:51:45 pm
Sorry to add to your expert discussion, but WIn7 downloaded the drivers for my Profilic USB-COM port itself,
he did not report any counterfeits and we have not had a problem with them to this day. I usually program various types of radios with it (Motorola, Mototrbo, Hytera and various Chinese products). It also joins the two timekeepers when measuring races. Seamlessly.
I would like to find out where the problem is, but if it doesn't work with LazSerial, I won't do anything about it ....
By the way ... for Jurassic Pork: is the ZX1 still functional? If so, my admiration ...
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on February 25, 2021, 08:09:58 pm
I'm starting to feel like a fool: I found a noname USB-COM converter in stock. Windows identified it as an FTDI device without any specification, without a digital signature, an unknown provider. SerTest works without any hesitation ....
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 26, 2021, 12:42:51 am
For the zx81 i don't know : i don't dare to power on again :  i am afraid to destroy it. I
i have tried my prolific UQ on Ubuntu 20.04 --> no problem  i can close my serial application.
Quote
[   12.235225] usbserial: USB Serial support registered for pl2303
[   12.235249] pl2303 1-5:1.0: pl2303 converter detected
[   12.236333] usb 1-5: pl2303 converter now attached to ttyUSB0
and for the driver under windows 10 :
Quote
NOTE:

Windows 8/8.1/10 are NOT supported in PL-2303HXA and PL-2303X EOL chip versions.
Run PL2303 CheckChipVersion tool program in Windows XP/Vista/7 to check chip version.
Windows Vista, XP, 2000, 98 and Windows ME driver technical support are discontinued.
Prolific recommends to use PL-2303HXD (HX Rev D) or PL2303TA chip.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on February 26, 2021, 01:14:00 am
PL2303 CheckChipVersion marked my chip as type PL-2303H. I installed the latest version of Profilic drivers - no compatibility issue (Win7 support). But the situation has not changed - I can not close the application. We probably won't solve it - thank you for your effort.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 26, 2021, 10:13:40 am
hello,
i have played with my prolific USB-COM and sertest on debug  and i have found where there is a problem :

it is in the DeviceClose procedure :

Code: Pascal  [Select][+][-]
  1. procedure TLazSerial.DeviceClose;
  2. begin
  3.   // flush device
  4.   if FSynSer.Handle<>INVALID_HANDLE_VALUE then begin
  5.     FSynSer.Flush;
  6.     FSynSer.CloseSocket;
  7.  //   FSynSer.Purge;
  8.   end;
  9.  
  10.   // stop capture thread
  11.   if ReadThread<>nil then begin
  12.     ReadThread.FreeOnTerminate:=false;
  13.     ReadThread.MustDie:= true;
  14.     while not ReadThread.Terminated do begin
  15.       Application.ProcessMessages;
  16.     end;
  17.     ReadThread.Free;
  18.     ReadThread:=nil;
  19.   end;  
     

with no breakpoint if i open the serial port and close the port , closing the port i don't reach ReadThread.Free : seems to be stayed in the ReadThread.Terminated loop.
if i put a breakpoint at the beginning of the procedure (line  if FSynSer.Handle) no problem running after the program . I reach the end of the procedure.
I have tried to put a delay at the beginning of the procedure with no success.
I don't understand why the breakpoint solve the problem.
friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on February 26, 2021, 03:45:46 pm
Amazing discovery !!! For me, it works the same as for you. But ... what about that? I don't get it very well either - this is too much for me.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on February 26, 2021, 03:57:02 pm
I noticed that the flush device and the close device are the same codes. I canceled the flush. I don't know what I messed up, but it works ....
Code: Pascal  [Select][+][-]
  1. procedure TLazSerial.DeviceClose;
  2. begin
  3.   // flush device
  4.  // if FSynSer.Handle<>INVALID_HANDLE_VALUE then begin
  5.  //   FSynSer.Flush;
  6.  //   FSynSer.CloseSocket;
  7.  ////   FSynSer.Purge;
  8.  // end;
  9.  
  10.   // stop capture thread
  11.   if ReadThread<>nil then begin
  12.     ReadThread.FreeOnTerminate:=false;
  13.     ReadThread.MustDie:= true;
  14.     while not ReadThread.Terminated do begin
  15.       Application.ProcessMessages;
  16.     end;
  17.     ReadThread.Free;
  18.     ReadThread:=nil;
  19.   end;
  20.  
  21.   // close device
  22.   if FSynSer.Handle<>INVALID_HANDLE_VALUE then begin
  23.     FSynSer.Flush;
  24.     FSynSer.CloseSocket;
  25.   end;
  26. end;                    
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 26, 2021, 04:21:10 pm
thanks for the Info  Joek,   i think that there is a   wrong closeSocket  at the beginning of the DeviceClose procedure.

this should be :

Code: Pascal  [Select][+][-]
  1. procedure TLazSerial.DeviceClose;
  2. begin
  3.   // flush device
  4.   if FSynSer.Handle<>INVALID_HANDLE_VALUE then begin
  5.     FSynSer.Flush;
  6. //    FSynSer.CloseSocket;
  7.     FSynSer.Purge;
  8.   end;
  9.  
  10.   // stop capture thread
  11.   if ReadThread<>nil then begin
  12.     ReadThread.FreeOnTerminate:=false;
  13.     ReadThread.MustDie:= true;
  14.     while not ReadThread.Terminated do begin
  15.       Application.ProcessMessages;
  16.     end;
  17.     ReadThread.Free;
  18.     ReadThread:=nil;
  19.   end;
  20.  
  21.   // close device
  22.   if FSynSer.Handle<>INVALID_HANDLE_VALUE then begin
  23.     FSynSer.Flush;
  24.     FSynSer.CloseSocket;
  25.   end;
  26. end;  

1 - Flush and purge the serial port
2 - Terminate the read thread
3 - close the serial port

i must check if this code always works and why there is a "lost" closesocket at the beginning of the code.


Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on February 26, 2021, 04:38:15 pm
Thank you very very much for solving the problem. It looks like I'll be able to complete my timekeeper app!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on February 27, 2021, 09:50:15 am
hello,
i must check if this code always works and why there is a "lost" closesocket at the beginning of the code.
i confirm that there is a wrong code in the deviceClose procedure of lazserial.pas since the version 0.2   :-[
the wrong code can prevent the read thread to be terminated. It is the case for USB-COM adapter with prolific chip on windows.
A new version of lazserial is available on my repository (https://github.com/JurassicPork/TLazSerial) (with  a fixed code for the DeviceClose procedure  of Lazserial.Pas. The new version is the 0.4. Soon on onlinepackagemanager.

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: hansotten on February 27, 2021, 11:06:55 am
That is good news! Thank you for maintaining TLazSerial!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: sstvmaster on February 27, 2021, 11:49:24 am
Thank you J.P.!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on March 12, 2021, 11:53:54 pm
I apologize for the stupid question, but I would welcome advice: How do I test when using LazSerial that the connected device is turned off - it does not return any data (the OnRxData event does not occur)? Now I send a request for data with a timer, OnRxData collects and analyzes it. It is not interconnected. Somehow I ran out of ideas ...
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on March 13, 2021, 03:05:40 am
hello,
have a look here (https://forum.lazarus.freepascal.org/index.php/topic,42566.msg297308.html#msg297308) or here (https://forum.lazarus.freepascal.org/index.php/topic,21045.msg122767.html#msg122767)
friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek on March 13, 2021, 06:27:54 am
Yes, the most complex problems have simple solutions .... and vice versa. Thank you very very much!!!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CJ on March 21, 2021, 05:35:55 pm
Hi, I have a working PC-dimmer version now, build with Lazarus. I use ComportDriverThread.pas (https://static.elitesecurity.org/uploads/3/1/316386/ComportDriverThread.pas).
I did not have to make a lot of changes to make PC-dimmer work starting from the try-out with ComDrv32. I have listed the changes in differences.txt. The file content is the result of the Unix diff command (https://unix.stackexchange.com/questions/81998/understanding-of-diff-output)
The source files are attached.
Many thanks on all who helped me in this conversion (see also Class ”TPage” not found posts).
I am ready just in time because the evaluation licence I used to make a Delphi version (Embarcadero 10.4) run out of time and the licence fee they ask is not affordable to me.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Frolov 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.  
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Frolov on March 28, 2021, 07:10:43 am
Picture for example
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Frolov on March 28, 2021, 07:35:06 am
Friends, how can I send and receive long strings ?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on March 28, 2021, 09:12:47 am
hello,
what is happening when you send this string :
Quote
abcdefghijklmnoprstuvwxyz0123456789
Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Frolov on March 28, 2021, 10:53:48 am
Everything is hyphenated after 32 characters
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Frolov on March 28, 2021, 10:56:12 am
Jurassic Pork help me out, I will be very grateful !!!

Your library is just great !!!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Frolov on March 28, 2021, 11:07:13 am
Here is the entire test project
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork 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
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Frolov 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 !!!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Frolov on March 28, 2021, 02:08:06 pm
Everything is great !!! Thanks !
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon 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.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: mas steindorff on September 29, 2021, 06:05:11 pm
let me guess, your working in an UNIX OS.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon on September 29, 2021, 06:51:07 pm
yes linux ubuntu 18.04
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: mas steindorff 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...
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon 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.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: MarkMLl on September 29, 2021, 07:56:24 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...

First thing to try is stty sane. However there's a specific funny in one of the serial device drivers which I've seen causing problems with faux-Arduino boards...

Code: C  [Select][+][-]
  1. /* This is the first project for which I've used Eclipse to program Arduinos
  2.  * with a CH340 chip. As of Eclipse 4.13 expect "staircasing" on those ports,
  3.  * see http://e2e.ti.com/support/tools/ccs/f/81/t/716472?CCS-EVMK2H-Serial-terminal-in-CCS-8-1-0-under-Linux-is-not-displaying-newlines-correctly
  4.  * for a fix but in short use a command like
  5.  *
  6.  * stty -F /dev/ttyUSBn -icrnl
  7.  *
  8.  * to disable kernel-level conversion of incoming carriage return (\r) to
  9.  * newline (\n) which will cause staircasing and double-spacing.
  10.  */
  11.  

Posted in the hope that it might be a useful addition to general knowledge, but without promising that it#s a fix in the current case.

MarkMLl
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon on September 29, 2021, 09:13:48 pm
I never speak of an Arduino.
And I ever said that I have a correct reception with no load charge cpu of the terminal program.

The problem is a bad interrupt of the RXread procedure as it  didnt appears... 

thank's.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: MarkMLl on September 29, 2021, 09:20:13 pm
I didn't say- or certainly didn't intend to imply- that it was Arduino-specific. It's a bug in one of the Linux serial driver modules which can be worked-around using stty... and I'd point out that you didn't give any details of the hardware you were using so I thought it worth throwing in lest it be relevant >:-)

MarkMLl
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon on September 29, 2021, 10:26:07 pm
yes, thank's for your help.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on September 30, 2021, 01:41:50 am
hello
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...
your examples are not very clear -> can you show  all the hexa bytes which are sent  ( ex 00 FF AA 13 10 ...) and what is received in SerialRxData and the code in the SerialRxData.
Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: alpine on September 30, 2021, 11:31:05 am
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.

Just a wild guess... You're using OnRxData event for receiving, which is called internally through TThread.Synchronized() and when the CPU is loaded it fails to execute your handler on time.
That way some bytes gets lost. Losing the #10 may be is just a coincidence. No way that initialized tty can translate cr/lf differently with respect of the CPU load.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon on September 30, 2021, 11:47:28 am
Hi

I'am pretty agree with your analisys y.ivanov!

No way to LF.
But the strange is that alll mesages are  only not serate and generally absolutly complete...


So I thinks that's a pb  of interrupt code as you explain :
is the soltuion to protect this thread part critical ?


thank's
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon on September 30, 2021, 11:57:46 am
with no problem:
ypr 258.7 12.8 -6.9 1446 //entete+3 reels+crc16
--------------ok
dst 329 F3D8 //entete+1 reel+crc16
--------------ok
ldt 85.10 A462 //entete+1 reel+crc16
--------------ok
gps 0 0 0 0 0 0 0 0 0902 //entete+8 integer+crc16
--------------ok


with problem (msg seem uncorretly receive ):
structure_message_example_nok:
"dem ?:"+bad_message+">"+crc16_receive_msg+"<NOKcrc"

dem ?:ldt 82.40 0ABA
gps 0 0 0 ypr 258.6 12.8 -7.1 7A37>0354<NOKcrc
+++++ nok
dem ?:ypr 258.6 12.ldt 86.10 3FBE>FCE2<NOKcrc
+++++ nok
dem ?:lps 0 0 0 0 0 0 0 0 0902>EB3C<NOKcrc  //ici melange ldt and gps
+++++ nok
ypr 258.7 12.8 -7.1 A27E
--------------ok
dem ?:ypr 258.7 12.ldt 90.30 D414>6C29<NOKcrc // message ypr dernier reel manque fract
+++++ nok

Not hexa but seem indicate a  pb of interruption rx thread as says y.ivanov...

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: alpine on September 30, 2021, 12:37:51 pm
@LaurentDelaon,
Are we discussing actually the https://github.com/JurassicPork/TLazSerial/tree/master/test program?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon on September 30, 2021, 12:48:37 pm
No discuss about this with him and me...
But maybe is it a very good idea....


I suggest modify his test prog like this :

add on form test a  sdpo video and observe if the messages gps are perturbates.
This is hardware dependent, but if we reproduce problem it's ok.

I can modify it's prog but I haven't gps.
I try to do it and inform you after realise this.

Then I will give the modified code if JurrassikPork is agree to help me  , on a real code problem it's better.

Laurent.
 
 

 

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon on September 30, 2021, 04:59:27 pm
Hi JurassikPork

I have modified your program test. 8)
I have include a video via a camera ; you can select video source and possibly modify zoom factor to increase load cpu (says 10 fps is like my condition  system).
to use it you should compile it with  sdpovideo and bgrabitmappack.
The setting initial parameter will not work after the video is on. (so set your serial before...)

Could you please try your communication with your gps observe whats happen with video on and cpu load at 10 fps ?

(You may check crc todetect badmessages.)

thanks for your help.  :)
Laurent.
 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on October 01, 2021, 09:23:36 am
hello,
sdpovideo must be a cpu muncher . Try to use another video display component.
Example :  TPasLibVlcPLayer (https://prog.olsztyn.pl/paslibvlc/)
i have try this component in my sertest project ---> no problem to receive gps frames while displaying ip camera
(see attachment).
The code of the button video on is :
Code: Pascal  [Select][+][-]
  1. PasLibVlcPlayer1.Play(WideString('http://webcam-roggwil1.bioforce.ch/axis-cgi/mjpg/video.cgi'));  
Friendly,J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon on October 01, 2021, 12:26:04 pm
thank's for your reply.
How did you do to read: /dev/video0 ?

Laurent.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on October 01, 2021, 12:58:17 pm
thank's for your reply.
How did you do to read: /dev/video0 ?
on windows i can see the first webcam with this command :
Code: Pascal  [Select][+][-]
  1. PasLibVlcPlayer1.Play(WideString('dshow://'));
dshow only on windows (directshow). On linux it is another command (may be tv://) , see the vlc documentation.
Ami calmant, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon on October 01, 2021, 04:36:20 pm
the answwer is:

Code: Pascal  [Select][+][-]
  1. PasLibVlcPlayer1.Play(WideString('v4l2:///dev/video0'));
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: MarkMLl on October 04, 2021, 10:00:51 pm
I  have one counterfeit FTDI IC in a Mega2560. The Windows driver by FTDI bricks it, unbricked it in Linux and now works fine in Linux. I regularly read people still getting a counterfeit FTDI in a cheap USB serial.

Which is why I used the words "reputable source": this has been a problem with Prolifics for a /long/ time... quite a few years before FTDI had their patience tested beyond endurance.

The Linux FTDI utility allows you to do things like writing a serial number to the chip: does that work properly, or it there some other easy way of detecting an FTDI counterfeit?

Just to get some oddments "into the record". I've been tidying up various serial-port code today, noting that very often that was working with an interface chip built into an instrument rather than a conventional RS232 port etc.

I can confirm that at least some of the counterfeit FTDI chips do not have writeable EEPROM: these can be identified in eBay etc. photos by bring serialised as G0370111 on the FT232RL chip, and possibly also by having a beige plastic-encapsulated capacitor next to the USB port rather than a ceramic device.

There must be at least one other counterfeit variant around, since a device with R/O EEPROM probably couldn't be bricked by a Windows driver.

Using Linux I was able to manipulate the serial number on a genuine chip using https://github.com/yogggoy/ftdi_eeprom_writer , and this leaves me able to locate which device (i.e. /dev/ttyUSBxxx) has a module in a particular role by its serial number... although it's hard work.

MarkMLl
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 on August 24, 2022, 08:59:34 am
Is there a way to make these setting of TLazSerial:


Code: Pascal  [Select][+][-]
  1. IOCTL_SERIAL_SET_QUEUE_SIZE: Set queue size
  2.    · Input       = 2048
  3.    · Output      = 2048
  4. IOCTL_SERIAL_SET_TIMEOUTS: Set timeouts
  5.    · Read interval               = 1
  6.    · Read total multiplier       = 0
  7.    · Read total constant         = 0
  8.    · Write total multiplier      = 0
  9.    · Write total constant        = 0
I found no properties for QueueSize and for the timeouts.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: sstvmaster on August 24, 2022, 12:42:26 pm
In LazSerial I don't think so, maybe JurassicPork knows more.

In TComPort there are these options.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on August 24, 2022, 03:43:38 pm
Hello,
In LazSerial I don't think so, maybe JurassicPork knows more.
I don't think : LazSerial use synaser and i haven't seen these properties in the TBlockSerial class of Synaser.

There is a SizeRecvBuffer property.

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 on August 26, 2022, 10:04:31 am
I am trying to connect a multimeter (GDM-461) to the PC.
I succeeded to make it work with TBlockSerial with the following settings:

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.Button1Click(Sender: TObject);
  3. var
  4.   ComDataPacket2: TComDataPacket;
  5. begin
  6.   ComPort2.Port:= 'COM1';
  7.   ComPort2.BaudRate:=br19200;
  8.   ComPort2.FlowControl.ControlDTR:= dtrEnable; //The DMM does NOT send data over RS232 without this line
  9.   Comport2.DataBits:= dbSeven;   //Communication works without it, but is unreadable
  10.   ComPort2.Parity.Bits:= prOdd;  //Communication works without it, but looks odd
  11.  
  12.  
  13.   ComDataPacket2:= TComDataPacket.Create(ComPort2); //The DMM does NOT send data over RS232 without this line
  14.   ComDataPacket2.ComPort:= ComPort2; //The DMM does NOT send data over RS232 without this line
  15.  
  16.  
  17.  //Next values are used by the original DMM software, but they seem to have no effect
  18.   ComPort2.FlowControl.ControlRTS:= rtsDisable; //Default
  19.   ComPort2.FlowControl.XoffChar:='0';
  20.   ComPort2.FlowControl.XonChar:='0';
  21.   ComPort2.FlowControl.FlowControl:=CPort.TFlowControl.fcNone;
  22.   ComPort2.Buffer.InputSize:=2048;
  23.   ComPort2.Buffer.OutputSize:=2048;
  24.   ComPort2.StopBits:= sbOneStopBit;
  25.   ComPort2.Timeouts.ReadInterval:=1;
  26.   ComPort2.Timeouts.ReadTotalConstant:=1;
  27.   ComPort2.Timeouts.WriteTotalConstant:=0;
  28.   ComPort2.Timeouts.WriteTotalMultiplier:=0;
  29.  
  30.  
  31.   Label1.Caption:='';
  32.   ComPort2.Open;end;    



I have also tried TLazSerial, but the DMM sends no data with the following source:
 
Code: Pascal  [Select][+][-]
  1. LazSerial1.Device:= 'COM1';
  2.   LazSerial1.BaudRate:=br_19200;
  3.   LazSerial1.FlowControl:= fcXonXoff;
  4.   LazSerial1.DataBits:=db7bits;
  5.   LazSerial1.Parity:=pOdd;
  6.   LazSerial1.Open;
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: MarkMLl on August 26, 2022, 10:29:52 am
I am trying to connect a multimeter (GDM-461) to the PC.
...
I have also tried TLazSerial, but the DMM sends no data with the following source:

I usually use the standard serial unit for that sort of thing, with a background thread if necessary.

https://github.com/MarkMLl/Mastech_ms2115b

It's years since I did any maintenance on that, in part because one of the platforms I used for testing was SPARC SunOS/Solaris which I no longer have running. Somebody recently suggested some Windows-specific changes to it, but in the general case I prefer to make sure that the low-level handle is accessible so that OS-specific stuff can be added at the app level: I've done that in one specific use case where I needed an estimate of how much data Linux had buffered internally.

MarkMLl
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: hansotten on August 26, 2022, 11:44:12 am
I am trying to connect a multimeter (GDM-461) to the PC.
I have also tried TLazSerial, but the DMM sends no data with the following source:
 
Code: Pascal  [Select][+][-]
  1. LazSerial1.Device:= 'COM1';
  2.   LazSerial1.BaudRate:=br_19200;
  3.   LazSerial1.FlowControl:= fcXonXoff;
  4.   LazSerial1.DataBits:=db7bits;
  5.   LazSerial1.Parity:=pOdd;
  6.   LazSerial1.Open;
You do not have all comm settings as the DMM likes it, like DTR setting, lazSerial.SetDTR etc
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 on August 26, 2022, 12:40:46 pm

You do not have all comm settings as the DMM likes it, like DTR setting, lazSerial.SetDTR etc

I have added LazSerial1.SetDTR(True); but still the device sends nothing.
Also, the PC floods the DMM with “IOCTL: IOCTL_SERIAL_GET_COMMSTATUS”.
And I do not know what TComDataPacket does, but without it the magic does not work.

I usually use the standard serial unit for that sort of thing, with a background thread if necessary.https://github.com/MarkMLl/Mastech_ms2115b (https://github.com/MarkMLl/Mastech_ms2115b)
Thanks, I do not know what the “standart serial unit” is, I will check your code.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: MarkMLl on August 26, 2022, 12:59:28 pm
Thanks, I do not know what the “standart serial unit” is, I will check your code.[/size][/font]

It is the serial unit which is supplied, as standard, with FPC.

Tested and used regularly with Linux, tested with Windows in the W2K era, tested with Solaris/SunOS on SPARC, not tested on Macs.

The protocol of your meter appears to be well understood, https://sigrok.org/wiki/GW_Instek_GDM-397 which is a close relation, I'd expect there to be plenty of projects on Github etc. that interface with it so the use case for FPC/Lazarus is if you have specific output format requirements or want to "pretty it up".

MarkMLl
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on August 26, 2022, 02:42:39 pm
Hello,
I have also tried TLazSerial, but the DMM sends no data with the following source:
  [/size]
Code: Pascal  [Select][+][-]
  1. LazSerial1.Device:= 'COM1';
  2.   LazSerial1.BaudRate:=br_19200;
  3.   LazSerial1.FlowControl:= fcXonXoff;
  4.   LazSerial1.DataBits:=db7bits;
  5.   LazSerial1.Parity:=pOdd;
  6.   LazSerial1.Open;
why LazSerial1.FlowControl:= fcXonXoff;  ?
with the tcomport component you have Flowcontrol to dtrEnable
try to use fcNone for tlazserial flowcontrol ( fcHardware use the signal RTS/CTS not use in your code).

Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 on September 01, 2022, 01:38:41 pm
Indeed, the working setting for TComPort is:
Code: Pascal  [Select][+][-]
  1. ComPort2.FlowControl.FlowControl:=CPort.TFlowControl.fcNone;
  2. ComPort2.FlowControl.ControlDTR:= dtrEnable;


But even with LazSerial1.FlowControl:= fcNone; I cannot make it with TLazSerial:


Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button3Click(Sender: TObject);
  2. begin
  3.   LazSerial1.Device:= 'COM1';
  4.   LazSerial1.BaudRate:=br_19200;
  5.   LazSerial1.FlowControl:= fcNone;
  6.   LazSerial1.SetDTR(True);
  7.   LazSerial1.DataBits:=db7bits;
  8.   LazSerial1.StopBits:=TStopBits.sbOne;
  9.   LazSerial1.Parity:=pOdd;
  10.   LazSerial1.Open;
  11. end;
  12.  
  13.  
  14. procedure TForm1.LazSerial1RxData(Sender: TObject);
  15. var
  16.   SerData: string='';
  17. begin
  18.   SerData := LazSerial1.ReadData;
  19.   Memo1.Text :=  Memo1.Text + SerData;
  20. end;



It is the serial unit which is supplied, as standard, with FPC.
...The protocol of your meter appears to be well understood, https://sigrok.org/wiki/GW_Instek_GDM-397 (https://sigrok.org/wiki/GW_Instek_GDM-397) which is a close relation, I'd expect there to be plenty of projects on Github etc. that interface with it so the use case for FPC/Lazarus is if you have specific output format requirements or want to "pretty it up".
MarkMLl
Sigrok looks interesting, the protocol is not hard to interprete, anyway.
The FPC serial does not look good but I might try it as a last resort.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: eldonfsr on September 14, 2022, 04:02:40 pm
Hi Can possible on Tlazserial when can not connect to port change to null value or something, not rise exception or a other way to handle the error...

 if FSynSer.Handle=INVALID_HANDLE_VALUE then
    raise Exception.Create('Could not open device '+ FSynSer.Device);

when handle this error, on this line i try but i don't know how i can put a different option..

thanks..
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: mas steindorff on September 14, 2022, 08:52:41 pm
my guess is your looking for an error code on opening the port since your handle will not be affected if an open port goes away.

in synaser (the original code LazSerial is based on) an error code could be accessed as ".LastError".   you can check this code for "sOK" after most port operations to see if things worked (are still working).   
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: eldonfsr on September 15, 2022, 05:42:07 pm
Yes, because that error trigger and my app ask
Code: Pascal  [Select][+][-]
  1.         if (cPort <> '' and serial.Active=false) then begin
  2.           try
  3.             Serial.SynSer.Connect( Serial.Device);
  4.             Serial.Active:=true;
  5.             StatusBar1.panels[0].Text := ' Connected to Port: ' + Serial.Device +' BaudRate:'+ BaudRateToStr(Serial.BaudRate)+' Databits:'+DataBitsToStr(Serial.DataBits)+' StopBits: '+StopBitsToStr(Serial.StopBits)+' Parity :'+ParityToStr(Serial.Parity);
  6.             Serial.WriteData(chr(27));
  7.  
  8.           except
  9.            showmessage('Can not open serial port , Check if connections is ok');
  10.           end;
  11.  
  12.  

two message tgrger with same message....
for that i think if resurn some different not rise on exception could be possible to handle that...
 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: geraldholdsworth on October 02, 2022, 11:46:04 am
Hi all,

I'm just trying to use this package, but I am falling on the first hurdle - installation.

I'm doing this on Lazarus 2.2.0 on macOS Catalina - as I noticed that, as of version 0.6, TLazSerial supports macOS. I've opened the package file, then clicked on Use -> Install. I get prompted to re-compile Lazarus, which I do, and it stops with the error
Code: Pascal  [Select][+][-]
  1. idewindowintf.pas(26,3) Fatal: Cannot find IDEOptionsIntf used by IDEWindowIntf, incompatible ppu=/Applications/Lazarus/components/buildintf/units/x86_64-darwin/ideoptionsintf.ppu, multiple packages: BuildIntf, IDEIntf

Many thanks,

Gerald.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on October 02, 2022, 12:06:55 pm
Hello,
I'm doing this on Lazarus 2.2.0 on macOS Catalina - as I noticed that, as of version 0.6, TLazSerial supports macOS. I've opened the package file, then clicked on Use -> Install. I get prompted to re-compile Lazarus, which I do, and it stops with the error
Code: Pascal  [Select][+][-]
  1. idewindowintf.pas(26,3) Fatal: Cannot find IDEOptionsIntf used by IDEWindowIntf, incompatible ppu=/Applications/Lazarus/components/buildintf/units/x86_64-darwin/ideoptionsintf.ppu, multiple packages: BuildIntf, IDEIntf
Have a look   :o  here :   Compiling aborts with error message "Cannot find IDEOptionsIntf used by IDEWindowIntf (https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39535)

Friendly, J.P   
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: geraldholdsworth on October 02, 2022, 01:37:19 pm
Thank you J.P.

That did the trick. However, it then stopped at another file, then another, and so on. It's currently looking for a macrointf.pas file. I'll attack it again later on, when I have more time and patience.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: geraldholdsworth on October 03, 2022, 05:08:13 pm
Finally got it installed OK. It keep aborting while looking for that macrofint.pas file - I just found an option, on the package dialogue box thingy, to recompile everything. This fixed the issue.

Now to try and use it - already found out how to get a list of available ports, now just need to work out how to send something. Oh, and it works fine on my Mac (at least, it tells me what ports are available) - although I'm not sure it'll work on your Zeddie, J.P. :D
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: geraldholdsworth on October 03, 2022, 11:01:32 pm
I actually found I could use the LazSynaSer unit directly. However, this has a major bug in it which causes the application to hang in macOS. It also does it if you use TLazSerial (as this is just a wrapper). It is caused by the creation of the lock file. It is hard coded to create a directory, then files in that directory, in '/var/lock' but the system disallows the creation of anything in the '/var' directory without admin password. So, in LazSynaSer (the one in the TLazSerial download), I have made the following edits:
Line 128:
Code: Pascal  [Select][+][-]
  1. //LockfileDirectory = '/var/lock'; {HGJ}
(i.e., just comment out the line)
Add at the bottom of that const block (line 172):
Code: Pascal  [Select][+][-]
  1. var LockfileDirectory:String;
Then, what is now line 2224, remove the extra backslash:
Code: Pascal  [Select][+][-]
  1. result := LockfileDirectory + 'LCK..' + s;
and in the cpomComportAccessible function, add after the 'begin':
Code: Pascal  [Select][+][-]
  1. LockfileDirectory:=GetTempDir;
This then ensures that the lock file is created in the temporary files location which doesn't need admin permission to access. I believe that this only affects Linux and macOS.

I haven't used it in anger yet, so it sends data but nothing comes back (as nothing is currently connected). That might happen tomorrow.

Can anyone else confirm that they experience the same issue with macOS?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tetrastes on October 04, 2022, 12:46:10 am
I don't know about macOS, but at Linux there is no much sense to place lock file in directory where system doesn't look for lock files, except if only your program accesses this port. It is simpler to set TBlockSerial.LinuxLock property to false, though at Linux usually there is no problem with /var/lock.

By the way, there is ancient code in function TBlockSerial.cpomComportAccessible, which is still not corrected (from synaser.pas in the last trunk of Synapse):
Code: Pascal  [Select][+][-]
  1.   // Is port owned by orphan? Then it's time for error recovery.
  2.   //FPC forgot to add getsid.. :-(
  3.   {$IFNDEF FPC}
  4.   if {$IFNDEF POSIX}Libc.{$ENDIF}getsid(ReadLockfile) = -1 then
  5.   begin //  Lockfile was left from former desaster
  6.     DeleteFile(Filename); // error recovery
  7.     CreateLockfile(MyPid);
  8.     result := FileExists(Filename);
  9.     exit;
  10.   end;
  11.   {$ENDIF}
FPC has fpGetsid for many years...
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on October 04, 2022, 03:11:36 am
Hello,
I don't know about macOS, but at Linux there is no much sense to place lock file in directory where system doesn't look for lock files, except if only your program accesses this port. It is simpler to set TBlockSerial.LinuxLock property to false, though at Linux usually there is no problem with /var/lock.
in the constructor of TLazserial the LinuxLock property is set to false :
Code: Pascal  [Select][+][-]
  1. constructor TLazSerial.Create(AOwner: TComponent);
  2. begin
  3.   inherited;
  4.   //FHandle:=-1;
  5.   ReadThread:=nil;
  6.   FSynSer:=TBlockSerial.Create;
  7.   FSynSer.LinuxLock:=false;
  8.   FHardflow:=false;
  9.   FSoftflow:=false;
  10.   FFlowControl:=fcNone;
  11.   {$IFDEF LINUX}
  12.   FDevice:='/dev/ttyS0';
  13.   {$ELSE}
  14.   FDevice:='COM1';
  15.   {$ENDIF}
  16.   FRcvLineCRLF := False;;
  17. //  FBaudRate:=br115200;
  18. end;  
     

Friendly, J.P             
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: geraldholdsworth on October 04, 2022, 09:38:31 am
Maybe a better idea is to ditch the lockfile idea for macOS, but put it back for Linux. The latest I've found (from earlier this year) has a fix for Android which does exactly that, so I'll go through and affect a similar fix to this file, but for macOS.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tetrastes on October 04, 2022, 10:01:13 am
in the constructor of TLazserial the LinuxLock property is set to false :
Yes, but
I actually found I could use the LazSynaSer unit directly. However, this has a major bug in it which causes the application to hang in macOS.
In lazsynaser LinuxLock is set to true, as in original synaser.

And then I don't understand this
It also does it if you use TLazSerial (as this is just a wrapper). It is caused by the creation of the lock file.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: geraldholdsworth on October 04, 2022, 10:15:03 am
And then I don't understand this
It also does it if you use TLazSerial (as this is just a wrapper). It is caused by the creation of the lock file.
OK, confused myself now - now not sure why the test program for TLazSerial hangs my machine. By setting the LinuxLock to false, it shouldn't try to create a lockfile, under any OS. I need to play some more.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: geraldholdsworth on October 04, 2022, 10:38:02 am
OK, got it. It appears that the lockfile wasn't causing a hang, but this line (in Connect function):
Code: Pascal  [Select][+][-]
  1. FHandle := THandle(fpOpen(FDevice, SerialFlags));
The red herring here was that the lockfile, likely, got created (certainly did in the temporary location) but was never deleted. Upon the second time of trying to connect, this file already exists so the function exits. It is supposed to raise an error in this case, but this doesn't happen. As I had nothing on my RS232 ports, nothing was found - I'm sure once I connected what I'm intending to control and it didn't work, this might have then clicked.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on October 04, 2022, 12:21:31 pm
hello,
what is the problem ?
I have no problem to use Tlazserial on Mac OS 10.15 Catalina.
In attachment capture of lazserial test application in Action . Two USB serial ports sending to each other GPS frames (crossed cable)
And lazsynaser is only for TLazserial.
Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: geraldholdsworth on October 04, 2022, 01:01:07 pm
Just tried the test application again. Configured to use my USB-Serial adapter (but nothing on the other end), then clicked on Open and....it hangs. Same line in lazsynaser.

My adapter identifies itself as '/dev/tty.usbserial-1410', but I can't see that making a difference.

CoolTerm can connect to this same adapter without issue, so it can't be a permission thing in macOS.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on October 04, 2022, 01:25:32 pm
Are you using the 0.6 version of TLazserial (only available on my repository) ?
Quote
new in v0.6 version (03/2022)
 Fixes for OS-X (thanks to rphoover), SynSer(synaser) properties now persistent, v0.3 of GPS simulator
 On OS-X you must set the property  SynSer/NonBlock to True  in the properties of TLazserial component.
set the NonBlock property to true in the SynSer part of TLazserial component (see attachment)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: geraldholdsworth on October 04, 2022, 02:53:11 pm
Ah...that did it. Thank you.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Noobie on April 25, 2023, 12:19:44 pm
I'm trying to read data from serial port. In every package has '#' as a first mark and '&' as an end mark but after the end mark there is also 16-bit CRC. With Lazserial it is easy to use "RecvTerminated" but how to get CRC in same package?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on April 25, 2023, 12:29:28 pm
Hello,
I'm trying to read data from serial port. In every package has '#' as a first mark and '&' as an end mark but after the end mark there is also 16-bit CRC. With Lazserial it is easy to use "RecvTerminated" but how to get CRC in same package?
Can you show us three data frames (as you received them).
And have you CRLF between data frames ?
Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tetrastes on April 25, 2023, 01:53:06 pm
I'm trying to read data from serial port. In every package has '#' as a first mark and '&' as an end mark but after the end mark there is also 16-bit CRC. With Lazserial it is easy to use "RecvTerminated" but how to get CRC in same package?

Code: Pascal  [Select][+][-]
  1. var
  2.   s: AnsiString;
  3.   CRCHi, CRCLo: byte;
  4. . . .
  5.   s := port.RecvTerminated(100, '&');
  6.   CRCHi := port.RecvByte(10);
  7.   CRCLo := port.RecvByte(10);
  8.   s := s + '&' + chr(CRCHi) + chr(CRCLo);    // If this is really needed

EDIT: Sorry, I forgot that "The resulting string is returned without this termination string!", corrected.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Noobie on April 25, 2023, 05:42:00 pm
Hello,
I'm trying to read data from serial port. In every package has '#' as a first mark and '&' as an end mark but after the end mark there is also 16-bit CRC. With Lazserial it is easy to use "RecvTerminated" but how to get CRC in same package?
Can you show us three data frames (as you received them).
And have you CRLF between data frames ?
Friendly, J.P

Hi J.P

There is no CRLF between frames.
Here is few examples:

#MASTER;WNER;OBC;169;TD;1;4;0;17.8;92;0;&84B6
#MASTER;TBAR;67.5;TD;7;9;N;22.0;15.8;1;&D407
#TBAR,MASTER,55,RECPT;&088B


Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tetrastes on April 25, 2023, 08:55:07 pm
Here is few examples:

#MASTER;WNER;OBC;169;TD;1;4;0;17.8;92;0;&84B6
#MASTER;TBAR;67.5;TD;7;9;N;22.0;15.8;1;&D407
#TBAR,MASTER,55,RECPT;&088B

For me "16-bit CRC" is real 16-bit CRC (2 bytes), but you have 4-byte string. Then
Code: Pascal  [Select][+][-]
  1. s := port.RecvTerminated(100, '&');
  2. s := s + '&' + port.RecvBufferStr(4, 10);
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BosseB on April 25, 2023, 09:50:21 pm
Normally when dealing with CRC16 over ascii transmission data the CRC16 is calculated over the complete telegram including the start and end markers, then the CRC16 is added as ASCII HEX representation, which is 4 characters, by the sender after the end marker.
.
The receiving end must localize the start and end of the telegram, then calculate the CRC16 over these bytes and finally compare to the transmitted CRC.
I always convert the received 4-char hex string to a word type variable (or uint16 if you like).
That can then be directly compared to the calculated CRC16 over the received telegram.
If different then discard the telegram.

I have just completed an electricity meter HAN interface app, which will run on an RPiZero W device communicating with the meter using 115200 baud. And I have used the built-in Free-pascal serial unit functionality.
This makes it not depend on the masses of stuff that Synapse brings along and is easily portable to Windows and what have you....
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: mas steindorff on April 25, 2023, 10:42:02 pm
...
There is no CRLF between frames.
Here is few examples:

#MASTER;WNER;OBC;169;TD;1;4;0;17.8;92;0;&84B6
#MASTER;TBAR;67.5;TD;7;9;N;22.0;15.8;1;&D407
#TBAR,MASTER,55,RECPT;&088B
just to clarify...
you have shown each frame on a separate line. so it was all one line and you when in front of each "#" and press enter?
if not, then there was either a CR or LF char that your capture software as "decoded" for you to show 3 lines
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: tetrastes on April 25, 2023, 10:47:50 pm
This makes it not depend on the masses of stuff that Synapse brings along and is easily portable to Windows and what have you....

There is no need in "the masses of stuff" of Synapse for serial communications, synaser and synautil (they use synafpc in addition, but I always comment it out) are enough.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Noobie on April 26, 2023, 08:09:13 am
...
There is no CRLF between frames.
Here is few examples:

#MASTER;WNER;OBC;169;TD;1;4;0;17.8;92;0;&84B6
#MASTER;TBAR;67.5;TD;7;9;N;22.0;15.8;1;&D407
#TBAR,MASTER,55,RECPT;&088B
just to clarify...
you have shown each frame on a separate line. so it was all one line and you when in front of each "#" and press enter?
if not, then there was either a CR or LF char that your capture software as "decoded" for you to show 3 lines

Sorry, my bad. Of course it is like #MASTER;WNER;OBC;169;TD;1;4;0;17.8;92;0;&84B6#MASTER;TBAR;67.5;TD;7;9;N;22.0;15.8;1;&D407#TBAR,MASTER,55,RECPT;&088B  etc.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: mas steindorff on April 26, 2023, 08:15:59 pm
In that case, no terminator (no CR LF ), I would treat the stream as binary using the x.WaitingData along with the x.RecvBuffer(@yourFIFO, x.WaitingData) in a loop / thread to move the stream into local memory.  Then you can check to see if you have a full frame by checking to see if your buffer has a "&" and 4 more bytes.   
This is about what I do but in my case, the number of bytes is a value sent shortly after the header "#" is sent.
Another option is to start a timer each time you receive the "#" that should be adequate to receive the rest of the frame but only if yours is a slow device that has large time gaps between frames (like 500ms). 
Mas
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on April 27, 2023, 07:05:04 am
Hello,
Sorry, my bad. Of course it is like #MASTER;WNER;OBC;169;TD;1;4;0;17.8;92;0;&84B6#MASTER;TBAR;67.5;TD;7;9;N;22.0;15.8;1;&D407#TBAR,MASTER,55,RECPT;&088B  etc.
You can try this:
I have modified the example project sertest of my component LazSerial :
1 - To calculate CRC16 XModem (it seems that it is the type of CRC of your frames) :
Code: Pascal  [Select][+][-]
  1. function CRC16(Buffer: String): string;  // CRC16 XMODEM
  2. const
  3.   Initial = $0000;
  4.   Polynom = $1021;   // 0001 0000 0010 0001  (0, 5, 12)
  5. var
  6.   i,j: Integer;
  7.   crc: Cardinal;
  8. begin
  9. crc:=Initial;
  10. for i:=1 to Length(Buffer) do begin
  11.   crc:=crc xor (ord(buffer[i]) shl 8);
  12.   for j:=0 to 7 do begin
  13.     if (crc and $8000)<>0 then crc:=(crc shl 1) xor Polynom
  14.     else crc:=crc shl 1;
  15.     end;
  16.   end;
  17. crc :=crc and $ffff;
  18.   CRC16 := IntToHex(crc ,4);
  19. end;    
         
2 - Simulate your frames :
Code: Pascal  [Select][+][-]
  1. procedure TFMain.Timer2Timer(Sender: TObject);
  2. const  StaticInc: Integer = 0;
  3.           Frame : Array[0..2] of string = ('MASTER;WNER;OBC;169;TD;1;4;0;17.8;92;0;',
  4.                                    'MASTER;TBAR;67.5;TD;7;9;N;22.0;15.8;1;',
  5.                                    'TBAR,MASTER,55,RECPT;');
  6. var
  7.   Str: String;
  8. begin
  9.    Str := Frame[StaticInc Mod 3];
  10.    Str := '#' + Str + '&' + CRC16(Str) ;
  11.    Serial.WriteData(Str);
  12.    inc(StaticInc);
  13. end;      
3 - Receive your frames and extract data and crc :
Code: Pascal  [Select][+][-]
  1. procedure TFMain.SerialRxData(Sender: TObject);
  2. var Str : string;
  3. var calcCRC : string;
  4. var data : string; // frame without # & and crc
  5. var crc : string;  // crc received
  6. begin
  7.   try  // adjust timeout if necessary
  8.     Str :=  Serial.SynSer.RecvTerminated(100,'&'); // Synchronize with &
  9.     crc :=  Serial.SynSer.RecvBufferStr(4,100); // crc = 4 chars after &
  10.   except
  11.     exit;  // if timeOut exit  (wait for frames)
  12.   end;
  13.   if pos('#',Str) = 0 then Exit; // if frame not whole exit  (frame lost)
  14.   data := Copy(Str,2,length(Str) -1);  // remove #
  15.   calcCRC := CRC16(data); // calculate CRC
  16.   Memo.Lines.BeginUpdate;
  17.   Memo.Lines.Add('data: ' + data + ' -> ' + crc + ' - CalcCRC: ' + calcCRC  );
  18.   Memo.Lines.EndUpdate;
  19.   Memo.SelStart := Length(Memo.Lines.Text)-1;
  20.   Memo.SelLength:=0;
  21. end;          
           

Seems to be OK with a 2 seconds frame frequency. I don't know if it is working with continuous frames.
Friendly, J.P
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Noobie on April 28, 2023, 02:57:08 pm
Hello,
Sorry, my bad. Of course it is like #MASTER;WNER;OBC;169;TD;1;4;0;17.8;92;0;&84B6#MASTER;TBAR;67.5;TD;7;9;N;22.0;15.8;1;&D407#TBAR,MASTER,55,RECPT;&088B  etc.
You can try this:
Thank you J.P! Works well.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi on August 08, 2023, 08:40:04 am
Hi - I'm afraid that I'm back with an old problem.  I need to use two tLazSerial components in one program. 

One speaks to an Arduino Mega on COM4 at 115200 Baud.  The Arduino replies with the output from a laser.  A question to the Arduino might be: @E121!    The response would be 112 numbers and letters in a fromatted string.

The other tLazSerial communicates with a USB RS485 converter that connects to Alicat mass flow controllers.  It runs at 9600 Baud on COM6.  A question sent to this might be 'A'+#13.  It will reply with a string of numbers and a gas identifier.

All other comms parameters are as usual - 8 databits, no parity, 1 stop bit etc.

The problem is that I cannot use both serial components; only one will work at a time and they will quickly lock up if I try to run both.

Here is my test code with one serial stream commented out and the tLazSerial component deleted.  The timer is set to tick every 2 seconds.

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, ExtCtrls,
  9.   LazSerial;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     LazSerial2: TLazSerial;
  17.     Memo1: TMemo;
  18.     Timer1: TTimer;
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure Timer1Timer(Sender: TObject);
  21.   private
  22.  
  23.   public
  24.  
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. { TForm1 }
  35.  
  36. procedure TForm1.FormCreate(Sender: TObject);
  37. begin
  38.  // lazSerial1.Open;
  39. //  lazSerial1.Active:= true ;
  40.   lazSerial2.Open;
  41.   lazSerial2.Active:= true ;
  42. end;
  43.  
  44. procedure TForm1.Timer1Timer(Sender: TObject);
  45. begin
  46. //  lazSerial1.WriteData('@E121!');
  47.  
  48. //  while lazSerial1.DataAvailable do
  49. //    memo1.Lines.add  (lazSerial1.ReadData) ;
  50.  
  51.   lazSerial2.WriteData('A' + #13 );
  52.  
  53.   while lazSerial2.DataAvailable do
  54.     memo1.Lines.add  (lazSerial2.ReadData) ;
  55. end;
  56.  
  57. end.            
  58.  
  59.  


In this case on the Alicats are being talked to.  If I replace lazSerial1 and uncomment the code, it stops working. 

I've tried numerous variants, with separate timers for each component and with time gaps between the calls, but the outcome is the same.

Any suggestions would be gratefully received before I resort to running two programs and IPC.

Thanks

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: af0815 on August 08, 2023, 08:57:41 am
I use sometimes more than 2 LazSerial. My way:  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. With this way of working i can use a lot of LazSerials at one time. On slow devices you read sometimes only chunks of data and have to concat the data up to your end of data, by yourself. 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Scalabr on August 08, 2023, 01:42:14 pm
Is there a chance to use TLazSerial and HidApi on the same project?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork on August 08, 2023, 02:15:37 pm
hello,
BeaglePi and af0815 what is your O.S ?
it seems that there is a problem on windows when there are two lazserial components : the received buffer of the second Tlazserial component is wrong -> return byte 00 while waitingData number is good. On linux no problem . I have modified the sertest project to have two lazserial components (see attachment). Send simulator data on first port , receive on second port (with null modem cable between the two ports).
Scalabr -> no idea i don't know HidApi
[EDIT] it's OK now  on windows. error in my baud speed parameter of the second TLazserial component  :-[ 

Friendly, J.P 

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: mas steindorff 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
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork 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
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: mas steindorff 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
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi 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
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: BeaglePi 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
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork 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
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: mig-31 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.




 
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek 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?
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork 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
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Joek 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!
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: CM630 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.
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon 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.

Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: Jurassic Pork 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 (https://github.com/PaulStoffregen/cores/issues/401)

Friendly J.P (not Jean-Pierre)
Title: Re: TLazSerial : serial port component for Lazarus (windows and linux).
Post by: LaurentDelaon 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.
TinyPortal © 2005-2018