# MODBUS

1. Connect your Modbus device to the Gateway as shown below.

<figure><img src="https://1313992628-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdTvSz7jpW1e3wAaLdma4%2Fuploads%2F3SVrqPqQFE8NL4XMB2BH%2FAB_collage.jpg?alt=media&#x26;token=5b5644e8-0a9f-455b-bf90-1cda4324f761" alt=""><figcaption><p>4GW-E (L) &#x26; 4GW-D (R)</p></figcaption></figure>

2. Enter the correct configuration details to make sure the Gateway is able to communicate to a Modbus device successfully and click on <mark style="color:purple;">**Update**</mark><mark style="color:purple;">.</mark>

<figure><img src="https://1313992628-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdTvSz7jpW1e3wAaLdma4%2Fuploads%2FiLGyBJFqT0meY2Z4t0nz%2Fmodbus%20border.png?alt=media&#x26;token=b643cff3-ceea-46d3-b4ad-0f55aebc71a9" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
If mode 3 (TCPIP) is selected, connect Gateway to the Ethernet switch/router and then connect the Modbus Slave also to the Ethernet switch/router in the same network.
{% endhint %}

<table><thead><tr><th width="76">No.</th><th width="142">Field</th><th width="141">Default Value</th><th>Description</th></tr></thead><tbody><tr><td>1</td><td>Mode</td><td>0</td><td>0 = Disabled<br>1 = RTU<br>2 = ASCII<br>3 = TCPIP<br>Enter the required mode if you wish to enable Modbus.</td></tr><tr><td>2</td><td>Scan Interval</td><td>5000</td><td>It is the time period to poll data from Modbus slaves.</td></tr><tr><td>3</td><td>Scan Timeout</td><td>1000</td><td>It is the timeout interval for one query.</td></tr><tr><td>4</td><td>Offset</td><td>0</td><td></td></tr><tr><td>5</td><td>Baud Rate</td><td>9600</td><td>4800 / 9600 / 115200 <br>Enter the baud rate same as your Modbus device.</td></tr><tr><td>6</td><td>Data Bits</td><td>8</td><td><mark style="background-color:red;">Do not change data bit value.</mark></td></tr><tr><td>7</td><td>Parity</td><td>0</td><td>0 = DISABLE<br>1 = EVEN<br>2 = ODD<br>Enter value of parity same as your Modbus device.</td></tr><tr><td>8</td><td>Stop Bits</td><td>1</td><td>1 / 1_5 / 2<br>Enter stop bits same as your Modbus device. </td></tr><tr><td>9</td><td>IP Address</td><td>[192.168.23.111]</td><td>IP address assigned to slave for Modbus TCPIP mode.</td></tr><tr><td>10</td><td>Port</td><td>502</td><td><mark style="background-color:red;">Do not change default port.</mark></td></tr><tr><td>11</td><td>Slave ID</td><td>[0, 1]</td><td>Enter multiple slave ids in array format required only in TCPIP mode if you wish to read data from multiple slaves.<br></td></tr></tbody></table>

3. You can see the Modbus response topic for the device. Subscribe to this topic to receive data from Gateway.

<figure><img src="https://1313992628-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdTvSz7jpW1e3wAaLdma4%2Fuploads%2F8QnIOOuHluwzS2iJ0ibx%2Fss30%20frame.png?alt=media&#x26;token=06c01e4b-a822-48aa-8f28-60a7fb8f1d5c" alt=""><figcaption></figcaption></figure>

4. Enter one or more Modbus queries in the specified format.

E.g `[[1,3,0,8,12,0],[1,3,12,10,12,1],[2,3,0,5,0,2]]`

{% hint style="info" %}
Make sure you are entering queries in the correct format.
{% endhint %}

{% hint style="info" %}
To know more about how to create a Modbus query please refer to [Modbus Query](https://aliter-business-solutions.gitbook.io/iot-gateway-user-manual/gateway-configuration/modbus-query) and [Modbus Datatypes & Function Codes](https://aliter-business-solutions.gitbook.io/iot-gateway-user-manual/gateway-configuration/modbus-datatypes-and-function-codes).
{% endhint %}

<figure><img src="https://1313992628-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdTvSz7jpW1e3wAaLdma4%2Fuploads%2FfqmqIXlqae5plGkAhO2s%2Fss31%20frame.png?alt=media&#x26;token=8d1e964c-2f42-4d07-bb3d-a9d2f568122d" alt=""><figcaption></figcaption></figure>

5. Click on <mark style="color:purple;">**Preview**</mark> to see a JSON preview of the Modbus data.

<figure><img src="https://1313992628-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdTvSz7jpW1e3wAaLdma4%2Fuploads%2FyrAphQz8v9Pm9n3yEkur%2Fss32%20frame.png?alt=media&#x26;token=f6ab6e07-65b8-470a-8002-e1bb2c02f6c0" alt=""><figcaption></figcaption></figure>

6. Click on <mark style="color:purple;">**Update**</mark> to update the queries on the Gateway.
7. Click on <mark style="color:purple;">**Erase**</mark> to erase all queries from the Gateway.
8. Enter Modbus address mapping.

E.g `{"voltage": ["1D4", "2D7"], "current": ["1D17", "3D124"]}`

{% hint style="info" %}
Make sure you are entering address mapping in the correct format.
{% endhint %}

{% hint style="info" %}
To know more about how to create a Modbus Address Mapping works please refer to [Modbus Address Mapping](https://aliter-business-solutions.gitbook.io/iot-gateway-user-manual/gateway-configuration/modbus-address-mapping).
{% endhint %}

<figure><img src="https://1313992628-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdTvSz7jpW1e3wAaLdma4%2Fuploads%2FwxlgfKkkUMdPMHbqvAbQ%2Fmodbus%20address%20mapping%20border.png?alt=media&#x26;token=dae3f272-0187-4223-97d0-af0dcbfe8984" alt=""><figcaption></figcaption></figure>

9. Click on <mark style="color:purple;">**Update**</mark> to update the addresses as per the given mapping.&#x20;
10. Click on <mark style="color:purple;">**Erase**</mark> to erase mapped addresses from the Gateway.
11. Enter Custom Publish details if you want to send data in sets(max 3 JSON objects in a set for a single Modbus slave is configurable).

<figure><img src="https://1313992628-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdTvSz7jpW1e3wAaLdma4%2Fuploads%2FUDm5O8sD85UANUGDZPT9%2Fcustom%20publish%20border.png?alt=media&#x26;token=7b82563a-7ed5-42df-ba14-7e43f60f4c5f" alt="" width="563"><figcaption></figcaption></figure>

<table><thead><tr><th width="77" data-type="number">No.</th><th width="161">Field</th><th width="146">Default Value </th><th>Description</th></tr></thead><tbody><tr><td>1</td><td>Mode</td><td>0</td><td>0 = Disabled<br>1 = Enabled <br>If 0 is selected data will be published as default.</td></tr><tr><td>2</td><td>Interval</td><td>1</td><td>It is the time period by which data should be published.</td></tr><tr><td>3</td><td>Data Points</td><td>3</td><td>No. of data points that should be published together in the given interval. </td></tr></tbody></table>

12. Click on <mark style="color:purple;">**Update**</mark> to publish data as per the given pattern.

{% hint style="info" %}
Please refer to the [Activity](https://aliter-business-solutions.gitbook.io/iot-gateway-user-manual/gateway-configuration/activity) section to verify that the Modbus configuration has been updated successfully.
{% endhint %}
