Recent

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

VTwin

  • Hero Member
  • *****
  • Posts: 787
  • Former Turbo Pascal 3 user
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #45 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 
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0 (2.0.7) fixes svn 62148 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.6 (64 bit on VBox)
fpc 3.0.4

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 753
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #46 on: January 29, 2014, 11:33:16 pm »
hello,
look for this patch 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
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Paul Breneman

  • Sr. Member
  • ****
  • Posts: 290
    • Control Pascal
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #47 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.
Regards,
Paul Breneman
www.ControlPascal.com

VTwin

  • Hero Member
  • *****
  • Posts: 787
  • Former Turbo Pascal 3 user
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #48 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
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0 (2.0.7) fixes svn 62148 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.6 (64 bit on VBox)
fpc 3.0.4

VTwin

  • Hero Member
  • *****
  • Posts: 787
  • Former Turbo Pascal 3 user
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #49 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
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0 (2.0.7) fixes svn 62148 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.6 (64 bit on VBox)
fpc 3.0.4

bsg55

  • Newbie
  • Posts: 3
Re: TLazSerial : High CPU?
« Reply #50 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.

JZS

  • Full Member
  • ***
  • Posts: 184
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #51 on: February 13, 2014, 09:35:11 am »
Thank you J.P for this component.
I use recent stable release

Motherjoker

  • New member
  • *
  • Posts: 6
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #52 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

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #53 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.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Motherjoker

  • New member
  • *
  • Posts: 6
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #54 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?

Motherjoker

  • New member
  • *
  • Posts: 6
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #55 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! :)
« Last Edit: February 21, 2014, 06:32:55 pm by Motherjoker »

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #56 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.

Motherjoker

  • New member
  • *
  • Posts: 6
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #57 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?

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #58 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}

Motherjoker

  • New member
  • *
  • Posts: 6
Re: TLazSerial : serial port component for Lazarus (windows and linux).
« Reply #59 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!
« Last Edit: February 21, 2014, 06:34:27 pm by Motherjoker »