Forum > Packages and Libraries

TLazSerial (RxData) in Daemon code

(1/1)

dimer:
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!

Jurassic Pork:
hello,
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.

--- Quote ---D:\Dev\Lazarus\Projets\SerialPortDaemon>serialPortdaemon.exe
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
--- End quote ---
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 :

--- Quote ---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
--- End quote ---

Friendly J.P

Navigation

[0] Message Index

Go to full version