Modbus master daemon
- Support doxygen style comments.
- ZMQ is a high-level message library, you can plug in your own socket implemetations without losing the core functionalities.
FC | Description | API |
---|---|---|
0x01 | read coils | int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest) |
0x02 | read discrete input | int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest) |
0x03 | read holding registers | int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest) |
0x04 | read input registers | int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest) |
0x05 | write single coil | int modbus_write_bit(modbus_t *ctx, int addr, int status) |
0x06 | write single register | int modbus_write_register(modbus_t *ctx, int addr, int value) |
0x0F | write multi coils | int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *src) |
0x10 | write multi registers | int modbus_write_registers(modbus_t *ctx, int addr, int nb, const uint16_t *src) |
Coil/Register numbers | data address | type | table name | offset | function code |
---|---|---|---|---|---|
1-9999 | 0000 to 270E (9998) | Read-Write | Discrete Output Coils | 1 | 1, 5, 15 |
10001-19999 | 0000 to 270E (9998) | Read-Only | Discrete Input Contacts | 10001 | 2 |
30001-39999 | 0000 to 270E (9998) | Read-Only | Analog Input Registers | 30001 | 4 |
40001-49999 | 0000 to 270E (9998) | Read-Write | Analog Output Holding Registers | 40001 | 3, 6, 16 |
{
"syslog": 1,
"ipc_sub": "ipc:///tmp/to.modbus",
"ipc_pub": "ipc:///tmp/from.modbus",
"mbtcp_connect_timeout": 200000
}
{
"ip": "192.168.3.2",
"port": "502",
"slave": 22,
"tid": 1,
"cmd": "fc1",
"addr": 250,
"len": 10
}
{
"tid": 1,
"data": [1,2,3,4],
"status": "ok"
}
{
"ip": "192.168.3.2",
"port": "502",
"slave": 22,
"tid": 1,
"cmd": "fc5",
"addr": 80,
"len": 4,
"data": [1,2,3,4]
}
{
"tid": 1,
"status": "ok"
}
{
"tid": 1,
"cmd": "timeout",
"data": 210000
}
{
"tid": 1,
"status": "ok"
}
Step by step from scratch or (Travis CI + Docker)
sudo apt-get update
sudo apt-get install -y git build-essential autoconf libtool pkg-config cmake
git clone https://github.com/stephane/libmodbus/
cd libmodbus
./autogen.sh
./configure
make
sudo make install
sudo ldconfig
wget https://github.com/zeromq/zeromq3-x/releases/download/v3.2.5/zeromq-3.2.5.tar.gz
tar xvzf zeromq-3.2.5.tar.gz
cd zeromq-3.2.5
./configure
make
sudo make install
sudo ldconfig
git clone git://github.com/zeromq/czmq.git
cd czmq
./autogen.sh
./configure
make
sudo make install
sudo ldconfig
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm install -g zmq
git clone modbusd
cd modbusd
mkdir build
cd build
cmake ..
make
./modbusd ../modbusd.json # load external configuration file
We do continuous integration and update docker images after git push by Travis CI.
You can download pre-built docker images according to the following commands.
- docker pull takawang/modbus-server
- docker pull takawang/modbus-zclient
- docker pull takawang/modbusd
# build simulation server image
docker build -t takawang/modbus-server tests/mbserver/.
# build zclient image
docker build -t takawang/modbus-zclient tests/zclient/.
# build modbusd image
docker build -t takawang/modbusd .
# run modbus server
docker run -itd --name=slave takawang/modbus-server
# run modbusd
docker run -v /tmp:/tmp --link slave -it --name=modbusd takawang/modbusd
# run zclient
docker run -v /tmp:/tmp -it --link slave takawang/modbus-zclient
# build & run
docker-compose up
# exit test
ctrl+c
You can download pre-built docker images according to the following commands.
- docker pull takawang/arm-modbus-server
- docker pull takawang/arm-modbus-zclient
- docker pull takawang/arm-modbusd
# build simulation server image
docker build -t takawang/arm-modbus-server -f tests/mbserver/Dockerfile.arm .
# build zclient image
docker build -t takawang/arm-modbus-zclient tests/zclient/Dockerfile.arm .
# build modbusd image
docker build -t takawang/arm-modbusd -f Dockerfile.arm .
# run modbus server
docker run -itd --name=slave takawang/arm-modbus-server
# run modbusd
docker run -v /tmp:/tmp --link slave -it --name=modbusd takawang/arm-modbusd
# run zclient
docker run -v /tmp:/tmp -it --link slave takawang/arm-modbus-zclient