Git Product home page Git Product logo

modbusd's Introduction

modbusd

Docker API

Modbus master daemon

  • Support doxygen style comments.
  • ZeroMQ is a high-level message library, you can replace it with your own data bus implementations without losing the core functionalities.

Table of content


Continuous Integration

I do continuous integration and build docker images after git push by self-hosted drone.io server for armhf platform , circleci server for x86 platform and dockerhub service.

CI Server Target Status
Travis API Build Status
CircleCI x86 CircleCI
Drone armhf Build Status

Design

Implemented libmodbus function codes

FC Description #Len API
0x01 read coils 2000 int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest)
0x02 read discrete inputs 2000 int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest)
0x03 read holding registers 125 int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest)
0x04 read input registers 125 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 1968 int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *src)
0x10 write multi registers 125 int modbus_write_registers(modbus_t *ctx, int addr, int nb, const uint16_t *src)

Coil/register number and address table

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

Command mapping table

Command Number Description
FC1 1 modbus fc 1
FC2 2 modbus fc 2
FC3 3 modbus fc 3
FC4 4 modbus fc 4
FC5 5 modbus fc 5
FC6 6 modbus fc 6
FC15 15 modbus fc 15
FC16 16 modbus fc 16
SET_TCP_TIMEOUT 50 set tcp timeout
GET_TCP_TIMEOUT 51 get tcp timeout

Environment variable

  • CONF_MODBUSD: config file path

Configuration File

{
    "syslog": 1,
    "zmq":
    {
        "sub": "ipc:///tmp/to.modbus",
        "pub": "ipc:///tmp/from.modbus"
    },
    "mbtcp":
    {
        "connect_timeout": 200000
    }
}

Modbus TCP command format

Please refer to command definition.

External libraries


Library documentations

Flow Chart

flow


Setup

Setup development dependencies

sudo apt-get update
sudo apt-get install -y git build-essential autoconf libtool pkg-config cmake

Setup OSS libs dependencies

Install libmodbus library (3.1.4)

git clone https://github.com/stephane/libmodbus/
cd libmodbus
./autogen.sh
./configure
make
sudo make install
sudo ldconfig

Install libzmq (3.2.5)

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

Install czmq (high-level C binding for zeromq)

git clone git://github.com/zeromq/czmq.git
cd czmq
./autogen.sh
./configure
make
sudo make install
sudo ldconfig

Build from source code

git clone modbusd
cd modbusd
mkdir build
cd build
cmake ..
make
./modbusd ../modbusd.json # load external configuration file

Test Cases

  • Test holding registers (4x)
    • 4X Table: 60000 Read/Write uint16 value test: FC6, FC3
    • 4X Table: 30000 Read/Write int16 value test: FC6, FC3
    • 4X Table Multiple read/write test: FC16, FC3
    • 4X Table Multiple read/write test: FC16, FC3
  • Test coils (0x)
    • 0X Table Single read/write test:FC5, FC1
    • 0X Table Multiple read/write test: FC15, FC1
  • Test Discrete Input (1x)
    • 1X Table read test: FC2
  • Test Input Registers (3x)
    • 3X Table read test:FC4
  • Test TCP Timeout
    • Set timeout test
    • Get timeout test

ci

Images and testing from the scratch

docker pull edgepro/c-modbus-slave:x86
docker build -t edgepro/modbusd .
docker build -t edgepro/dummy-psmbtcp test/dummy-psmbtcp/.

docker run -itd --name=slave edgepro/c-modbus-slave:x86
docker run -v /tmp:/tmp --link slave -it --name=modbusd edgepro/modbusd
docker run -v /tmp:/tmp -it --link slave edgepro/dummy-psmbtcp

Docker compose

docker-compose up --abort-on-container-exit

Deployment Diagram

uml


Documentations


License

MIT

modbusd's People

Contributors

taka-wang avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.