Template:Networking rut manual modbus: Difference between revisions

From Teltonika Networks Wiki
No edit summary
m (Text replacement - "\{\{Template: Networking_rutos_manual_fw_disclosure (.*) (.*) (.*) (.*) \}\}" to "{{Template: Networking_device_manual_fw_disclosure | series = {{{series}}} | name = {{{name}}} | fw_version ={{Template: Networking_device_manual_latest_fw | series = {{{series}}} | name = {{{name}}} }} }}")
Tags: Mobile edit Mobile web edit
 
(68 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{Template: Networking_device_manual_fw_disclosure
| series = {{{series}}}
| name  = {{{name}}}
| fw_version ={{Template: Networking_device_manual_latest_fw
| series = {{{series}}}
| name  = {{{name}}}
}}
}}
==Summary==
==Summary==


'''Modbus''' is a serial communications protocol. Simple and robust, it has since become a de facto standard communication protocol and is now a commonly available means of connecting industrial electronic devices. This chapter is an overview of the Modbus TCP functionality.
<b>Modbus</b> is a serial communications protocol. Simple and robust, it has become a de facto standard communication protocol and is now a commonly available means of connecting industrial electronic devices.
 
This chapter of the user manual provides an overview of the Modbus page for {{{name}}} devices.


==Modbus TCP==
==Modbus TCP==


'''Modbus TCP''' provides users with the possibility to set or get system parameters. The Modbus daemon acts as slave device. That means it accepts connections from a master (client) and sends out a response or sets some system related parameter in accordance with the given query.
<b>Modbus TCP</b> provides users with the possibility to set or get system parameters. The Modbus daemon acts as slave device. That means it accepts connections from a master (client) and sends out a response or sets some system related parameter in accordance with the given query.


The figure below is an example of the Modbus TCP window section and the table below provides information on the fields contained in that window:
The figure below is an example of the Modbus TCP window section and the table below provides information on the fields contained in that window:


[[File:{{{modbus_tcp_file}}}]]
[[File:Networking_rut_manual_modbus_modbus_tcp.png|border|class=tlt-border]]


{{#ifeq: {{{series}}} | RUT2xx
<table class="nd-mantable">
| {{Template: Networking_rut2xx_manual_modbus_modbus_tcp_table|name={{{name}}}}}
    <tr>
| {{Template: Networking_rut9xx_manual_modbus_modbus_tcp_table}}
        <th>Field</th>
}}
      <th>Value</th>
      <th>Description</th>
    </tr>
    <tr>
      <td>Enable</td>
      <td>yes | no; default: <b>none</b></td>
      <td>Turns Modbus TCP on or off.</td>
    </tr>
    <tr>
      <td>Port</td>
      <td>integer [0..65535]; default: '''502'''</td>
      <td>TCP port used for Modbus communications.</td>
    </tr>
    <tr>
      <td>Device ID</td>
      <td>integer [0..255]; default: <b>1</b></td>
      <td>The device's Modbus slave ID. When set to 0, it will respond to requests addressed to any ID.</td>
    </tr>
    <tr>
    <td>Allow Remote Access</td>
        <td>yes | no; default: <b>no</b></td>
        <td>Allows remote Modbus connections by adding an exception to the device's firewall on the port specified in the field above.</td>
    </tr>
    <tr>
    <td>Keep persistent connection</td>
        <td>yes | no; default: <b>no</b></td>
        <td>If enabled, the connection will not be closed after each completed Modbus request.</td>
    </tr>
    <tr>
    <td>Connection timeout</td>
        <td>integer [1..60]; default: <b>0</b></td>
        <td>Timeout in seconds after which the connection will be closed. Use <b>0</b> to use default value provided by Operating System.</td>
    </tr>
    <tr>
    <td>Enable custom register block</td>
        <td>yes | no; default: <b>no</b></td>
        <td>Allow custom register block</td>
    </tr>
</table>


===Get Parameters===
===Get Parameters===
----
----
Modbus parameters are held within '''registers'''. Each register contains 2 bytes of information. For simplification, the number of registers for storing numbers is 2 (4 bytes), while the number of registers for storing text information is 16 (32 bytes). The register numbers and corresponding system values are described in the table below:
Modbus parameters are held within <b>registers</b>. Each register contains 2 bytes of information. For simplification, the number of registers for storing numbers is 2 (4 bytes), while the number of registers for storing text information is 16 (32 bytes). The register numbers and corresponding system values are described in the table below:
<br> <br>
<br> <br>
{{#ifeq: {{{series}}} | RUT2xx
{{#ifeq: {{{series}}} | RUT2XX
| {{Template: Networking_{{lc:{{{series}}}}}_manual_modbus_modbus_tcp_get_parameters_table}}  
| {{Template: Networking_{{lc:{{{series}}}}}_manual_modbus_modbus_tcp_get_parameters_table}}  
| {{Template: Networking_{{lc:{{{name}}}}}_manual_modbus_modbus_tcp_get_parameters_table}}
| {{Template: Networking_{{lc:{{{name}}}}}_manual_modbus_modbus_tcp_get_parameters_table}}
}}
}}
{{#ifeq: {{{series}}} | RUT2xx
{{#ifeq: {{{series}}} | RUT2XX
| {{Template: Networking_device_manual_modbus_modbus_tcp_get_parameters_table_asterisk}}
| {{Template: Networking_device_manual_modbus_modbus_tcp_get_parameters_table_asterisk}}
|
|
Line 31: Line 79:
----
----
The Modbus daemon can also set some device parameters. These parameters and explanations on how to use them are described in the table below:
The Modbus daemon can also set some device parameters. These parameters and explanations on how to use them are described in the table below:
<br> <br>
<br><br>
{{#ifeq: {{{series}}} | RUT2xx
{{#ifeq: {{{series}}} | RUT2XX
| {{Template: Networking_{{lc:{{{series}}}}}_manual_modbus_modbus_tcp_set_parameters_table}}  
| {{Template: Networking_{{lc:{{{series}}}}}_manual_modbus_modbus_tcp_set_parameters_table}}  
| {{Template: Networking_{{lc:{{{name}}}}}_manual_modbus_modbus_tcp_set_parameters_table}}
| {{Template: Networking_{{lc:{{{name}}}}}_manual_modbus_modbus_tcp_set_parameters_table}}
}}
}}


<span class="asterisk">*</span> All ON/OFF commands only accept '''0''' and '''1''' values, which represent the following:
<span class="asterisk">*</span> All ON/OFF commands only accept <b>0</b> and <b>1</b> values, which represent the following:
<ul>
<ul>
     <li>1 - ON</li>
     <li>1 - ON</li>
Line 45: Line 93:
==Modbus TCP Master==
==Modbus TCP Master==


A Modbus <b>master</b> device can request data from Modbus slaves. The Modbus TCP Master section is used to configure Modbus TCP slaves. To add a new slave, enter a custom name, slave's ID, IP address and port and click the "Add" button:
A Modbus <b>master</b> device can request data from Modbus slaves. The Modbus TCP Master section is used to configure Modbus TCP slaves.  
 
You can create a maximum of 10 slave configurations.
[[File:{{{file_add_new_slave}}}]]
 
<ul>
    <li><b>Alarms</b> - Redirects you to the slave's alarm configuration page (more information in [[{{{name}}} Modbus#Alarm_configuration|section 3.3]])</li>
    <li><b>Clone</b> - Creates an identical slave configuration</li>
</ul>
<table class="nd-othertables_2">
    <tr>
        <th width=250>Button</th>
        <th width=902>Description</th>
    </tr>
    <tr>
        <td>Alarms</td>
        <td>Redirects you to the slave's alarm configuration page (more information in [[{{{name}}} Modbus#Alarm_configuration|section 3.3]])</td>
    </tr>
    <tr>
        <td>Clone</td>
        <td>Creates an identical slave configuration</td>
    </tr>
</table>


===Slave device configuration===
===Slave device configuration===
Line 72: Line 100:
The figure below is an example of the <b>Slave device configuration</b> and the table below provides information on the fields contained in that section:
The figure below is an example of the <b>Slave device configuration</b> and the table below provides information on the fields contained in that section:


[[File:{{{file_slave_configuration}}}]]
[[File:Networking_rut_manual_modbus_modbus_tcp_master_slave_device_configuration.png|border|class=tlt-border]]


<table class="nd-mantable">
<table class="nd-mantable">
     <tr>
     <tr>
         <th>Field name</th>
         <th>Field</th>
         <th>Value</th>
         <th>Value</th>
         <th>Description</th>
         <th>Description</th>
Line 82: Line 110:
     <tr>
     <tr>
         <td>Enabled</td>
         <td>Enabled</td>
         <td>yes | no; Default: <b>no</b></td>
         <td>yes | no; default: <b>no</b></td>
         <td>Turns communication with the slave device ON or OFF</td>
         <td>Turns communication with the slave device on or off.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Name</td>
         <td>Name</td>
         <td>string; Default: <b>none</b></td>
         <td>string; default: <b>none</b></td>
         <td>Slave device custom name, used for easier management purposes</td>
         <td>Slave device's name, used for easier management purposes.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Slave ID</td>
         <td>Slave ID</td>
         <td>integer [1..255]; Default: <b>none</b></td>
         <td>integer [0..255]; default: <b>none</b></td>
         <td>Slave ID. Each slave in a network is assigned a unique identifier randging from 1 to 255. When the master requests data from a slave, the first byte it sends is the Slave ID</td>
         <td>Slave ID. Each slave in a network is assigned a unique identifier ranging from 1 to 255. When the master requests data from a slave, the first byte it sends is the Slave ID. When set to 0, the slave will respond to requests addressed to any ID.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>IP address</td>
         <td>IP address</td>
         <td>ip; Default: <b>none</b></td>
         <td>ip; default: <b>none</b></td>
         <td>Slave device IP address</td>
         <td>Slave device's IP address.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Port</td>
         <td>Port</td>
         <td>integer [0..65535]; Default: <b>none</b></td>
         <td>integer [0..65535]; default: <b>none</b></td>
         <td>Slave device Modbus TCP port</td>
         <td>Slave device's Modbus TCP port.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Period</td>
         <td>Period</td>
         <td>integer [1..6400]; Default: <b>none</b></td>
         <td>integer [1..6400]; default: <b>60</b></td>
         <td>Interval at which requests are sent to the slave device</td>
         <td>Interval at which requests are sent to the slave device.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Timeout</td>
         <td>Timeout</td>
         <td>integer [1..30]; Default: <b>none</b></td>
         <td>integer [1..30]; default: <b>5</b></td>
         <td>Maximum response wait time</td>
         <td>Maximum response wait time.</td>
     </tr>
     </tr>
</table>
</table>
Line 119: Line 147:
===Requests configuration===
===Requests configuration===
----
----
A Modbus <b>request</b> is way of obtaining data from Modbus slaves. The master a sends a request to a slave specifying which Modbus registers should be read. The slave then sends the requested data back to the Modbus master.
A Modbus <b>request</b> is a way of obtaining data from Modbus slaves. The master sends a request to a slave specifying the function code to be performed. The slave then sends the requested data back to the Modbus master. You can create a maximum of 64 request configurations for each slave device.


The figure below is an example of the Requests configuration section and the table below provides information contained in the fields of that section:
The figure below is an example of the Requests configuration section and the table below provides information contained in the fields of that section:


[[File:{{{file_requests}}}]]
[[File:Networking_rut_manual_modbus_modbus_tcp_master_request_configuration.png|border|class=tlt-border]]


<table class="nd-mantable">
<table class="nd-mantable">
     <tr>
     <tr>
         <th>Field name</th>
         <th>Field</th>
         <th>Value</th>
         <th>Value</th>
         <th>Description</th>
         <th>Description</th>
Line 133: Line 161:
     <tr>
     <tr>
         <td>Name</td>
         <td>Name</td>
         <td>string; Default: <b>Unnamed Parameter</b></td>
         <td>string; default: <b>Unnamed Parameter</b></td>
         <td>Request name. Used for easier management purposes</td>
         <td>Request name. Used for easier management purposes.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Data type</td>
         <td>Data type</td>
         <td>8bit INT | 8bit UINT | 16bit INT, high byte first | 16bit INT, low byte first | 16bit UINT, high byte first | 16bit UINT, low byte first | 32bit float, Byte order 1,2,3,4 | 32bit float, Byte order 4,3,2,1 | 32bit float, Byte order 2,1,4,3 | 32bit float, Byte order 3,4,1,2; Default: <b>16bit INT, high byte first</b></td>
         <td>Hex | Ascii | 8bit INT | 8bit UINT | 16bit INT, high byte first | 16bit INT, low byte first | 16bit UINT, high byte first | 16bit UINT, low byte first | 32bit float, Byte order 1,2,3,4 | 32bit float, Byte order 4,3,2,1 | 32bit float, Byte order 2,1,4,3 | 32bit float, Byte order 3,4,1,2; default: <b>16bit INT, high byte first</b></td>
         <td>Type of data contained in Modbus registers</td>
         <td>How read data will be stored.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Function</td>
         <td>Function</td>
         <td>1 | 2 | 3 | 4 | 5 | 15 | 16; Default: <b>3</b></td>
         <td>1 | 2 | 3 | 4 | 5 | 6 | 15 | 16; default: <b>3</b></td>
         <td></td>
         <td>A function code specifies the type of register being addressed by a Modbus request. The codes represent these functions:<br>
            <ul>
                <li><b>1</b> - read Coil Status</li>
                <li><b>2</b> - read Input Status</li>
                <li><b>3</b> - read Holding Registers</li>
                <li><b>4</b> - read Input Registers</li>
                <li><b>5</b> - force Single Coil</li>
                <li><b>6</b> - preset Single Register</li>
                <li><b>15</b> - force Multiple Coils</li>
                <li><b>16</b> - force Multiple Registers</li>
            </ul>
        </td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>First Register</td>
         <td>First Register</td>
         <td>integer [0..65535]; Default: <b>1</b></td>
         <td>integer [1..65536]; default: <b>1</b></td>
         <td>First Modbus register from which data will be read</td>
         <td>First Modbus register number from which data will be read.<br>'''Note''' - {{{series}}} Modbus Master uses register numbers, which value is +1 higher than address value.</br></td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Number of Registers</td>
         <td>Number of Registers</td>
         <td>integer [1..2000]; Default: <b>none</b></td>
         <td>integer [1..2000]; default: <b>none</b></td>
         <td>Number of Modbus registers that will be read during the request</td>
         <td>Number of Modbus registers that will be read during the request.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Enabled</td>
         <td>Enabled</td>
         <td>yes | no; Default: <b>no</b></td>
         <td>yes | no; default: <b>no</b></td>
         <td>Turns the request ON or OFF</td>
         <td>Turns the request on or off.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Test</td>
         <td>Test</td>
         <td>- (interactive button)</td>
         <td>- (interactive button)</td>
         <td>Generates a Modbus request according to given parameters in order to test the request configuration. You must first save the configuration before you can use the Test button</td>
         <td>Generates a Modbus request according to given parameters in order to test the request configuration. You must first save the configuration before you can use the Test button.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Delete</td>
         <td>Delete</td>
         <td>- (interactive button)</td>
         <td>- (interactive button)</td>
         <td>Deletes the request</td>
         <td>Deletes the request.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Add</td>
         <td>Add</td>
         <td>- (interactive button)</td>
         <td>- (interactive button)</td>
         <td>Adds a new request request</td>
         <td>Adds a new request configuration.</td>
     </tr>
     </tr>
</table>
</table>
Line 180: Line 219:
===Alarm configuration===
===Alarm configuration===
----
----
<b>Alarms</b> are way of  
<b>Alarms</b> are a way of setting up automated actions when some Modbus values meet user specified conditions. The figure below is an example of the Alarm configuration page and the table below provides information on fields that it contains:


[[File:{{{file_alarms}}}]]
{{#ifeq:{{{series}}}|RUT2XX|[[File:Networking_rut2xx_manual_modbus_modbus_tcp_master_alarm_configuration.png|border|class=tlt-border]]
|[[File:Networking_rut_manual_modbus_modbus_tcp_master_alarm_configuration.png|border|class=tlt-border]]
}}


<table class="nd-mantable">
<table class="nd-mantable">
     <tr>
     <tr>
         <th>Field name</th>
         <th>Field</th>
         <th>Value</th>
         <th>Value</th>
         <th>Description</th>
         <th>Description</th>
Line 192: Line 233:
     <tr>
     <tr>
         <td>Enabled</td>
         <td>Enabled</td>
         <td>yes | no; Default: <b>no</b></td>
         <td>yes | no; default: <b>no</b></td>
         <td>Turns the alarm ON or OFF</td>
         <td>Turns the alarm on or off</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Function code</td>
         <td>Function code</td>
         <td>Read Coil Status (1) | Read Input Status (2) | Read Holding Registers (3) | Read Input Registers (4); Default: <b>Read Coil Status (1)</b></td>
         <td>Read Coil Status (1) | Read Input Status (2) | Read Holding Registers (3) | Read Input Registers (4); default: <b>Read Coil Status (1)</b></td>
         <td></td>
         <td>Modbus function used in Modbus request.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Register</td>
         <td>Register</td>
         <td>integer [0..65535]; Default: <b>none</b></td>
         <td>integer [0..65535]; default: <b>none</b></td>
         <td></td>
         <td>Number of the Modbus coil/input/holding register/input register that will be read.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Condition</td>
         <td>Condition</td>
         <td>More than | Less than | Equal to | Not Equal to; Default: <b>Equal to</b></td>
         <td>More than | Less than | Equal to | Not Equal to; default: <b>Equal to</b></td>
         <td></td>
         <td>When a value is obtained it will be compared against the value specified in the following field. The comparison will be made in accordance with the condition specified in this field.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Value</td>
         <td>Value</td>
         <td>various; Default: <b>none</b></td>
         <td>various; default: <b>none</b></td>
         <td></td>
         <td>The value against which the read data will be compared.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Action</td>
         <td>Action</td>
         <td>SMS | Trigger output | Modbus Request; Default: <b>SMS</b></td>
         <td><span style="color: #f0632c; font-weight:bold;">SMS</span> | <span style="color: red; font-weight:bold;">Trigger output</span> | <span style="color: purple; font-weight:bold;">Modbus Request</span>; default: <b>SMS</b></td>
         <td></td>
         <td>Action that will be taken if the condition is met. Possible actions:
            <ul>
                <li><b>SMS</b> - sends and SMS message to a specified recipient(s).</li>
                <li><b>Trigger output</b> - changes the state of a specified output(s).</li>
                <li><b>Modbus Request</b> - sends a Modbus request to a specified slave.</li>
            </ul>
        </td>
    </tr>
    <tr>
        <td><span style="color: #f0632c;">SMS:</span> Message</td>
        <td>string; default: <b>none</b></td>
        <td>SMS message text.</td>
    </tr>
    <tr>
        <td><span style="color: #f0632c;">SMS:</span> Phone number</td>
        <td>phone number; default: <b>none</b></td>
        <td>Recipient's phone number.</td>
    </tr>
    <tr>
        <td><span style="color: red;">Trigger output:</span> Output</td>{{#ifeq:{{{name}}}|RUT955|
        <td>Open collector output {{!}} Relay output {{!}} Both; default: <b>Open collector output</b></td>|
        <td>4PIN output; default: <b>4PIN output</b></td>}}
        <td>Which output(s) will be triggered.</td>
    </tr>
    <tr>
        <td><span style="color: red;">Trigger output:</span> I/O Action</td>
        <td>Turn On | Turn Off | Invert; default: <b>Turn On</b></td>
        <td>Action that will taken on the specified output.</td>
    </tr>
    <tr>
        <td><span style="color: purple;">Modbus Request:</span> IP address</td>
        <td>ip | host; default: <b>none</b></td>
        <td>Modbus slave's IP address.</td>
    </tr>
    <tr>
        <td><span style="color: purple;">Modbus Request:</span> Port</td>
        <td>integer [0..65535]; default: <b>none</b></td>
        <td>Modbus slave's port.</td>
    </tr>
    <tr>
        <td><span style="color: purple;">Modbus Request:</span> Timeout</td>
        <td>integer [1..30]; default: <b>5</b></td>
        <td>Maximum time to wait for a response.</td>
    </tr>
    <tr>
        <td><span style="color: purple;">Modbus Request:</span> ID</td>
        <td>integer [1..255]; default: <b>none</b></td>
        <td>Modbus slave ID.</td>
    </tr>
    <tr>
        <td><span style="color: purple;">Modbus Request:</span> Modbus function</td>
        <td>Read Coil Status (1) | Read Input Status (2) | Read Holding Registers (3) | Read Input Registers (4) | Force Single Coil (5) | Preset Single Register (6) | Force Multiple Coils (15) | Force Multiple Registers (16); default: <b>Force Single Coil (5)</b></td>
        <td>A function code specifies the type of register being addressed by a Modbus request.</td>
    </tr>
    <tr>
        <td><span style="color: purple;">Modbus Request:</span> First register</td>
        <td>integer [0..65535]; default: <b>none</b></td>
        <td>Begins reading from the register specified in this field.</td>
    </tr>
    <tr>
        <td><span style="color: purple;">Modbus Request:</span> Number of registers</td>
        <td>integer [0..65535]; default: <b>none</b></td>
        <td>The number of registers that will be read from the first register.</td>
    </tr>
</table>
 
{{#ifeq: {{{serial}}} | 1 |
 
==Modbus Serial Master==
 
The <b>Modbus Serial Master</b> page is used to configure the router as a Modbus RTU master. Modbus RTU (remote terminal unit) is a serial communication protocol mainly used in communication via RS232 or RS485 serial interfaces.
 
===RS232===
----
This section is used to configure the Modbus RTU master's RS232 serial interface settings. Refer to the figure and table below for information on RS232 configuration.
 
[[File:Networking_rut_manual_modbus_modbus_serial_master_rs232.png|border|class=tlt-border]]
 
<table class="nd-mantable">
    <tr>
        <th>Field</th>
        <th>Value</th>
        <th>Description</th>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: #0054a6;">SMS: Message</span></td>
         <td>Enabled</td>
         <td>string; Default: <b>none</b></td>
        <td>yes {{!}} no; default: <b>no</b></td>
         <td>SMS message text</td>
        <td>Turns Modbus RTU via RS232 on or off.</td>
    </tr>
    <tr>
        <td>Baud rate</td>
        <td>300 {{!}} 1200 {{!}} 2400 {{!}} 4800 {{!}} 9600 {{!}} 19200 {{!}} 38400 {{!}} 57600 {{!}} 115200; default: <b>115200</b></td>
        <td>Serial data transmission rate (in bits per second).</td>
    </tr>
    <tr>
        <td>Data bits</td>
        <td>5 {{!}} 6 {{!}} 7 {{!}} 8; default: <b>8</b></td>
        <td>Number of data bits for each character.</td>
    </tr>
    <tr>
        <td>Parity</td>
        <td>None {{!}} Even {{!}} Odd; default: <b>Even</b></td>
        <td>In serial transmission, parity is a method of detecting errors. An extra data bit is sent with each data character, arranged so that the number of 1 bits in each character, including the parity bit, is always odd or always even. If a byte is received with the wrong number of 1s, then it must have been corrupted. However, an even number of errors can pass the parity check.
            <ul>
                <li><b>None</b> (<b>N</b>) - no parity method is used.</li>
                <li><b>Odd</b> (<b>O</b>) - the parity bit is set so that the number of "logical ones (1s)" has to be odd.</li>
                <li><b>Even</b> (<b>E</b>) - the parity bit is set so that the number of "logical ones (1s)" has to be even.</li>
            </ul>
        </td>
    </tr>
    <tr>
        <td>Stop bits</td>
        <td>1 {{!}} 2; default: <b>1</b></td>
        <td>Stop bits sent at the end of every character allow the receiving signal hardware to detect the end of a character and to resynchronise with the character stream. Electronic devices usually use one stop bit. Two stop bits are required if slow electromechanical devices are used.</td>
    </tr>
    <tr>
        <td>Flow control</td>
        <td>None {{!}} RTS/CTS {{!}} Xon/Xoff; default: <b>None</b></td>
        <td>In many circumstances a transmitter might be able to send data faster than the receiver is able to process it. To cope with this, serial lines often incorporate a "handshaking" method, usually distinguished between hardware and software handshaking.
            <ul>
                <li><b>RTS/CTS</b> - hardware handshaking. RTS and CTS are turned OFF and ON from alternate ends to control data flow, for instance when a buffer is almost full.</li>
                <li><b>Xon/Xoff</b> - software handshaking. The Xon and Xoff characters are sent by the receiver to the sender to control when the sender will send data, i.e., these characters go in the opposite direction to the data being sent. The circuit starts in the "sending allowed" state. When the receiver's buffers approach capacity, the receiver sends the Xoff character to tell the sender to stop sending data. Later, after the receiver has emptied its buffers, it sends an Xon character to tell the sender to resume transmission.</li>
            </ul>
        </td>
    </tr>
</table>
 
===RS485===
----
This section is used to configure the Modbus RTU master's RS485 serial interface settings. Refer to the figure and table below for information on RS485 configuration.
 
[[File:Networking_rut_manual_modbus_modbus_serial_master_rs485.png|border|class=tlt-border]]
 
<table class="nd-mantable">
    <tr>
        <th>Field</th>
        <th>Value</th>
        <th>Description</th>
    </tr>
    <tr>
        <td>Enabled</td>
        <td>yes {{!}} no; default: <b>no</b></td>
        <td>Turns Modbus RTU via RS485 on or off.</td>
    </tr>
    <tr>
        <td>Baud rate</td>
        <td>300 {{!}} 1200 {{!}} 2400 {{!}} 4800 {{!}} 9600 {{!}} 19200 {{!}} 38400 {{!}} 57600 {{!}} 115200; default: <b>115200</b></td>
        <td>Serial data transmission rate (in bits per second).</td>
    </tr>
    <tr>
        <td>Data bits</td>
        <td>5 {{!}} 6 {{!}} 7 {{!}} 8; default: <b>8</b></td>
        <td>Number of data bits for each character.</td>
    </tr>
    <tr>
        <td>Parity</td>
        <td>None {{!}} Even {{!}} Odd; default: <b>Even</b></td>
        <td>In serial transmission, parity is a method of detecting errors. An extra data bit is sent with each data character, arranged so that the number of 1 bits in each character, including the parity bit, is always odd or always even. If a byte is received with the wrong number of 1s, then it must have been corrupted. However, an even number of errors can pass the parity check.
            <ul>
                <li><b>None</b> (<b>N</b>) - no parity method is used.</li>
                <li><b>Odd</b> (<b>O</b>) - the parity bit is set so that the number of "logical ones (1s)" has to be odd.</li>
                <li><b>Even</b> (<b>E</b>) - the parity bit is set so that the number of "logical ones (1s)" has to be even.</li>
            </ul>
        </td>
    </tr>
    <tr>
        <td>Stop bits</td>
         <td>1 {{!}} 2; default: <b>1</b></td>
         <td>Stop bits sent at the end of every character allow the receiving signal hardware to detect the end of a character and to resynchronise with the character stream. Electronic devices usually use one stop bit. Two stop bits are required if slow electromechanical devices are used.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: #0054a6;">SMS: Phone number</span></td>
         <td>Flow control</td>
         <td>phone number; Default: <b>none</b></td>
        <td>None {{!}} RTS/CTS {{!}} Xon/Xoff; default: <b>None</b></td>
        <td>recipient's phone number</td>
         <td>In many circumstances a transmitter might be able to send data faster than the receiver is able to process it. To cope with this, serial lines often incorporate a "handshaking" method, usually distinguished between hardware and software handshaking.
            <ul>
                <li><b>RTS/CTS</b> - hardware handshaking. RTS and CTS are turned OFF and ON from alternate ends to control data flow, for instance when a buffer is almost full.</li>
                <li><b>Xon/Xoff</b> - software handshaking. The Xon and Xoff characters are sent by the receiver to the sender to control when the sender will send data, i.e., these characters go in the opposite direction to the data being sent. The circuit starts in the "sending allowed" state. When the receiver's buffers approach capacity, the receiver sends the Xoff character to tell the sender to stop sending data. Later, after the receiver has emptied its buffers, it sends an Xon character to tell the sender to resume transmission.</li>
            </ul>
        </td>
     </tr>
     </tr>
</table>
===Slaves===
----
The <b>Slaves</b> section is used to configure new Modbus slave devices. A Modbus slave is an entity that can be called upon by a Modbus master in order to obtain some type of information from it.
To create a new Modbus slave, enter a custom name for it and click the 'Add' button. Then click the 'Edit' button next to the slave in order to enter its configuration window.
====Slave settings====
----
The <b>Settings</b> section is used to configure the main parameters of the Modbus slave. Refer to the figure and table below for additional information.
[[File:Networking_rut_manual_modbus_modbus_serial_master_slave_device_configuration.png|border|class=tlt-border]]
<table class="nd-mantable">
     <tr>
     <tr>
         <td><span style="color: red;">Trigger output: Output</span></td>
         <th>Field</th>
         <td>Open collector output | Relay output | Both; Default: <b>Open collector output</b></td>
         <th>Value</th>
         <td>Which output will be triggered</td>
         <th>Description</th>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: red;">Trigger output: I/O Action</span></td>
         <td>Enabled</td>
         <td>Turn On | Turn Off | Invert; Default: <b>Turn On</b></td>
         <td>yes {{!}} no; default: <b>no</b></td>
         <td>Action that will taken on the specified output</td>
         <td>Turns the slave on or off.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: IP address</span></td>
         <td>Slave ID</td>
         <td>ip | host; Default: <b>none</b></td>
         <td>integer [1..255]; default: <b>1</b></td>
         <td>Modbus slave's address</td>
         <td>Slave ID. Each slave in a network is assigned a unique identifier ranging from 1 to 255. When the master requests data from a slave, the first byte it sends is the Slave ID.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: Port</span></td>
         <td>Frequency settings period</td>
         <td>integer [0..65535]; Default: <b>none</b></td>
        <td>Period {{!}} Schedule; default: <b>Period</b></td>
         <td>Modbus slave's port</td>
        <td>Specifies whether request frequency should happen every x amount of seconds (<i>Period</i>) or on a set schedule (<i>Schedule</i>).</td>
    </tr>
    <tr>
        <td>Period/Schedule</td>
         <td>integer [1..9999]/; default: <b>10</b></td>
         <td>Interval (in minutes) at which requests are sent to the slave device. Or Shedule (crontab-like, three fields (HH MM SS); e.g.. <i>0,12 * *</i>).</td>
     </tr>
     </tr>
</table>
====Slave requests====
----
A Modbus <b>request</b> is a way of obtaining data from Modbus slaves. The master sends a request to a slave specifying the function code to be performed. The slave then sends the requested data back to the Modbus master.
The figure below is an example of the Requests configuration section and the table below provides information contained in the fields of that section:
[[File:Networking_rut_manual_modbus_modbus_serial_master_request_configuration.png|border|class=tlt-border]]
<table class="nd-mantable">
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: Timeout</span></td>
         <th>Field</th>
         <td>integer [1..30]; Default: <b>5</b></td>
         <th>Value</th>
         <td>Maximum time to wait for a response</td>
         <th>Description</th>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: ID</span></td>
         <td>Enabled</td>
         <td>integer [1..255]; Default: <b>none</b></td>
         <td>yes {{!}} no; default: <b>no</b></td>
         <td>Modbus slave ID</td>
         <td>Turns the request on or off.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: Modbus function</span></td>
         <td>Function</td>
         <td>Read Coil Status (1) | Read Input Status (2) | Read Holding Registers (3) | Read Input Registers (4) | Force Single Coil (5) | Preset Single Register (6) | Force Multiple Coils (15) | Force Multiple Registers (16); Default: <b>Force Single Coil (5)</b></td>
         <td>Read Coil {{!}} Read Discrete Input {{!}} Read Holding Registers {{!}} Read Input Registers; default: <b>Read Holding Registers</b></td>
         <td></td>
         <td>Modbus function used in Modbus request.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: First register</span></td>
         <td>First Register</td>
         <td>integer [0..65535]; Default: <b>none</b></td>
         <td>integer [1..65536]; default: <b>1</b></td>
         <td>Begins reading from the register specified in this field</td>
         <td>First Modbus register from which data will be read.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: Number of registers</span></td>
         <td>Number of Registers</td>
         <td>integer [0..65535]; Default: <b>none</b></td>
         <td>integer [1..2000]; default: <b>none</b></td>
         <td></td>
         <td>Number of Modbus registers that will be read during the request/</td>
     </tr>
     </tr>
</table>
</table>


====Slave alarms====
----
<b>Alarms</b> are a way of setting up automated actions when some Modbus values meet user specified conditions. The figure below is an example of the Alarm configuration page and the table below provides information on fields that it contains:
[[File:Networking_rut_manual_modbus_modbus_serial_master_alarm_configuration.png|border|class=tlt-border]]
<table class="nd-mantable">
    <tr>
        <th>Field</th>
        <th>Value</th>
        <th>Description</th>
    </tr>
    <tr>
        <td>Enabled</td>
        <td>yes {{!}} no; default: <b>no</b></td>
        <td>Turns the alarm on or off.</td>
    </tr>
    <tr>
        <td>Function</td>
        <td>Read Coil {{!}} Read Discrete Input {{!}} Read Holding Registers {{!}} Read Input Registers; default: <b>Read Holding Registers</b></td>
        <td>Modbus function used in Modbus request.</td>
    </tr>
    <tr>
        <td>Register</td>
        <td>integer [1..65536]; default: <b>1</b></td>
        <td>Number of the Modbus coil/input/holding register/input register that will be read.</td>
    </tr>
    <tr>
        <td>Condition</td>
        <td>More than {{!}} Less than {{!}} Equal to {{!}} Not equal to; default: <b>More than</b></td>
        <td>When a value is obtained it will be compared against the value specified in the following field. The comparison will be made in accordance with the condition specified in this field.</td>
    </tr>
    <tr>
        <td>Value</td>
        <td>integer [0..65535]; default: <b>0</b></td>
        <td>The value against which the read data will be compared.</td>
    </tr>
    <tr>
        <td>Action</td>
        <td>SMS {{!}} Trigger output {{!}} Modbus request; default: <b>SMS</b></td>
        <td>Action that will be taken if the condition is met. Possible actions:
            <ul>
                <li><b>SMS</b> - sends and SMS message to a specified recipient(s).</li>
                <li><b>Trigger output</b> - changes the state of a specified output(s).</li>
                <li><b>Modbus Request</b> - sends a Modbus request to a specified slave.</li>
            </ul>
        </td>
    </tr>
</table>
|}}
==Modbus Data to Server==
==Modbus Data to Server==


The Modbus <b>Data to Server</b> function provides you with the possibility to set up senders that transfer data collected from Modbus slaves to remote servers. To add a new data sender, enter the server's address, specify the data sending period and click the "Add" button:
The Modbus <b>Data to Server</b> function provides you with the possibility to set up senders that transfer data collected from Modbus slaves to remote servers. To add a new data sender, enter the server's address, specify the data sending period and click the "Add" button:


[[File:{{{file_add_new_sender}}}]]
[[File:Networking_rut_manual_modbus_modbus_data_to_server_new_modbus_data_sender.png]]


===Data sender configuration===
===Data sender configuration===
----
----
When you add a new data sender, you will redirected to its configuration window. The figure below is an example of that window and the table below provides information on the fields that it contains:
When you add a new data sender, you will be redirected to its configuration window.  
The figure below is an example of that window and the table below provides information on the fields that it contains:


[[File:{{{file_sender_configuration}}}]]
[[File:Networking_rut_manual_modbus_modbus_data_to_server_data_sender_configuration.png|border|class=tlt-border]]


<table class="nd-mantable">
<table class="nd-mantable">
     <tr>
     <tr>
         <th>Enabled</th>
         <th>Field</th>
         <th>yes | no; Default: <b>no</b></th>
        <th>Value</th>
         <th>Turns the data sender ON or OFF</th>
         <th>Description</th>
    </tr>
    <tr>
        <td>Enabled</td>
        <td>yes | no; Default: <b>no</b></td>
         <td>Turns the data sender ON or OFF</td>
     </tr>
     </tr>
     <tr>
     <tr>
Line 302: Line 598:
     <tr>
     <tr>
         <td>Protocol</td>
         <td>Protocol</td>
         <td>HTTP(S); Default: <b>HTTP(S)</b></td>
         <td><span style="color:#fb4828; font-weight:bold;">HTTP(S)</span> | <span style="color:#217979; font-weight:bold;">MQTT</span>; Default: <b>HTTP(S)</b></td>
         <td>Data sending protocol</td>
         <td>Data sending protocol</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>JSON format</td>
         <td>JSON format</td>
         <td>string; Default: <b>{"ID":"%i", "TS":"%t","ST":"%s","VR":"%a"}</b></td>
         <td>json string; Default: <b>{"ID":"%i", "TS":"%t","ST":"%s","VR":"%a"}</b></td>
         <td></td>
         <td>Provides the possibility to fully customize the JSON segment</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Segment count</td>
         <td>Segment count</td>
         <td>1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; Default: <b>1</b></td>
         <td>1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | All; Default: <b>1</b></td>
         <td></td>
         <td>Max segment count in one JSON string sent to server.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>URL</td>
         <td>URL / Host /  Connection string</td>
         <td>host | ip; Default: <b>none</b></td>
         <td>host | ip; Default: <b>none</b></td>
         <td>Address of the server to which the data will be sent</td>
         <td>Address of the server to which the data will be sent.<br><b>Important note</b>: when using HTTPS, remember to add the <b><i>https://</i></b> prefix before the URL.</td>
     </tr>
     </tr>
     <tr>
     <tr>
Line 326: Line 622:
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Data filtering</td>
         <td><span style="color:#fb4828;">HTTP(S): </span>Data filtering</td>
         <td>All data | By slave ID | By slave IP; Default: <b>All data</b></td>
         <td>All data | By slave ID | By slave IP; Default: <b>All data</b></td>
         <td></td>
         <td>Which data this sender will transfer to the server</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Retry on fail</td>
         <td><span style="color:#fb4828;">HTTP(S): </span>Retry on fail</td>
         <td>yes | no; Default: <b>no</b></td>
         <td>yes | no; Default: <b>no</b></td>
         <td>Specifies whether the data sender should retry failed attempts</td>
         <td>Specifies whether the data sender should retry failed attempts</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>Custom header</td>
         <td><span style="color:#fb4828;">HTTP(S): </span>Custom header</td>
         <td>string; Default: <b>no</b></td>
         <td>string; Default: <b>no</b></td>
         <td></td>
         <td>Adds a custom header(s) to HTTP requests</td>
    </tr>
    <tr>
        <td><span style="color:#217979;">MQTT: </span>Port</td>
        <td>integer [0..65535]; Default: <b>none</b></td>
        <td>Port used to connect to host.</td>
    </tr>
    <tr>
        <td><span style="color:#217979;">MQTT: </span>Keepalive</td>
        <td>integer [1..640]; Default: <b>none</b></td>
        <td>MQTT keepalive period in seconds.</td>
    </tr>
    <tr>
        <td><span style="color:#217979;">MQTT: </span>Topic</td>
        <td>string; Default: <b>none</b></td>
        <td>Write topic to which your data will be sent.</td>
    </tr>
    <tr>
        <td><span style="color:#217979;">MQTT: </span>QoS</td>
        <td>0 {{!}} 1 {{!}} 2; Default: <b>0</b></td>
        <td>This field defines the guarantee of delivery for specific message.<br>Possible values are:
        <li>At most once (0)</li>
        <li>At least once (1)</li>
        <li>Exactly once (2)</li></td>
    </tr>
    <tr>
        <td><span style="color:#217979;">MQTT: </span>Use TLS</td>
        <td>yes | no; Default: <b>no</b></td>
        <td>Turns TLS authentication on or off.</td>
    </tr>
</table>
 
==MQTT Gateway==
 
The <b>MQTT Gateway</b> function is used to transfer Modbus data (send requests, receive responses) over MQTT. When it is enabled, the device (this {{{name}}}) subscribes to a REQUEST topic and publishes on a RESPONSE topic on a specified MQTT broker. It translates received MQTT message payload to a Modbus request and relays it to the specified Modbus TCP slave.
 
When the MQTT Gateway receives a response from the slave, it translates it to an MQTT message and publishes it on the RESPONSE topic.
 
[[File:Networking_rutos_manual_modbus_mqtt_gateway_scheme.png]]
 
Below is an example of the MQTT Gateway page. Refer to the table for information on MQTT Gateway configuration fields.
 
[[File:Networking_rut_manual_modbus_mqtt_gateway.png|border|class=tlt-border]]
 
<table class="nd-mantable">
    <tr>
        <th>Field</th>
        <th>Value</th>
        <th>Description</th>
    </tr>
    <tr>
        <td>Enable</td>
        <td>off <nowiki>|</nowiki> on; default: <b>off</b></td>
        <td>Turns MQTT gateway on or off.</td>
    </tr>
    <tr>
        <td>Host</td>
        <td>ip <nowiki>|</nowiki> host; default: <b>127.0.0.1</b></td>
        <td>IP address or hostname of an MQTT broker.</td>
    </tr>
    <tr>
        <td>Port</td>
        <td>integer [0..65535]; default: <b>1883</b></td>
        <td>Port number of the MQTT broker.</td>
    </tr>
    <tr>
        <td>Request topic</td>
        <td>string; default: <b>request</b></td>
        <td>MQTT topic for sending requests.</td>
    </tr>
    <tr>
        <td>Response topic</td>
        <td>string; default: <b>response</b></td>
        <td>MQTT topic for subscribing to responses.</td>
    </tr>
    <tr>
        <td>Username</td>
        <td>string; default: <b>none</b></td>
        <td>Username for authentication to the MQTT broker. Leave empty if you do not use client authentication.</td>
    </tr>
    <tr>
        <td>Password</td>
        <td>string; default: <b>none</b></td>
        <td>Password for authentication to the MQTT broker. Leave empty if you do not use client authentication.</td>
     </tr>
     </tr>
</table>
</table>
===Request messages===
----
Modbus request data sent in the MQTT payload should be generated in accordance with the following format:
<b>0 <COOKIE> <IP_TYPE> <IP> <PORT> <TIMEOUT> <SLAVE_ID> <MODBUS_FUNCTION> <REGISTER_NUMBER> <REGISTER_COUNT/VALUE></b>
Explanation:
<ul>
    <li><b>0</b> - must be 0, which signifies a textual format (currently the only one implemented).</li>
    <li><b>Cookie</b> - a 64-bit unsigned integer in range [0..2<sup>64</sup>]). A cookie is used in order to distinguish which response belongs to which request, each request and the corresponding response contain a matching cookie: a 64-bit unsigned integer.</li>
    <li><b>IP type</b> - host IP address type. Possible values:
        <ul>
            <li><b>0</b> - IPv4 address;</li>
            <li><b>1</b> - IPv6 address;</li>
            <li><b>2</b> - hostname that will be resolved to an IP address.</li>
        </ul></li>
    <li><b>IP</b> - IP address of a Modbus TCP slave. IPv6 must be presented in full form (e.g., <i>2001:0db8:0000:0000:0000:8a2e:0370:7334</i>).</li>
    <li><b>Port</b> - port number of the Modbus TCP slave.</li>
    <li><b>Timeout</b> - timeoutfor Modbus TCP connection, in seconds. Range [1..999].</li>
    <li><b>Slave ID</b> - Modbus TCP slave ID. Range [1..255].</li>
    <li><b>Modbus function</b> -  Only these are supported at the moment:
        <ul>
            <li><b>3</b> - read holding registers;</li>
            <li><b>6</b> - write to a single holding register;</li>
            <li><b>16</b> - write to multiple holding registers.</li>
        </ul></li>
    <li><b>Register number</b> - number of the first register (in range [1..65536]) from which the registers will be read/written to.
    <li><b>Register count/value</b> - this value depends on the Modbus function:
        <ul>
            <li><b>3</b> - <u>register count</u> (in range [1..125]); must not exceed the boundary (first register number + register count <= 65537);</li>
            <li><b>6</b> - <u>register value</u> (in range [0..65535]);</li>
            <li><b>16</b> - <u>register count</u> (in range [1..123]); must not exceed the boundary (first register number + register count <= 65537); and <u>register values</u> separated with commas, without spaces (e.g., <i>1,2,3,654,21,789</i>); there must be exactly as many values as specified (with register count); each value must be in the range of [0..65535].</li>
        </ul></li>
</ul>
===Response messages===
----
A special response message can take one of the following forms:
<COOKIE> OK                              - <i>for functions 6 and 16</i>
<COOKIE> OK <VALUE> <VALUE> <VALUE>...  - <i>for function 3, where <VALUE> <VALUE> <VALUE>... are read register values</i>
<COOKIE> ERROR: ...                      - <i>for failures, where ... is the error description</i>
===Examples===
----
Below are a few <b>examples</b> of controlling/monitoring the internal Modbus TCP Slave on {{{name}}}.
----
<b>Reboot the device</b>
<ul>
    <li>Request:<br><pre>0 65432 0 192.168.1.1 502 5 1 6 206 1</pre></li>
    <li>Response:<br><pre>65432 OK</pre></li>
</ul>
----
<b>Retrieve uptime</b>
<ul>
    <li>Request:<br><pre>0 65432 0 192.168.1.1 502 5 1 3 2 2</pre></li>
    <li>Response:<br><pre>65432 OK 0 5590</pre></li>
</ul>
----
If you're using Eclipse Mosquitto (MQTT implementation used on {{{name}}}), Publish/Subscribe commands may look something like this:
<b>Retrieve uptime</b>
<ul>
    <li>Request:<br><pre>mosquitto_pub -h 192.168.1.1 -p 1883 -t request -m "0 65432 0 192.168.1.1 502 5 1 3 2 2"</pre></li>
    <li>Response:<br><pre>mosquitto_sub -h 192.168.1.1 -p 1883 -t response
65432 OK 0 5590</pre></li>
</ul>


==See also==
==See also==


{{Template: Networking_device_modbus_see_also}}
<ul>
    <li><b>[[{{{name}}} Monitoring via Modbus|Monitoring via Modbus]]</b> - detailed examples on how to use Modbus TCP</li>
</ul>


[[Category:{{{name}}} WebUI]]
[[Category:{{{name}}} Services section]]

Latest revision as of 11:09, 24 October 2023

The information in this page is updated in accordance with firmware version .

Summary

Modbus is a serial communications protocol. Simple and robust, it has become a de facto standard communication protocol and is now a commonly available means of connecting industrial electronic devices.

This chapter of the user manual provides an overview of the Modbus page for {{{name}}} devices.

Modbus TCP

Modbus TCP provides users with the possibility to set or get system parameters. The Modbus daemon acts as slave device. That means it accepts connections from a master (client) and sends out a response or sets some system related parameter in accordance with the given query.

The figure below is an example of the Modbus TCP window section and the table below provides information on the fields contained in that window:

Field Value Description
Enable yes | no; default: none Turns Modbus TCP on or off.
Port integer [0..65535]; default: 502 TCP port used for Modbus communications.
Device ID integer [0..255]; default: 1 The device's Modbus slave ID. When set to 0, it will respond to requests addressed to any ID.
Allow Remote Access yes | no; default: no Allows remote Modbus connections by adding an exception to the device's firewall on the port specified in the field above.
Keep persistent connection yes | no; default: no If enabled, the connection will not be closed after each completed Modbus request.
Connection timeout integer [1..60]; default: 0 Timeout in seconds after which the connection will be closed. Use 0 to use default value provided by Operating System.
Enable custom register block yes | no; default: no Allow custom register block

Get Parameters


Modbus parameters are held within registers. Each register contains 2 bytes of information. For simplification, the number of registers for storing numbers is 2 (4 bytes), while the number of registers for storing text information is 16 (32 bytes). The register numbers and corresponding system values are described in the table below:

{{Template: Networking_{{{name}}}_manual_modbus_modbus_tcp_get_parameters_table}}

Set Parameters


The Modbus daemon can also set some device parameters. These parameters and explanations on how to use them are described in the table below:

{{Template: Networking_{{{name}}}_manual_modbus_modbus_tcp_set_parameters_table}}

* All ON/OFF commands only accept 0 and 1 values, which represent the following:

  • 1 - ON
  • 0 - OFF

Modbus TCP Master

A Modbus master device can request data from Modbus slaves. The Modbus TCP Master section is used to configure Modbus TCP slaves. You can create a maximum of 10 slave configurations.

Slave device configuration


The figure below is an example of the Slave device configuration and the table below provides information on the fields contained in that section:

Field Value Description
Enabled yes | no; default: no Turns communication with the slave device on or off.
Name string; default: none Slave device's name, used for easier management purposes.
Slave ID integer [0..255]; default: none Slave ID. Each slave in a network is assigned a unique identifier ranging from 1 to 255. When the master requests data from a slave, the first byte it sends is the Slave ID. When set to 0, the slave will respond to requests addressed to any ID.
IP address ip; default: none Slave device's IP address.
Port integer [0..65535]; default: none Slave device's Modbus TCP port.
Period integer [1..6400]; default: 60 Interval at which requests are sent to the slave device.
Timeout integer [1..30]; default: 5 Maximum response wait time.

Requests configuration


A Modbus request is a way of obtaining data from Modbus slaves. The master sends a request to a slave specifying the function code to be performed. The slave then sends the requested data back to the Modbus master. You can create a maximum of 64 request configurations for each slave device.

The figure below is an example of the Requests configuration section and the table below provides information contained in the fields of that section:

Field Value Description
Name string; default: Unnamed Parameter Request name. Used for easier management purposes.
Data type Hex | Ascii | 8bit INT | 8bit UINT | 16bit INT, high byte first | 16bit INT, low byte first | 16bit UINT, high byte first | 16bit UINT, low byte first | 32bit float, Byte order 1,2,3,4 | 32bit float, Byte order 4,3,2,1 | 32bit float, Byte order 2,1,4,3 | 32bit float, Byte order 3,4,1,2; default: 16bit INT, high byte first How read data will be stored.
Function 1 | 2 | 3 | 4 | 5 | 6 | 15 | 16; default: 3 A function code specifies the type of register being addressed by a Modbus request. The codes represent these functions:
  • 1 - read Coil Status
  • 2 - read Input Status
  • 3 - read Holding Registers
  • 4 - read Input Registers
  • 5 - force Single Coil
  • 6 - preset Single Register
  • 15 - force Multiple Coils
  • 16 - force Multiple Registers
First Register integer [1..65536]; default: 1 First Modbus register number from which data will be read.
Note - {{{series}}} Modbus Master uses register numbers, which value is +1 higher than address value.
Number of Registers integer [1..2000]; default: none Number of Modbus registers that will be read during the request.
Enabled yes | no; default: no Turns the request on or off.
Test - (interactive button) Generates a Modbus request according to given parameters in order to test the request configuration. You must first save the configuration before you can use the Test button.
Delete - (interactive button) Deletes the request.
Add - (interactive button) Adds a new request configuration.

Alarm configuration


Alarms are a way of setting up automated actions when some Modbus values meet user specified conditions. The figure below is an example of the Alarm configuration page and the table below provides information on fields that it contains:

Field Value Description
Enabled yes | no; default: no Turns the alarm on or off
Function code Read Coil Status (1) | Read Input Status (2) | Read Holding Registers (3) | Read Input Registers (4); default: Read Coil Status (1) Modbus function used in Modbus request.
Register integer [0..65535]; default: none Number of the Modbus coil/input/holding register/input register that will be read.
Condition More than | Less than | Equal to | Not Equal to; default: Equal to When a value is obtained it will be compared against the value specified in the following field. The comparison will be made in accordance with the condition specified in this field.
Value various; default: none The value against which the read data will be compared.
Action SMS | Trigger output | Modbus Request; default: SMS Action that will be taken if the condition is met. Possible actions:
  • SMS - sends and SMS message to a specified recipient(s).
  • Trigger output - changes the state of a specified output(s).
  • Modbus Request - sends a Modbus request to a specified slave.
SMS: Message string; default: none SMS message text.
SMS: Phone number phone number; default: none Recipient's phone number.
Trigger output: Output4PIN output; default: 4PIN output Which output(s) will be triggered.
Trigger output: I/O Action Turn On | Turn Off | Invert; default: Turn On Action that will taken on the specified output.
Modbus Request: IP address ip | host; default: none Modbus slave's IP address.
Modbus Request: Port integer [0..65535]; default: none Modbus slave's port.
Modbus Request: Timeout integer [1..30]; default: 5 Maximum time to wait for a response.
Modbus Request: ID integer [1..255]; default: none Modbus slave ID.
Modbus Request: Modbus function Read Coil Status (1) | Read Input Status (2) | Read Holding Registers (3) | Read Input Registers (4) | Force Single Coil (5) | Preset Single Register (6) | Force Multiple Coils (15) | Force Multiple Registers (16); default: Force Single Coil (5) A function code specifies the type of register being addressed by a Modbus request.
Modbus Request: First register integer [0..65535]; default: none Begins reading from the register specified in this field.
Modbus Request: Number of registers integer [0..65535]; default: none The number of registers that will be read from the first register.


Modbus Data to Server

The Modbus Data to Server function provides you with the possibility to set up senders that transfer data collected from Modbus slaves to remote servers. To add a new data sender, enter the server's address, specify the data sending period and click the "Add" button:

Data sender configuration


When you add a new data sender, you will be redirected to its configuration window. The figure below is an example of that window and the table below provides information on the fields that it contains:

Field Value Description
Enabled yes | no; Default: no Turns the data sender ON or OFF
Name string; Default: none Data sender's name. used for easier management purposes
Protocol HTTP(S) | MQTT; Default: HTTP(S) Data sending protocol
JSON format json string; Default: {"ID":"%i", "TS":"%t","ST":"%s","VR":"%a"} Provides the possibility to fully customize the JSON segment
Segment count 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | All; Default: 1 Max segment count in one JSON string sent to server.
URL / Host / Connection string host | ip; Default: none Address of the server to which the data will be sent.
Important note: when using HTTPS, remember to add the https:// prefix before the URL.
Period integer [1..6400]; Default: none Data sending frequency (in seconds)
HTTP(S): Data filtering All data | By slave ID | By slave IP; Default: All data Which data this sender will transfer to the server
HTTP(S): Retry on fail yes | no; Default: no Specifies whether the data sender should retry failed attempts
HTTP(S): Custom header string; Default: no Adds a custom header(s) to HTTP requests
MQTT: Port integer [0..65535]; Default: none Port used to connect to host.
MQTT: Keepalive integer [1..640]; Default: none MQTT keepalive period in seconds.
MQTT: Topic string; Default: none Write topic to which your data will be sent.
MQTT: QoS 0 | 1 | 2; Default: 0 This field defines the guarantee of delivery for specific message.
Possible values are:
  • At most once (0)
  • At least once (1)
  • Exactly once (2)
  • MQTT: Use TLS yes | no; Default: no Turns TLS authentication on or off.

    MQTT Gateway

    The MQTT Gateway function is used to transfer Modbus data (send requests, receive responses) over MQTT. When it is enabled, the device (this {{{name}}}) subscribes to a REQUEST topic and publishes on a RESPONSE topic on a specified MQTT broker. It translates received MQTT message payload to a Modbus request and relays it to the specified Modbus TCP slave.

    When the MQTT Gateway receives a response from the slave, it translates it to an MQTT message and publishes it on the RESPONSE topic.

    Below is an example of the MQTT Gateway page. Refer to the table for information on MQTT Gateway configuration fields.

    Field Value Description
    Enable off | on; default: off Turns MQTT gateway on or off.
    Host ip | host; default: 127.0.0.1 IP address or hostname of an MQTT broker.
    Port integer [0..65535]; default: 1883 Port number of the MQTT broker.
    Request topic string; default: request MQTT topic for sending requests.
    Response topic string; default: response MQTT topic for subscribing to responses.
    Username string; default: none Username for authentication to the MQTT broker. Leave empty if you do not use client authentication.
    Password string; default: none Password for authentication to the MQTT broker. Leave empty if you do not use client authentication.

    Request messages


    Modbus request data sent in the MQTT payload should be generated in accordance with the following format:

    0 <COOKIE> <IP_TYPE> <IP> <PORT> <TIMEOUT> <SLAVE_ID> <MODBUS_FUNCTION> <REGISTER_NUMBER> <REGISTER_COUNT/VALUE>
    

    Explanation:

    • 0 - must be 0, which signifies a textual format (currently the only one implemented).
    • Cookie - a 64-bit unsigned integer in range [0..264]). A cookie is used in order to distinguish which response belongs to which request, each request and the corresponding response contain a matching cookie: a 64-bit unsigned integer.
    • IP type - host IP address type. Possible values:
      • 0 - IPv4 address;
      • 1 - IPv6 address;
      • 2 - hostname that will be resolved to an IP address.
    • IP - IP address of a Modbus TCP slave. IPv6 must be presented in full form (e.g., 2001:0db8:0000:0000:0000:8a2e:0370:7334).
    • Port - port number of the Modbus TCP slave.
    • Timeout - timeoutfor Modbus TCP connection, in seconds. Range [1..999].
    • Slave ID - Modbus TCP slave ID. Range [1..255].
    • Modbus function - Only these are supported at the moment:
      • 3 - read holding registers;
      • 6 - write to a single holding register;
      • 16 - write to multiple holding registers.
    • Register number - number of the first register (in range [1..65536]) from which the registers will be read/written to.
    • Register count/value - this value depends on the Modbus function:
      • 3 - register count (in range [1..125]); must not exceed the boundary (first register number + register count <= 65537);
      • 6 - register value (in range [0..65535]);
      • 16 - register count (in range [1..123]); must not exceed the boundary (first register number + register count <= 65537); and register values separated with commas, without spaces (e.g., 1,2,3,654,21,789); there must be exactly as many values as specified (with register count); each value must be in the range of [0..65535].

    Response messages


    A special response message can take one of the following forms:

    <COOKIE> OK                              - for functions 6 and 16
    <COOKIE> OK <VALUE> <VALUE> <VALUE>...   - for function 3, where <VALUE> <VALUE> <VALUE>... are read register values
    <COOKIE> ERROR: ...                      - for failures, where ... is the error description
    

    Examples


    Below are a few examples of controlling/monitoring the internal Modbus TCP Slave on {{{name}}}.


    Reboot the device

    • Request:
      0 65432 0 192.168.1.1 502 5 1 6 206 1
    • Response:
      65432 OK

    Retrieve uptime

    • Request:
      0 65432 0 192.168.1.1 502 5 1 3 2 2
    • Response:
      65432 OK 0 5590

    If you're using Eclipse Mosquitto (MQTT implementation used on {{{name}}}), Publish/Subscribe commands may look something like this:

    Retrieve uptime

    • Request:
      mosquitto_pub -h 192.168.1.1 -p 1883 -t request -m "0 65432 0 192.168.1.1 502 5 1 3 2 2"
    • Response:
      mosquitto_sub -h 192.168.1.1 -p 1883 -t response
      65432 OK 0 5590


    See also

    • [[{{{name}}} Monitoring via Modbus|Monitoring via Modbus]] - detailed examples on how to use Modbus TCP

    [[Category:{{{name}}} Services section]]