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 v0.1           EDIT  (january 2017) :   new version v0.2 in Github   here (https://github.com/JurassicPork/TLazSerial)
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!