Author Topic: TLazSerial (RxData) in Daemon code  (Read 1459 times)


  • New member
  • *
  • Posts: 5
TLazSerial (RxData) in Daemon code
« on: January 17, 2022, 09:07:23 pm »
Dear all,
I need a help in a realization a simple daemon to serve COM (serial) port on Windows platform.

The task: Computer with Windows have a serial port producing 21-bytes binary data every 16 seconds. This data can be READ in a moment of appearance. COM port doesn't have a WRITE possibility. When I've using TLazSerial component to get a data in a desktop application - everything seems OK (event OnRxData is raising periodically and the procedure in my code can proceed proper binary string/array). But in a daemon code (DaemonApp and so on) it doesn't work. The event OnRxData never raised.

Toolkit: Lazarus IDE 2.2.0, FPC 3.2.2, lazserial 0.5

Would anybody show an example to reach my target? Or maybe there's another free solution to work eventually with COM (serial) port in non-desktop, non-console - especially in daemon application? Thanks in advance!
« Last Edit: January 17, 2022, 09:22:15 pm by dimer »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1111
Re: TLazSerial (RxData) in Daemon code
« Reply #1 on: January 18, 2022, 07:30:56 am »
don't use Tlazserial to do this (only use TLazserial for GUI application). You can use synaser in synapse package.
In attachment a small windows daemon project to listen COM3 serial port for gps information.
Usage: D:\Dev\Lazarus\Projets\SerialPortDaemon\serialPortdaemon.exe [command]
Where command is one of the following:
  -i --install   To install the program as a service
  -u --uninstall To uninstall the service
The incoming data are written in the log file.
You have to change the port settings and the read data procedure because your data are binary.
here is the content of my log file :
serialPortdaemon [2022-01-18 07:16:31.841 Debug] SpDaemonMapper.Created
serialPortdaemon [2022-01-18 07:16:38.127 Debug] SpDaemonMapper.Create
serialPortdaemon [2022-01-18 07:16:38.127 Debug] SpDaemonMapper.Created
serialPortdaemon [2022-01-18 07:16:38.127 Debug] SpDaemonMapper.Install
serialPortdaemon [2022-01-18 07:16:38.158 Debug] Daemon.installed: true
serialPortdaemon [2022-01-18 07:18:46.131 Debug] SpDaemonMapper.Create
serialPortdaemon [2022-01-18 07:18:46.131 Debug] SpDaemonMapper.Created
serialPortdaemon [2022-01-18 07:18:46.131 Debug] SpDaemonMapper.Run
serialPortdaemon [2022-01-18 07:18:46.131 Debug] Daemon.Start: true
serialPortdaemon [2022-01-18 07:18:46.147 Debug] TComPortReadThread.Execute
serialPortdaemon [2022-01-18 07:18:46.147 Debug] Daemon.Execute: false
serialPortdaemon [2022-01-18 07:19:41.326 Debug] $GPRMC,071941,A,4852.443,N,00222.586,E,000.5,054.7,180122,020.3,E*77
serialPortdaemon [2022-01-18 07:19:43.330 Debug] $GPRMC,071943,A,4852.452,N,00222.598,E,000.5,054.7,180122,020.3,E*7A
serialPortdaemon [2022-01-18 07:19:45.317 Debug] $GPRMC,071945,A,4852.461,N,00222.609,E,000.5,054.7,180122,020.3,E*77
serialPortdaemon [2022-01-18 07:19:47.339 Debug] $GPRMC,071947,A,4852.471,N,00222.621,E,000.5,054.7,180122,020.3,E*7E
serialPortdaemon [2022-01-18 07:19:49.340 Debug] $GPRMC,071949,A,4852.480,N,00222.633,E,000.5,054.7,180122,020.3,E*7D
serialPortdaemon [2022-01-18 07:19:51.326 Debug] $GPRMC,071951,A,4852.489,N,00222.645,E,000.5,054.7,180122,020.3,E*7C

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


TinyPortal © 2005-2018