I'll try to make a summary thread about Modbus on Lazarus/FPC.
Short terms explanation:
Modbus/TCP - Modbus over Ethernet
Modbus/RTU - Modbus over serial connection (RS-485)
Modbus/ASCII - Modbus over serial connection, but the communication is encoded as hexadecimal ASCII text
A simple Modbus network has one master and one or more slaves. The master is the single device sending requests for read or write, and slaves are responding.
These terms/names are replaced by newer terms recently.
Master = Client = Broker
Slave = Server = Device
Back to Lazarus - there are a couple of packages/libraries for Modbus.
Native:delphi-modbus (
https://github.com/coassoftwaresystems/delphi-modbus ) - Modbus/TCP master and slave
PascalSCADA (
https://www.pascalscada.com/ ) - Modbus/TCP master and slave, Modbus/RTU master
pascal-modbus (
https://sourceforge.net/projects/pascal-modbus/ ) - Modbus/TCP master and slave, Modbus/RTU master and slave
mbutils (
https://sourceforge.net/projects/mbutils/ ) - Modbus/TCP master and slave, Modbus/RTU master
lazarus-modbus ( https://github.com/BobanSpasic/lazarus-modbus ) - Modbus/TCP master and slaveNon-native:SnapModbus (
https://snapmodbus.sourceforge.io ) - Modbus/TCP master and slave, Modbus/RTU master and slave
Lazarus extended demos for SnapModbus - https://github.com/BobanSpasic/lazarus-SnapModbus-demosSupport files:untCOMPortList (
https://github.com/BobanSpasic/lazarus-SnapModbus-demos/blob/main/untCOMPortList.pas ) - cross-platform (tested on Windows and Linux) unit for listing available COM Ports. Based on code from Synapse and from this forum post:
https://forum.lazarus.freepascal.org/index.php/topic,63256.0.htmlPros & Cons:delphi-modbus - primarily developed for Delphi and there are some minor installation problems with Lazarus 4.0 on Linux. Based on Indy components. Just one example for usage in Lazarus
PascalSCADA - very good if you are working with known register addresses. Very good support and developed for Lazarus primarily. Not easy to implement a monitor/sniffer
pascal-modbus - based on synapse. Abandoned project but still usable. Complicated usage (confusing function/procedure names and some low-level settings for communication are left to user to calculate and set up)
mbutils - latest snapshot (tested on 15.06.2025) does not compile. The fixes are relatively easy (some variables are declared twice - change the name of one variable). The example from the readme file seems to be too old - it does not match the current object structures.
SnapModbus - most complete feature set. Good example/demo projects. No support.
What next:
- I'll try to summarize the forum threads here, containing useful information on Modbus
- I've cleaned delphi-modbus from all the code that is non-relevant for Lazarus, and also fixed the installation on Linux. As Thaddy suggested, this will probably get its own repo on Github under the name lazarus-modbus. I also wrote some pretty usable example projects.- write/collect some examples for mbutils
- I've extended the SnapModbus demos, making them more usable (open/save configurations, hide/show registers for better visibility, Linux builds, better COM-Ports selection...)- convert ModbusEmu from CT to Lazarus, translate from Russian to English, correct English spelling in unit/function/procedure names (Chennel > Channel etc)
Any suggestions?