Modbus is a general industrial standard. Control devices produced by different manufacturers can be connected to an industrial network through Modbus for centralized monitoring.

Modbus TCP and Modbus RTU are two common transmission methods of Modbus, Modbus RTU is serial communication, Modbus TCP is TCP communication, the two are very similar in protocol, but due to the reliability of the TCP protocol, no verification is required in the Modbus TCP protocol. , and one more application header than the Modbus RTU protocol.

As an IoT edge industrial protocol gateway software that supports dozens of industrial protocol conversions, Neuron has also implemented the function of TCP transmission based on the Modbus RTU protocol. At the same time, in the Modbus protocol, Neuron optimizes the strategy according to the configured points, which can realize the function of automatically collecting device data in batches.

This article will introduce how to use Neuron to access Modbus TCP and Modbus RTU under the environment of Ubuntu 20.04.3 and X86_64.

Introduction to Neuron

Neuron is an industrial protocol gateway software that can run on various IoT edge gateway hardware. It aims to solve the problem of difficult unified access to device data in the context of Industry 4.0. By converting data of different protocol types from complex and diverse industrial equipment into unified standard IoT MQTT messages, the interconnection between devices and industrial IoT systems and between devices is realized, and remote direct control and information acquisition are carried out. Intelligent manufacturing provides data support.

Neuron supports one-stop access and MQTT protocol conversion for multiple different communication protocol devices and dozens of industrial protocols at the same time. It only takes up ultra-low resources, that is, it can be deployed in X86, ARM, RISC-V, etc. in the form of native or container in various edge hardware of the architecture. At the same time, users can realize online gateway configuration management through the Web-based management console.

Configuration environment description

  • Please download Neuron software from the official website https://neugates.io/zh/downloads and execute the following instructions to install Neuron software.

     sudo apt install ./neuron-2.0.1-linux-amd64.deb

    Then use the following command to check the Neuron status

     sudo systemctl status neuron
  • Please download the Modbus simulator from the PeakHMI official website and install it, then open the Modbus TCP slave Ex.

For getting started with Neuron, please refer to: Neuron Quick Tutorial .

Operating procedures

Two plug-ins, modbus-plus-tcp and modbus-rtu, will be used in Neuron. The following will introduce how to connect to Modbus TCP.

Example of connecting to Modbus TCP

The first step is to create a node card

添加 Modbus TCP 设备

  1. Click 添加设备 ;
  2. Fill in the device name, such as modbus-plus-tcp-1;
  3. Select from the drop-down box modbus-plus-tcp plugin.

The second step, device configuration

Click the 设备配置 button in the node card to enter the device configuration interface.

  1. Fill in the IP address where the Modbus simulator is started;

    1. Started neuron and modbus simulator should be under the same network segment;
    2. The windows where the Modbus simulator is located should close the firewall as much as possible, otherwise it may not be able to connect to Neuron.
  2. Fill in the port number of the Modbus simulator, generally the default is 502;
  3. Set the timeout time for Neuron to connect to the device;
  4. Select the connection method, Neuron now supports two connection modes as Client and Server, and the Client connection method is selected by default;
  5. Click 提交 to complete the device configuration and open the card working state.

配置 Modbus TCP 1

配置 Modbus TCP 2

The third step, create a Group group

Click any blank space of the node card to enter the Group* list interface.

  1. Click 创建 ;
  2. Fill in the Group name in the pop-up box, such as group-1;
  3. Fill in the time interval for Neuron to read data from the device and upload data in the pop-up window, for example, 3000;
  4. Click 创建 to complete the creation of the Group;
*Note: Group can be understood as a type of sensor. For example, if multiple temperature sensors and multiple humidity sensors are connected to one device, a "temperature" group can be set to unify all temperature sensors into one group. Data reporting and reading are in groups, and users can group points according to business needs.

Neuron 创建 Group

Note:

When configuring Modbus points of different stations on the Neuron, it is recommended to include only the points of one station under the same Group, or only include the points of the same data area under one station to obtain higher configuration collection efficiency.

The fourth step, create a Tag

Click Tag 列表创建 in the Group to manually add tags.

  1. Fill in the Tag name, such as tag1;
  2. Fill in the Tag address, such as 1!40001 (for detailed address configuration rules, please refer to the extended knowledge below);
  3. Drop-down selection properties, such as Read, Write;
  4. Drop down to select the data type, for example, select INT16;
  5. Click 创建 to add a Tag;
  6. You can also click 添加 , add multiple Tags at a time and then click 创建 ;

Neuron Tag 列表

Neuron Tag 列表1

Neuron 创建 Tag

After the creation is completed, the Tag list will display the created Tag information, then return to the southbound device management interface, wait for about 15s, and check whether the connection status of the Modbus node card displays 已连接 , as shown in the following figure.

Neuron 已创建 Tag 列表

Modbus 连接状态

If the connection is not connected for a long time, please perform the following troubleshooting:

  • Check whether the host and port of the device configuration are incorrectly filled against the simulator. You can execute the telnet command on the terminal running the Neuron server to check whether the remote server and port can be accessed;
  • In the terminal running the Neuron server, check whether port 502 is occupied;
  • Check whether the port number of the emulator is 502, and check the Port Number in file → settings, as shown in the following figure.

    Modbus 模拟器

The fifth step, data monitoring and viewing data

After successfully connecting to the Modbus simulator, you can open the data monitoring interface to view the data collected by Neuron from the Modbus simulator.

查看 Modbus 上报数据

Example of connecting to Modbus RTU

The steps are like Modbus TCP, but because Modbus RTU is serial communication, so 设备配置 is different from Modbus TCP.

连接 Modbus RTU 示例

  • Device, the path of the serial port connection;
  • Stop, stop bit;
  • Parity, check digit;
  • Baud, bit rate;
  • Data, data bits;

Neuron already supports Modbus RTU-based TCP transmission function, and the application configuration is shown in the figure below.

基于 Modbus RTU 的 TCP 传输功能

knowledge extension

The general configuration format of Modbus point address in Neuron is SLAVE!ADDRESS , among which:

  • SLAVE stands for Slave ID;
  • ADDRESS refers to the PLC address:
block Modbus block number
coils 0
input registers 3
Discrete input (Input) 1
hold registers 4

The function code and register addressing address are used in the instruction. The register addressing address starts from 0. Different function codes correspond to different blocks. The PLC address is block number + register addressing address + 1. For example, if the function code 0x03 is used, the addressing address is 0, and the corresponding ADDERESS in neuron should be 40001.

Epilogue

So far, we have completed the entire process of using Neuron to access Modbus TCP and Modbus RTU protocol devices. As an edge industrial protocol gateway software for the "connection" of the Industrial Internet of Things, Neuron also supports access to other industrial protocols such as OPC UA and Siemens, helping to build an efficient Industrial Internet of Things platform.

Copyright statement: This article is original by EMQ, please indicate the source when reprinting.

Original link: https://www.emqx.com/zh/blog/connecting-modbus-tcp-and-modbus-rtu-protocol-devices-with-neuron


EMQX
336 声望436 粉丝

EMQ(杭州映云科技有限公司)是一家开源物联网数据基础设施软件供应商,交付全球领先的开源 MQTT 消息服务器和流处理数据库,提供基于云原生+边缘计算技术的一站式解决方案,实现企业云边端实时数据连接、移动、...