Simulate Modbus serial communication RutOS

From Teltonika Networks Wiki
Revision as of 13:04, 24 October 2022 by JustasB (talk | contribs) (Created page with "{{Template:Networking_manual_Modbus_serial_RutOS}}")

(diff) ← Older revision | Approved revision (diff) | Latest revision (diff) | Newer revision → (diff)
Main Page > General Information > Configuration Examples > Modbus > Simulate Modbus serial communication RutOS

Summary

Modbus is a serial communications protocol originally published by Modicon (now Schneider Electric) in 1979 for use with its programmable logic controllers (PLCs). Modbus has become a de facto standard communication protocol and is now a commonly available means of connecting industrial electronic devices. The main reasons for the use of Modbus in the industrial environment are:

  • developed with industrial applications in mind;
  • openly published and royalty-free;
  • easy to deploy and maintain;
  • moves raw bits or words without placing many restrictions on vendors.

Modbus enables communication among many devices connected to the same network, for example, a system that measures temperature and humidity and communicates the results to a computer. Modbus is often used to connect a supervisory computer with a remote terminal unit (RTU) in supervisory control and data acquisition (SCADA) systems. Many of the data types are named from its use in driving relays: a single-bit physical output is called a coil, and a single-bit physical input is called a discrete input or a contact.

This article provides a brief example on how to use Modbus serial to monitor a slave device, send data to server and how to configure slave alarms. To find more information about this feature visit RUT955 Modbus page.

Prerequisites

  • One device with RS232 Serial port;
  • Windows 10/11 OS computer;
  • Beeceptor account and created Mock server;
  • ModRSsim application;
  • RS232 to USB cable.

Topology

Installation

From FW version of RUT9_R_00.07.05 and newer Modbus Serial Client package is installed by default. To install it on older FW versions open device's WebUI, navigate to Services → Package manager → Packages and search for Modbus Serial Master and press + icon to install. After installation you should see a status Installed on this package.

Configuring Modbus serial slave device

In this example we are going to be using our Windows 10/11 OS computer as a slave. To do so you will need to install modRSsim application, which you can download here.

When you are done with that, open the app and apply the following configuration.

  1. Select Protocol (MODBUS RS-232).
  2. Click Setup the communication Serial or TCP/IP port.

  1. Select the Port which you connected RS232 cable to (to find which port you are using go to Windows search bar and write Device Manager then select Ports and see which one you are using).
  2. Select Parity (Even).
  3. Click OK.

Configuring Modbus serial master

Open router’s WebUI, navigate to Services → Modbus → Modbus Serial Client and in Serial Device configuratio section add new instance by entering a name, selecting rs232 and pressing button. In the newly opened Device Configuration window configure everything as follows:

  1. Enable instance;
  2. Select Baud rate (9600, it must match slave‘s baud rate);
  3. Select Parity (Even);
  4. Press button.

Now in Modbus Devices section create RS232 slave by writing a new instance name, selecting rs232 and pressing button. In the new window apply the following configuration:

  1. Check Enable;
  2. Type in desired Name;
  3. Type in Server ID (any number from 1 to 255);
  4. Select Period, e.g. 10;
  5. Write a name for a new request.
  6. Add new request by writing it's name and clicking ADD;
  7. Select data type.
  8. Select Function (Read holding registers (3)).
  9. Write First register (1) and Write Register count (10).
  10. Enable the request and you can test it through request configuration testing section.
  11. Press button.

Modbus data to server

Creating server


In order to test the functionality, you will need to set up a server.

There are many ways how you can create a server to which Modbus will send data to. In this example we are going to be using a Beeceptor's Mock server. If you don't have a Beeceptor account yet – create it or login via Google account.

  1. Specify your desired mock server's URL.
  2. Press on Create Mock Server.

And that is it, now you will be able to see the data coming from Modbus to your created Beeceptor's server.

RUT Modbus data to server configuration


In order to setup your router to send Modbus data to server you will need to navigate to Services → Data to Server, create a "New collectiom name" and press ADD to add a new instance.

  1. Select Type: Modbus;
  2. Select Format Type: Custom;
  3. Enter desired format string;
  4. Leave other parameterms as it is and click on icon;
  5. In the Collection configuration window leave the settings as default and click on button;
  6. In the Server configuration window select Type: HTTP;
  7. Enter Server address;
  8. Click ;

Receiving data


Open Beeceptor's window again, and after some time you should start receiving Modbus Data messages.

Try to change some data in the Modbus Slave simulator.

Received data should change.

Slave alarms

In order to setup the following configuration SIM card is required.

Go back to Services → Modbus → Modbus Serial Client and press button on the previously created Modbus slave Device instance or create a new one. In the opened window scroll down to the bottom and in Alarms Configuration section press .

In Alarm Configuration apply the following changes:

  1. Enable instance.
  2. Select Function (Read Holding Registers).
  3. Write Register (1).
  4. Select Condition (More than).
  5. Write Value (10).
  6. Select Action frequency (First trigger)
  7. Select Action (SMS).
  8. Create Message (type anything you want to receive).
  9. Write Phone number (the number you want to receive the messages to).
  10. Press button.

Now go back to Modbus slave simulator and edit this window:

Change the value to anything below 10, you should not receive messages. Then change the value to anything above 10, you should start receiving messages.