# Modbus

Modbus is one of the most popular serial protocol for industrial systems. It is used for data exchange between sensors, instruments, PLC, HMI and parts of SCADA system. Please refer to [Wikipedia](https://en.wikipedia.org/wiki/Modbus) and [official standard](https://modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf) for technical details.

With advent of IIoT, IoT gateways communicate with various components over Modbus. This documents various topologies of Modbus based systems.

## Modbus Communication Concept

Modbus works on the concept of **Master** and **Slave.** The master sends a **request** to slave and slave **reply** with required information.

{% hint style="info" %}
These words have been [officially](https://modbus.org/docs/Client-ServerPR-07-2020-final.docx.pdf) replaced to **Client** *(Master)* and **Server** *(Slave).* Unfortunately, Master/Slave words still remain popular in industry (at least for Modbus/RS485). In Modbus TCP/IP, Client-Server is more prevalent. For ease of understanding, we use unofficial words in this tutorial.
{% endhint %}

## Modbus Versions

Following are two popular version of Modbus which are supported by YuDash IoT devices.

#### 1) Modbus/RS485 (or Modbus/RTU)

* Refer to [Modbus Settings in LYNX User Manual](https://docs.yudash.com/yudash-iot-devices/lynx-user-manual/lynx-settings/modbus-rs485).&#x20;
* Integration with RS/485 devices in [Industrial Equipment Integration Guide](https://docs.yudash.com/integration-guides/industrial-instruments).
* [Modbus RS485](https://docs.yudash.com/dc/df/modbus) in YuDash Device Features
* [Modbus Poll Tutorial](https://docs.yudash.com/dc/df/modbus/modbus-poll-tutorial) in YuDash Device Features

#### 2) Modbus/TCP-IP

* Refer to [Modbus TCP/IP](https://docs.yudash.com/yudash-iot-devices/lynx-user-manual/lynx-settings/modbus-tcp-ip) in LYNX User Manual

With assumption of basic Modbus understanding, we explain integration of YuDash IoT devices with Modbus instruments, PLCs and HMIs.

## Integration of IoT Gateway in various Modbus topologies

### 1) Integration of IoT Gateway with PLC based systems

#### 1) Typical PLC application with Modbus/RS485 communication

<figure><img src="https://1858257737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FToww5EM1cml3ouN6fvnJ%2Fuploads%2Fw1XyphWB4uCAzykW2jLn%2F3.jpg?alt=media&#x26;token=b60ea77a-523c-4246-a566-a4b297295c35" alt=""><figcaption></figcaption></figure>

#### 1A) PLC system with IoT Gateway using Modbus/RS485

<figure><img src="https://1858257737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FToww5EM1cml3ouN6fvnJ%2Fuploads%2F6MURJgvTNoqHIjfC5O8j%2F4.jpg?alt=media&#x26;token=634a567f-8339-4352-98d3-ef8b1bede2c5" alt=""><figcaption></figcaption></figure>

#### 1B) PLC system with IoT Gateway using Modbus TCP/IP

<figure><img src="https://1858257737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FToww5EM1cml3ouN6fvnJ%2Fuploads%2FOcJddaHvOoZuo0F2ma36%2F8.jpg?alt=media&#x26;token=81d5154f-ee70-48d3-a6df-fc9725d4e1e3" alt=""><figcaption></figcaption></figure>

### 2) Integration of IoT Gateway with PLC+HMI based systems

#### 2) Typical PLC+HMI based system

<figure><img src="https://1858257737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FToww5EM1cml3ouN6fvnJ%2Fuploads%2FhsmK7sBRl9g5iMSILuUW%2F5.jpg?alt=media&#x26;token=a3e0c267-6780-483c-9f73-d45b6cd96aef" alt=""><figcaption></figcaption></figure>

#### 2A) PLC+HMI with IoT Gateway using Modbus/RS485

<figure><img src="https://1858257737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FToww5EM1cml3ouN6fvnJ%2Fuploads%2FoHYb2nlQ4r9755951Gmu%2F6.jpg?alt=media&#x26;token=609e5bf1-ad74-4a78-bbc9-38d09af12026" alt=""><figcaption></figcaption></figure>

#### 2B) PLC+HMI with IoT Gateway using Modbus TCP/IP

<figure><img src="https://1858257737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FToww5EM1cml3ouN6fvnJ%2Fuploads%2FOg7fbR7z0NcRErLbtH9i%2F9.jpg?alt=media&#x26;token=826023bc-c668-478b-801e-379f13761732" alt=""><figcaption></figcaption></figure>

### 3) IoT Gateway with RS485 enabled instruments

<figure><img src="https://1858257737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FToww5EM1cml3ouN6fvnJ%2Fuploads%2FF85EPOWMwSAKgaDezLDj%2F11.jpg?alt=media&#x26;token=07edfc77-69d7-4b10-bfd3-3b4a68becb11" alt=""><figcaption></figcaption></figure>

All Modbus topologies are captured in below tutorial

{% file src="<https://1858257737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FToww5EM1cml3ouN6fvnJ%2Fuploads%2FrEkOipQMZh57uONZ43ne%2FYuDash_Modbus_Tutorial.pdf?alt=media&token=03784aa4-197f-4e66-9760-7736c3f7e74b>" %}

## Requirements in PLC system for IoT compatible

It is important that PLC based system for Industrial Machines/Assets are designed to be IoT compatible. It is imperative that all machines will be IoT enabled (Industry 4.0) now or later in future. Following are key requirements during system design to make IoT ready (using Modbus):&#x20;

1. Identify existing topology of PLC/HMI system from [above](#integration-of-iot-gateway-in-various-modbus-topologies) list and select one of integration option for IoT Gateway.
2. One channel of Modbus RS485 or Modbus TCP/IP (Ethernet) has to be made available for IoT gateway. IoT Gateway will be Modbus Master (Client) which will request data from the existing system.
3. The select Modbus channel has to be configured as Slave (Server) and communication settings should be well documented.&#x20;
4. Following is required information for **Modbus RS485**:

<table><thead><tr><th width="281">RS485 Parameter</th><th>Sample/Description</th></tr></thead><tbody><tr><td>Baudrate</td><td>9600, 19200 etc</td></tr><tr><td>Data Bits, Parity &#x26; Stop Bit</td><td>8N1, 8E1 etc.</td></tr><tr><td>Slave ID for Modbus slave</td><td>1, 2 etc.</td></tr><tr><td>Modbus RS485 terminals</td><td><p>The RS485 terminals should be well defined (preferably take a photograph with A and B marked). </p><p>In case of DB9/RJ25/RJ45  jack, clearly identify the pins. It is advisable to provide a two wire connector on the jack.</p></td></tr><tr><td></td><td></td></tr></tbody></table>

> It is advisable that provided communication settings should be verified by PC based Modscan software. Please document snapshots of Modscan, similar to this [example](https://docs.yudash.com/yudash-iot-devices/lynx-user-manual/lynx-settings/modbus-rs485). &#x20;

5. Following is required information for **Modbus TCP/IP**

| Modbus TCP/IP Paramter                | Sample/Description                                                               |
| ------------------------------------- | -------------------------------------------------------------------------------- |
| IP address                            | 192.168.100, 10.0.0.1 etc.                                                       |
| IP port                               | The port number on which Modbus Server is running. For example: 503, 888         |
| Server ID Modbus Server               | 1, 2, etc.                                                                       |
| RJ 45 jack for connecting IoT gateway | Well defined RJ45 jack to connect IoT Gateway. It can be in PLC/HMI or a switch. |

6. Identify critical parameters from the system to be provided to the IoT Gateway. These can be real-time process values, thresholds, batch numbers or alarm values.&#x20;
7. List down the parameter names, Modbus register numbers, data types in tabular form.&#x20;
   1. The register should be complete 5 digits or define the register type (Input, Holding etc).
   2. If data type is Floating point, please define LSB/MSB type.
8. Sample Table of Modbus Registers&#x20;

| Parameter   | Modbus Register | Data Type            |
| ----------- | --------------- | -------------------- |
| Voltage     | 40000           | Signed Integer       |
| Temperature | 30050           | Floating point (LSB) |
| Alarm1      | 10000           | Binary               |

### Technical References for YuDash IoT Gateways

1. [Modbus RS485 Settings in YuDash LYNX](https://docs.yudash.com/yudash-iot-devices/lynx-user-manual/lynx-settings/modbus-rs485)
2. [Modbus TCP/IP Settings in YuDash LYNX](https://docs.yudash.com/yudash-iot-devices/lynx-user-manual/lynx-settings/modbus-tcp-ip)
3. [Instrument Integration Guides with YuDash LYNX](https://docs.yudash.com/integration-guides/industrial-instruments)

&#x20;
