A modbus simulator written by rust.
This project is derived from https://github.com/hirschenberger/modbus-rs, with the following modifications aimed to provide full-set function simulation of modbus protocol.
- Retrieve common implementation of Server/Client side to form a new modbus_protocol crate.
- Create modbus_client crate which link with modbus_protocol crate.
- Add new modbus_server crate to provide server side implementation.
-
launch modbus server
$ ./modbus_server 127.0.0.1 --port=1234 --unit_id=5 --capacity=64
-
launch modbus client
$ ./modbus_client 127.0.0.1 --port=1234 --read-coils 5 3
You can use --help option for detailed usage and more other command options.
-
The default Modbus TCP port number is 502, but the TCP/IP port numbers below 1024 are special in that normal users are not allowed to run servers on them, so you maybe encounter a permission denied error when you use the default port. --port is provided to enable the modbus server to bind on other port for test without root privilege.
-
Multiple clients can connect to the same server simultaneously.
-
Crate log4rs is used to provide logging function on both server side and client side. Two .yaml files in config_samples folder are example files for log4rs configuration, you can modify them to fulfill your needs.