# 13.3 Modbus Slave WCC Lite can act as one (or several) of slave devices in a communication line. This can be used to transmit data to SCADA systems or other RTU devices. It can reply to messages from Modbus Master with matching devices and register addresses. #### Configuring datapoints Modbus Slave in WCC Lite has to be configured via Excel. This configuration contains two Excel sheets where parameters have to be filled in - Devices and Signals

If TCP/IP is used as a transmission medium, only devices with IPs predefined in the 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**
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
unknown
enablebooleanEnabling/disabling of a device NoNo101
protocolstringProtocol to be used YesYes Modbus serial Slave, Modbus TCP Slave
hoststringSpace-separated host IP addresses of master deviceYes-
portintegerTCP port to listen for incoming connections Yes -
bind\_addressstringThe IP address of the network adapter used to connect to the slave device (Default: ”0.0.0.0”) NoNo0.0.0.0
keep\_alive\_timeout integerThe minimum time a connection can be idle without being closed in seconds NoNo60
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
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 The communication device’s flow control option. -Nonone none
respond\_delayinteger Time in milliseconds to wait before sending responses. Disabled if the value is set to 0 NoNo0 0 4294967295
##### Modbus Slave parameters for the 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 used YesYes
enablebooleanEnabling/disabling an individual signal NoNo101
number\_type stringType of a number (FLOAT, DOUBLE, DIGITAL, etc.). This defines the size that will be read. YesYes
log integerIf the log parameter is equal to 1, the signal values and attributes will be seen in the events log. NoNo0
slave\_idintegerAddress of a slave deviceYesYes
functionintegerFunction numberYesYes 1, 2, 3, 4
register\_addressintegerRegister addressYesYes
periodic\_update\_msintegerSignal value is published periodically according to the value set.NoNo---
##### Device status signals
Modbus slave has an additional signal which can be configured to show communication status. It indicates if the master device has disconnected from the slave (WCC Lite). To configure such signal for Modbus protocol, tag\_job\_todo field with string value is required. For Modbus slave required parameters for the status, the signal will be: **signal\_name,** **device\_alias, signal\_alias,** and **tag\_job\_todo**. Tag\_job\_todo must be: **communication\_status.** If the signal returns the value of 1 – the device or protocol connection is on and working correctly, if 2 – the device is off or the protocol is disconnected. #### Mapping values to registers Internally stored values aren’t organised in a register-like order, therefore mapping should be done by the user. This mapping includes setting the address of the device WCC Lite is simulating as well as the function number, register number and how many 16-bit registers are used to store a value. These values should be set in `common_address`, `function`, `info_address` and `size` columns respectively in the Excel configuration. To find out how many registers should be used for storing values, and how values can have their values swapped, a user should consult a section `number_type`.

If a Modbus master device requests data from a register that is mapped but doesn’t yet have an initial value, an ILLEGAL DATA ADDRESS error code will be returned. The same error code is returned if the requested size of the value is bigger than defined or if the register is not configured at all.

#### Debugging a Modbus Slave application If the configuration for Modbus Slave is set up, a handler for the protocol will start automatically. If the configuration is missing or contains errors, the protocol will not start. It is done intentionally to decrease unnecessary memory usage. Modbus Slave command line debugging options To run a debug session: - **Step 1**: Service must be stopped by entering the following command into the wcclite: ``` /etc/init.d/modbus-slave stop ``` - **Step 2**: After the service is stopped it must be started with the preferred configuration file (JSON files found in the /etc/ folder) and a debug level 7: ``` modbus-slave -c /etc/modbus-slave/modbus-slave.json -d7 ``` Additional output forming options described in the table below. - **Step 3**: Once the problem is diagnosed normal operations can be resumed with the following command: ``` /etc/init.d/modbus-slave start ``` ``` -h [ –help ] Display help information

-V [ –version ] Show version

-d Set debugging level

-c [ –config ] Config path

-e [ –redis ] Show redis debug information ```

If Modbus Slave does not work properly (e.g. no communication between devices, data is corrupted, etc.), a user can launch a debug session from the command line interface and find out why the 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.