2016-04-25 16:25:05 +02:00
About mbusd
===========
2021-11-15 11:08:32 +01:00
[![mbusd ](https://github.com/3cky/mbusd/actions/workflows/build.yml/badge.svg )](https://github.com/3cky/mbusd/actions/workflows/build.yml)
2017-12-11 12:10:35 +01:00
2019-05-26 13:45:18 +02:00
**mbusd** is open-source [Modbus TCP to Modbus RTU (RS-232/485) ](https://en.wikipedia.org/wiki/Modbus )
gateway. It presents a network of RTU slaves as single TCP slave.
That is a TCP-Slave (or server) which acts as a RTU-master to get data from Modbus RTU-slave devices.
2016-04-25 16:25:05 +02:00
Features:
---------
* Small footprint - suitable to run on embedded devices and SBCs like Raspberry Pi
* Multi-master - multiple TCP masters can access slave devices in RTU network using same gateway
* Robustness - can retry requests with mismatched response CRC
* Flexible RTU modes - speed/parity/stop-bits/timeouts can be configured for RTU network
* Support for both of automatic and manual (using RTS bit) direction control types for RS-485 transceivers
Supported function codes:
-------------------------
* 01: Read coil status
* 02: Read input status
* 03: Read holding registers
* 04: Read input registers
* 05: Force single coil
* 06: Preset single register
* 07: Read exception status
* 15: Force multiple coils
* 16: Preset multiple registers
Please note all other function codes (including vendor-specific extensions) are supported on a "best-effort" basis and most likely will fail.
2017-12-05 16:10:46 +01:00
Installation instructions:
2016-04-25 16:25:05 +02:00
----------------------------
2017-12-05 16:10:46 +01:00
```
2017-11-22 09:46:28 +01:00
$ git clone https://github.com/3cky/mbusd.git mbusd.git
$ cd mbusd.git
2017-12-05 16:10:46 +01:00
$ mkdir -p build & & cd build
2018-02-20 21:42:19 +01:00
$ cmake -DCMAKE_INSTALL_PREFIX=/usr ..
2017-11-22 09:46:28 +01:00
$ make
2017-12-05 16:10:46 +01:00
$ sudo make install
```
2017-11-22 09:46:28 +01:00
2017-12-01 11:37:30 +01:00
***Compile time options***
2017-12-05 16:10:46 +01:00
can be altered in many ways, e.g. by using the following tools in the `build` dir:
2017-12-01 11:37:30 +01:00
* ccmake - usually in the package cmake-curses-gui
* cmake-gui - usually in the package cmake-qt-gui
2016-04-25 16:25:05 +02:00
Usage:
------
2017-12-05 16:10:46 +01:00
mbusd [-h] [-d] [-L logfile] [-v level] [-c cfgfile] [-p device] [-s speed] [-m mode]
2019-07-16 09:14:37 +02:00
[-t] [-y file] [-Y file] [-A address] [-P port] [-C maxconn] [-N retries]
[-R pause] [-W wait] [-T timeout]
2016-04-25 16:25:05 +02:00
-h Usage help.
-d Instruct mbusd not to fork itself (non-daemonize).
2017-11-29 11:39:40 +01:00
-L logfile
Specifies log file name ('-' for logging to STDOUT only, default is /var/log/mbusd.log).
2016-04-25 16:25:05 +02:00
-v level
Specifies log verbosity level (0 for errors only, 1 for warnings
and 2 for also information messages.) If mbusd was compiled in debug mode,
valid log levels are up to 9, where log levels above 2 forces
logging of information about additional internal events.
2017-11-29 11:39:40 +01:00
-c cfgfile
Read configuration from cfgfile.
2016-04-25 16:25:05 +02:00
-p device
Specifies serial port device name.
-s speed
Specifies serial port speed.
-m mode
Specifies serial port mode (like 8N1).
2017-11-29 11:39:40 +01:00
-t Enable RTS RS-485 data direction control (if not disabled while compile).
-y file
Enable RS-485 direction data direction control by writing '1' to file
for transmitter enable and '0' to file for transmitter disable
-Y file
Enable RS-485 direction data direction control by writing '0' to file
for transmitter enable and '1' to file for transmitter disable
2019-07-16 09:14:37 +02:00
-A address
Specifies TCP address to bind (default 0.0.0.0).
2017-12-05 16:10:46 +01:00
-P port
Specifies TCP port number (default 502).
2016-04-25 16:25:05 +02:00
-C maxconn
Specifies maximum number of simultaneous TCP connections.
-N retries
Specifies maximum number of request retries (0 disables retries).
-R pause
Specifies pause between requests in milliseconds.
-W wait
Specifies response wait time in milliseconds.
-T timeout
Specifies connection timeout value in seconds (0 disables timeout).
2021-07-06 15:37:36 +02:00
-b
Instructs **mbusd** to reply on a broadcast.
2016-04-25 16:25:05 +02:00
Please note running **mbusd** on default Modbus TCP port (502) requires root privileges!
2017-11-29 11:39:40 +01:00
Configuration file:
-------------------
**mbusd** can read the configuration from a file specified by `-c` command line flag.
Please see [example configuration file ](conf/mbusd.conf.example )
for complete list of available configuration options.
2017-11-02 21:28:24 +01:00
systemd:
---------------
2017-11-29 11:39:40 +01:00
**mbusd** has [systemd ](https://wiki.archlinux.org/index.php/systemd ) support.
The build system detects whether the system has systemd after which `sudo make install`
installs the `mbusd@.service` file on systems with systemd active.
2017-11-02 21:28:24 +01:00
The **mbusd** service can be started via:
2017-11-23 11:09:03 +01:00
# systemctl start mbusd@< serial port > .service
2022-02-17 11:12:04 +01:00
where `<serial port>` is escaped serial port device short name (like `ttyUSB0` for `/dev/ttyUSB0` device name or `serial-rs485` for `/dev/serial/rs485` device name).
2017-11-02 21:28:24 +01:00
2017-11-29 11:39:40 +01:00
**mbusd** started by systemd will read its configuration from file named `/etc/mbusd/mbusd-<serial port>.conf` .
This way it's possible to run multiple **mbusd** instances with different configurations.
2017-11-02 21:35:02 +01:00
To see the **mbusd** service status:
2017-11-23 11:09:03 +01:00
# systemctl status mbusd@< serial port > .service
2017-11-02 21:35:02 +01:00
To monitor the **mbusd** service:
2017-11-23 11:09:03 +01:00
# journalctl -u mbusd@< serial port > .service -f -n 10
2017-11-02 21:35:02 +01:00
2017-11-02 21:28:24 +01:00
To start the **mbusd** service on system boot:
2017-11-23 11:09:03 +01:00
# systemctl enable mbusd@< serial port > .service
2017-11-02 21:28:24 +01:00
Please check systemd documentation for other usefull systemd [commands ](https://wiki.archlinux.org/index.php/systemd )
2019-05-26 13:45:18 +02:00
Contributing:
-------------
### Reporting bugs
2016-04-25 16:25:05 +02:00
Please file [issue ](https://github.com/3cky/mbusd/issues ) with attached debug log in verbose (`-v9`) mode, i.e.:
# mbusd -L/tmp/mbusd.log -p /dev/ttyUSB0 -s 9600 -P 502 -d -v9
2017-11-29 11:39:40 +01:00
Unless you were prompted so or there is another pertinent reason (e.g. GitHub fails to accept the bug report),
please do not send bug reports via personal email.
2016-04-25 16:25:05 +02:00
2019-05-26 13:45:18 +02:00
### Workflow for code contributions
2016-04-25 16:25:05 +02:00
1. Fork it and clone forked repository
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Make your changes
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Push to the branch (`git push origin my-new-feature`)
6. Create new Pull Request
2019-05-26 13:45:18 +02:00
### Building and Testing
Dependencies: please see the correct OS-distribution section in the
[.gitlab-ci.yml ](https://github.com/3cky/mbusd/blob/master/.gitlab-ci.yml )
With all dependencies met, one is able to *build and execute tests*
issuing the following *bash* commands:
```
# build
mkdir output.dir/ & & cd $_
cmake ../ & & make
# execute all tests
(cd ../ & & python tests/run_itests.py output.dir/mbusd)
```
2016-04-25 16:25:05 +02:00
Author:
-------
2016-04-25 17:13:13 +02:00
Victor Antonovich (< v.antonovich @ gmail . com > )
2016-04-25 16:25:05 +02:00
2017-12-05 16:10:46 +01:00
Contributors:
-------------
2016-04-25 16:25:05 +02:00
2016-04-25 17:13:13 +02:00
Andrew Denysenko (< nitr0 @ seti . kr . ua > ):
2016-04-25 16:25:05 +02:00
- RTS RS-485 data direction control
- RTU response receiving by length
2017-02-16 23:43:24 +01:00
James Jarvis (< jj @ aprsworld . com > ):
- file based RS-485 data direction control
2017-11-29 11:39:40 +01:00
Luuk Loeffen (< luukloeffen @ hotmail . com > ):
- systemd support
2017-12-05 16:10:46 +01:00
Nick Mayerhofer (< nick.mayerhofer @ enchant . at > ):
- CMake build system
2016-04-25 16:25:05 +02:00
License:
--------
2017-02-16 23:43:24 +01:00
This project is distributed under the BSD license. See the [LICENSE ](LICENSE ) file for the full license text.