Skip to content

Commit ad92721

Browse files
authored
Enhance readme (#22)
* Enhance README * Format table
1 parent 75e916e commit ad92721

File tree

1 file changed

+94
-42
lines changed

1 file changed

+94
-42
lines changed

README.md

Lines changed: 94 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Maintained by: [Michael Oberdorf IT-Consulting](https://www.oberdorf-itc.de/)
44

55
Source code: [GitHub](https://github.com/cybcon/modbus-server)
66

7+
Container image: [DockerHub](https://hub.docker.com/repository/docker/oitc/modbus-server)
8+
79
# Supported tags and respective `Dockerfile` links
810

911
* [`latest`, `1.1.4`](https://github.com/cybcon/modbus-server/blob/v1.1.4/Dockerfile)
@@ -12,9 +14,15 @@ Source code: [GitHub](https://github.com/cybcon/modbus-server)
1214

1315
# What is Modbus TCP Server?
1416

15-
The Modbus TCP Server is a simple, in python written, Modbus TCP server. It listens to port 5020 and respond to any register types with a `0x0000`.
17+
The Modbus TCP Server is a simple, in python written, Modbus TCP server.
1618
The Modbus registers can be also predefined with values.
1719

20+
The Modbus server was initially created to act as a Modbus slave mock system
21+
for enhanced tests with modbus masters and to test collecting values from different registers.
22+
23+
The Modbus specification can be found here: [PDF](https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf)
24+
25+
1826
# QuickStart with Modbus TCP Server and Docker
1927

2028
Step - 1 : Pull the Modbus TCP Server
@@ -34,15 +42,25 @@ Step - 3 : Predefine registers
3442
The default configuration file is configured to initialize every register with a `0x0000`.
3543
To set register values, you need to create your own configuration file.
3644

37-
An example can be found in the GIT repo: [abb_coretec_example.json](./examples/abb_coretec_example.json)
38-
3945
```bash
4046
docker run --rm -p 5020:5020 -v ./server_config.json:/server_config.json oitc/modbus-server:latest -f /server_config.json
4147
```
4248

49+
or you mount the config file over the default file, then you can skip the file parameter:
50+
51+
```bash
52+
docker run --rm -p 5020:5020 -v ./server_config.json:/app/modbus_server.json oitc/modbus-server:latest
53+
```
54+
4355
# Configuration
4456

45-
## Default configuration
57+
## Configuration file
58+
59+
The path and filename to the general configuration file can be set via command option `-f <file>` after mounting it inside of the container. By default, the script will use `/app/modbus_server.json`.
60+
61+
### Default configuration file of the container
62+
63+
The `/app/modbus_server.json` file comes with following content:
4664

4765
```json
4866
{
@@ -71,51 +89,85 @@ docker run --rm -p 5020:5020 -v ./server_config.json:/server_config.json oitc/mo
7189
}
7290
```
7391

74-
## Predefined registers
92+
### Field description
93+
94+
| Field | Type | Description |
95+
|------------------------------------------|---------|-----------------------------------------------------------------------------------------------------------------------|
96+
| `server` | Object | Modbus slave specific runtime parameters. |
97+
| `server.listenerAddress` | String | The IPv4 Address to bound to when starting the server. `"0.0.0.0"` let the server listens on all interface addresses. |
98+
| `server.listenerPort` | Integer | The TCP port number of the modbus slave to listen to. |
99+
| `server.tlsParams` | Object | Configuration parameters to use TLS encrypted modbus tcp slave. (untested) |
100+
| `server.tlsParams.description` | String | No configuration option, just a description of the parameters. |
101+
| `server.tlsParams.privateKey` | String | Filesystem path of the private key to use for a TLS encrypted communication. |
102+
| `server.tlsParams.certificate` | String | Filesystem path of the TLS certificate to use for a TLS encrypted communication. |
103+
| `server.logging` | Object | Log specific configuration. |
104+
| `server.logging.format` | String | The format of the log messages as described here: https://docs.python.org/3/library/logging.html#logrecord-attributes |
105+
| `server.logging.logLevel` | String | Defines the maximum level of severity to log to std out. Possible values are `DEBUG`, `INFO`, `WARN` and `ERROR`. |
106+
| `registers` | Object | Configuration parameters to predefine registers. |
107+
| `registers.description` | String | No configuration option, just a description of the parameters. |
108+
| `registers.zeroMode` | Boolean | By default the modbus registers starts at 1 (`false`) but some implementation requires to start at 0 (`true`). |
109+
| `registers.initializeUndefinedRegisters` | Boolean | If `true` the server will initialize all not defined registers with a default value of `0`. |
110+
| `registers.discreteInput` | Object | The pre-defined registers of the register type "Discrete Input". |
111+
| `registers.coils` | Object | The pre-defined registers of the register type "Coils". |
112+
| `registers.holdingRegister` | Object | The pre-defined registers of the register type "Holding Registers". |
113+
| `registers.inputRegister` | Object | The pre-defined registers of the register type "Input Registers". |
114+
115+
### Pre-define Registers within the configuration file
116+
117+
Pre-define registers always starts with the register number. We use a json format as configuration file, so the "key" needs to be a string. So, the register number needs also to be a string. During server initialization, the json key that represents the register number will be converted to an integer.
118+
119+
As by the modbus spec, the "Discrete Input" and "Coils" registers contains a single bit. In the json configuration file, we use `true` or `false` as register values.
120+
121+
Example configuration of pre-defined registers from type "Discrete Input" or "Coils":
122+
```
123+
[..]
124+
"<register_type>": {
125+
"0": true,
126+
"1": true,
127+
"42": true,
128+
"166": false
129+
}
130+
[..]
131+
```
75132

76-
```json
77-
{
78-
"server": {
79-
"listenerAddress": "0.0.0.0",
80-
"listenerPort": 5020,
81-
"tlsParams": {
82-
"description": "path to certificate and private key to enable tls",
83-
"privateKey": null,
84-
"certificate": null
85-
},
86-
"logging": {
87-
"format": "%(asctime)-15s %(threadName)-15s %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s",
88-
"logLevel": "DEBUG"
89-
}
90-
},
91-
"registers": {
92-
"description": "initial values for the register types",
93-
"zeroMode": false,
94-
"initializeUndefinedRegisters": true,
95-
"discreteInput": {},
96-
"coils": {},
97-
"holdingRegister": {
98-
"123": "0xAABB",
99-
"246": "0x0101"
100-
},
101-
"inputRegister": {}
133+
As by the modbus spec, the "Holding Registers" and "Input Registers" tables contains a 16-bit word. In the json configuration file, we use a hexadecimal notation, starting with `0x`, as register values.
134+
135+
Example configuration of pre-defined registers from type "Holding Registers" or "Input Registers":
136+
```
137+
[..]
138+
"<register_type>": {
139+
"9": "0xAA00",
140+
"23": "0xBB11",
141+
"142": "0x1FC3",
142+
"2346": "0x00FF"
102143
}
103-
}
144+
[..]
104145
```
105146

106-
# Docker compose
107147

148+
## Configuration file examples
149+
150+
- [src/app/modbus_server.json](https://github.com/cybcon/modbus-server/blob/main/src/app/modbus_server.json)
151+
- [examples/abb_coretec_example.json](https://github.com/cybcon/modbus-server/blob/main/examples/abb_coretec_example.json)
152+
- [examples/test.json](https://github.com/cybcon/modbus-server/blob/main/examples/test.json)
153+
154+
155+
156+
# Docker compose configuration
108157

109158
```yaml
110-
modbus-server:
111-
container_name: modbus-server
112-
image: oitc/modbus-server
113-
restart: always
114-
command: -f /server_config.json
115-
ports:
116-
- 5020:5020
117-
volumes:
118-
- ./server.json:/server_config.json:ro
159+
version: '3.8'
160+
161+
services:
162+
modbus-server:
163+
container_name: modbus-server
164+
image: oitc/modbus-server:latest
165+
restart: always
166+
command: -f /server_config.json
167+
ports:
168+
- 5020:5020
169+
volumes:
170+
- ./server.json:/server_config.json:ro
119171
```
120172
121173

0 commit comments

Comments
 (0)