# 13.2 Modbus Master Modbus communication contains a single Master and may include more than 1, but not more than 247 devices. To gather data from peripheral devices, master device request a cluster of slave devices for data. If any device understand that this message is addressed for it – it replies with data. As no timestamp is sent along with data, having recent data requires frequent polling. WCC Lite can be configured to acquire data periodically in custom-defined intervals. #### Configuring datapoints To use Modbus Master in WCC Lite, it has to be configured via an Excel configuration. This configuration contains two Excel sheets where parameters have to be filled in - Devices and Signals ##### Modbus Master parameters for Devices tab
**Parameter** **Type** **Description** **Required** **Default Value** (when not specified) **Range**
TCPRTU/ASCIIMinMax
name stringUser-friendly name for a device YesYes
description stringDescription of a device NoNo
device\_alias stringAlphanumeric string to identify a device YesYes
enablebooleanEnabling/disabling of a device NoNo101
protocolstringProtocol to be used YesYes Modbus RTU, Modbus TCP
ipstringIP address of TCP slave deviceYes-
portintegerTCP communication port Yes - 502
bind\_addressstringIP address of network adapter used to connect to slave device (Default: ”0.0.0.0”) NoNo0.0.0.0
idintegerModbus Slave IDYesYes
modestringChoosing between RTU (”rtu”), ASCII (”ascii”) and TCP(”tcp”) modes. ASCII is the same as RTU, but with ASCII symbols.NoNoTCP (for TCP) RTU (for Serial) rtu, ascii, tcp
timeout\_msintegerResponse timeout in milliseconds Yes Yes10000
devicestring Communication port (”PORT1”/”PORT2”) - YesPORT1 PORT2
baudrateintegerCommunication speed, baud/s - Yes9600 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200
databitsintegerData bit count for communication - Yes8 6 9
stopbitsintegerStop bit count for communication - Yes1 1 2
paritystring Communication parity option - Yesnone none, even, odd
flowcontrolstring Number of requests, before link is considered lost (device status signals are changed) and reconnect attempt will be issued - Yesnone none
scan\_rate\_msintegerIf 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) YesYes300
retry\_countintegerNumber of requests, before link is considered lost (device status signals are changed) and reconnect attempt will be issued NoNo3
serial\_delayintegerRS485 delay between read and write operations in milliseconds - Yes50
keep\_alive\_timeout integerTime interval for sending a keep alive packet (in milliseconds) NoNo60
modbus\_multi\_write booleanUse 15/16 functions to write 1 register/coil (Default: 0) NoNo001
comm\_restart\_delay integerTime delay between disconnecting from slave device and restarting connection (in milliseconds) (Default: 500) No -500
update booleanEnable to keep updating the tags even if they have the same value. No No 0 0 1
##### Modbus Master parameters for Signals tab
**Parameter** **Type** **Description** **Required** **Default Value** (when not specified) **Range**
TCPRTU/ASCIIMinMax
signal\_name stringUser-friendly signal name YesYes
device\_alias stringAlphanumeric string to identify a device YesYes
signal\_alias stringUnique alphanumeric name of the signal to be Yes used YesYes
enablebooleanEnabling/disabling of an individual signal NoNo101
job\_todo stringRequest 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 YesYes
tag\_job\_todo stringSimilar format to job\_todo field. Address and length must be a subset of job field. Defines the individual tag’s register(s) or coil(s). Can be described in HEX or DEC formats YesYes
number\_type stringType of a number (FLOAT, DOUBLE, DIGITAL, etc.) YesYes
log integerSize of this signal’s log in Event log. NoNo0
pulse\_short\_time\_ms integerTime interval for short output pulse to stay active NoNo0
pulse\_long\_time\_ms integerTime interval for long output pulse to stay active NoNo0
##### Device status signals Modbus Master has an additional signal which can be configured to show communication status. It is used to indicate if the slave device has disconnected from master (WCC Lite). To configure such signal for Modbus protocol, job\_todo and tag\_job\_todo fields with string values are required. For Modbus master required parameters for status signal will be: **signal\_name** **device\_alias, signal\_alias, number\_type, job\_todo** and **tag\_job\_todo**. Job\_todo value must be *device\_status* and for tag\_job\_todo there are 4 variations: communication\_status, device\_running, device\_error, uknown\_error. Each signal has 4 possible values and are based on the same logic. If signal returns value of 0, it means unknown error has appeared, 1 – device or protocol connection is on and working properly, 2 – device is off or protocol is disconnected, 3 – error or service is down. Different device vendors can have different implementations of a Modbus protocol stack. A register table can be a one of the primary differences. WCC Lite Modbus Master transmits the most significant word (byte) first, however, devices from some vendors might require transmitting the least significant word (byte) first. If that is the case, make sure to switch bytes as needed. To find out more about setting a correct number format, one should consult a section [`number_type`](https://wiki.elseta.com/link/859#bkmrk-number_type-field). Modbus job or tag (as a task to be completed) can be built in two different formats - user can select a more convenient way for him: - hexadecimal format with every single byte separated by | symbol. Device address, bytes containing output information and CRC (LRC) bytes should be excluded from the message; - decimal format containing function number, first address and address count, separated by ; symbol. All other information should be excluded from the message; `job_todo` can group several `tag_job_todo`’s. That way one Modbus message can be used to extract several tags. Grouping is accomplished dynamically meaning that if several identical jobs are found, their tags are grouped automatically. #### Debugging a Modbus Master application If configuration for Modbus Master 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 Master command line debugging options `modbus-master ` ``` -h [ –help ] Display help information -V [ –version ] Show version -d Set debugging level -c [ –config ] Config path -r [ –raw ] Show raw telegram data -f [ –frame ] Show frame data -s [ –serial ] Show serial port data –tcp Show tcp packets –ascii Show ASCII messages –rtu Show RTU messages -e [ –redis ] Show redis debug information -R [ –readyfile ] Ready notification file ``` If Modbus Master 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-master process and run modbus-master command with respective flags as shown above.