# 13 Modbus # 13.1 Introduction Modbus is a serial communications protocol for use with its programmable logic controllers (PLCs). Modbus has become a de facto standard communication protocol and is now a commonly available means of connecting industrial electronic devices. It was developed for industrial applications, is relatively easy to deploy and maintain compared to other standards, and places few restrictions other than size on the format of the data to be transmitted. Modbus enables communication among many devices connected to the same network, for example, a system that measures temperature and humidity and communicates the results to a computer. Modbus is often used to connect a supervisory computer with a remote terminal unit (RTU) in supervisory control and data acquisition (SCADA) systems. Many of the data types are named from industry usage of Ladder logic and its use in driving relays: a single-bit physical output is called a coil, and a single-bit physical input is called a discrete input or a contact.
**Parameter** | **Type** | **Description** | **Required** | **Default Value** (when not specified) | **Range** | |
Min | Max | |||||
name | string | User-friendly name for a device | Yes | |||
description | string | Description of a device | No | |||
device\_alias | string | Alphanumeric string to identify a device | Yes | |||
enable | boolean | Enabling/disabling of a device | No | 1 | 0 | 1 |
protocol | string | Protocol to be used | Yes | Modbus RTU, Modbus TCP | ||
ip | string | IP address of TCP slave device | Yes (for TCP). | |||
port | integer | TCP communication port | No (for TCP) | 502 | ||
bind\_address | string | IP address of network adapter used to connect to slave device (Default: ”0.0.0.0”) | No (for TCP) | 0.0.0.0 | ||
id | integer | Modbus Slave ID | Yes | |||
mode | string | Choosing between RTU (”rtu”), ASCII (”ascii”) and TCP(”tcp”) modes. ASCII is the same as RTU, but with ASCII symbols. | No | TCP (for TCP) RTU (for Serial) | rtu, ascii, tcp | |
timeout\_ms | integer | Response timeout in milliseconds | No | 10000 | ||
device | string | Communication port (”PORT1”/”PORT2”) | Yes (for RTU/ASCII) | PORT1 | PORT2 | |
baudrate | integer | Communication speed, baud/s | No (for RTU/ASCII) | 9600 | 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200 | |
databits | integer | Data bit count for communication | No (for RTU/ASCII) | 8 | 6 | 9 |
stopbits | integer | Stop bit count for communication | No (for RTU/ASCII) | 1 | 1 | 2 |
parity | string | Communication parity option | No (for RTU/ASCII) | none | none, even, odd | |
flowcontrol | string | Number of requests, before link is considered lost (device status signals are changed) and reconnect attempt will be issued | No (for RTU/ASCII) | none | none | |
scan\_rate\_ms | integer | If provided and positive - all jobs will have similar scan rate - all reads and writes will be executed within this timeframe (parameter scan\_rate\_ms in Signals tab will be ignored) | No | 300 | ||
retry\_count | integer | Number of requests, before link is considered lost (device status signals are changed) and reconnect attempt will be issued | No | 3 | ||
serial\_delay | integer | RS485 delay between read and write operations in milliseconds | No (for RTU/ASCII) | 50 | ||
keep\_alive\_timeout | integer | Time interval for sending a keep alive packet (in milliseconds) | No (for TCP) | 60 | ||
modbus\_multi\_write | boolean | Use 15/16 functions to write 1 register/coil (Default: 0) | No | 0 | 0 | 1 |
comm\_restart\_delay | integer | Time delay between disconnecting from slave device and restarting connection (in milliseconds) (Default: 500) | No (for TCP) | 500 | ||
update | boolean | Enable to keep updating the tags even if they have the same value. | No | 0 | 0 | 1 |
**Parameter** | **Type** | **Description** | **Required** | **Default Value** (when not specified) | **Range** | |
Min | Max | |||||
signal\_name | string | User-friendly signal name | Yes | |||
device\_alias | string | Alphanumeric string to identify a device | Yes | |||
signal\_alias | string | Unique alphanumeric name of the signal to be Yes used | Yes | |||
enable | boolean | Enabling/disabling of an individual signal | No | 1 | 0 | 1 |
job\_todo | string | Request to send according to modbus specification without device address and checksum. This field can be identical on several tags to fetch them in single request | Yes | |||
tag\_job\_todo | string | Similar format to job\_todo field. Address and length must be a subset of job field. Defines the individual tag’s resgister(s) or coil(s). Can be described in HEX or DEC formats | Yes | |||
number\_type | string | Type of a number (FLOAT, DOUBLE, DIGITAL, etc.) | Yes | |||
log | integer | Size of this signal’s log in Event log. | No | 0 | ||
pulse\_short\_time\_ms | integer | Time interval for short output pulse to stay active | No | |||
pulse\_long\_time\_ms | integer | Time interval for long output pulse to stay active | No |
If TCP/IP is used as a trasmission medium, only devices with IPs predefined in host column are allowed to connect. All other connections are rejected
##### Modbus Slave parameters for Devices tab**Parameter** | **Type** | **Description** | **Required | **Default value** (when not specified) | **Range** | |
Min | Max | |||||
name | string | User-friendly name for a device | Yes | |||
description | string | Description of a device | No | |||
device\_alias | string | Alphanumeric string to identify a device | Yes | |||
enable | boolean | Enabling/disabling of a device | No | 1 | 0 | 1 |
protocol | string | Protocol to be used | Yes | Modbus serial Slave, Modbus TCP Slave | ||
host | string | Space separated host IP addresses of master device | Yes (for TCP). | |||
port | integer | TCP port to listen for incoming connections | Yes (for TCP) | |||
bind\_address | string | IP address of network adapter used to connect to slave device (Default: ”0.0.0.0”) | No (for TCP) | 0.0.0.0 | ||
keep\_alive\_timeout | integer | Minimum time a connection can be idle without being closed in miliseconds | No (for TCP) | 60 | ||
mode | string | Choosing between RTU (”rtu”), ASCII (”ascii”) and TCP(”tcp”) modes. ASCII is the same as RTU, but with ASCII symbols. | No | TCP (for TCP) RTU (for Serial) | rtu, ascii, tcp | |
device | string | Communication port (”PORT1”/”PORT2”) | Yes (for serial) | PORT1 | PORT2 | |
baudrate | integer | Communication speed, baud/s | No (for serial) | 9600 | 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200 | |
databits | integer | Data bit count for communication | No (for serial) | 8 | 6 | 9 |
stopbits | integer | Stop bit count for communication | No for serial) | 1 | 1 | 2 |
parity | string | Communication parity option | No (for serial) | none | none, even, odd | |
flowcontrol | string | Communication device’s flow control option. | No (for serial) | none | none |
**Parameter** | **Type** | **Description** | **Required | **Default value** (when not specified) | **Range** | |
Min | Max | |||||
signal\_name | string | User-friendly signal name | Yes | |||
device\_alias | string | Alphanumeric string to identify a device | Yes | |||
signal\_alias | string | Unique alphanumeric name of the signal to be Yes used | Yes | |||
enable | boolean | Enabling/disabling an individual signal | No | 1 | 0 | 1 |
number\_type | string | Type of a number (FLOAT, DOUBLE, DIGITAL, etc.). This defines the size that will be read. | Yes | |||
log | integer | Size of this signal’s log in the Event log. | No | 0 | ||
slave\_id | integer | Address of a slave device | Yes | |||
function | integer | Function number | Yes | |||
register\_address | integer | Register address | Yes |
If a Modbus master device requests a data from a register that is mapped but doesn’t yet have initial value, ILLEGAL DATA ADDRESS error code will be returned. The same error code is returned if a requested size of value is bigger that defined or if register is not configured at all.
#### Debugging a Modbus Slave application If configuration for Modbus Slave is set up, handler for protocol will start automatically. If configuration is missing or contains errors, protocol will not start. It is done intentionally to decrease unnecessary memory usage. Modbus Slave command line debugging options `modbus-slave` ``` -h [ –help ] Display help information -V [ –version ] Show version -dIf Modbus Slave does not work properly (e.g. no communication between devices, data is corrupted, etc.), a user can launch a debug session from command line interface and find out why link is not functioning properly.
To launch a debugging session, a user should stop `modbus-slave` process and run `modbus-slave` command with respective flags as shown above.