Frequently Asked Question

Video: 7.2.1. Modbus introduction
Last Updated 2 years ago


Press "Ctrl + F" to find the keyword of your interest.

If you wish to have a direct link access to the video timestamps, please follow these instructions.

Found this video helpful? Why not take the whole HIL Specialist course? A Certificate is waiting for you for free at HIL Academy.

Would you or your organization benefit from having these videos narrated in your native language? Contact us and let us know if you wish to contribute.

TRANSCRIPT

protocol implementation on Typhoon HIL devices.Modbus is a data communications protocol  

00:00:15

originally published by Modicon in 1979 for use with its programmable logic controllers,  

00:00:20

or P L Cs. Modbus has become a de facto standard communication protocol  

00:00:25

and is now a commonly available means of connecting industrial electronic devices. 

00:00:30

Modbus is popular in industrial environments because it is openly published and royalty-free.  

00:00:36

It was developed for industrial applications, is relatively easy to deploy and maintain, and places  

00:00:41

few restrictions on the format of the data to be transmitted. It is widely used in applications  

00:00:47

ranging from industrial control networks, microgrids, Healthcare, and home automation. 

00:00:53

Modbus supports communication to and from multiple devices connected to the same cable or Ethernet  

00:00:58

network. For example, there can be a device that measures temperature and another device to  

00:01:03

measure humidity connected to the same cable, both communicating measurements to the same computer. 

00:01:09

Modbus TCP is a Modbus variant used for communications over TCP/IP  

00:01:14

networks, connecting over port 502, which communicates using an ethernet network. 

00:01:20

TCP stands for transport control protocol. Modbus was first introduced as RTU, and in  

00:01:26

this configuration it communicates through either a RS232 or RS485 serial interface. 

00:01:33

For these lessons, we will be focusing on the TCP configuration because only  

00:01:37

this is natively implemented in the Typhoon HIL toolchain. However, it is possible to  

00:01:42

interface a HIL device with Modbus RTU by simply using a Modbus RS485 adapter,  

00:01:48

which converts from one type to the other.Modbus RTU is a master slave protocol. This  

00:01:54

means that one device acts as a master, initiating all communication to a slave device via requests.  

00:02:00

The slave device simply responds to these requests and then waits for new ones. 

00:02:05

In Modbus TCP configuration, on the other hand, the master is referred to as a client  

00:02:10

and the slave as a server. Beyond this, the communication process generally remains the same. 

00:02:16

In Typhoon HIL Control Center, both Modbus TCP Server and Client are implemented using Signal  

00:02:22

Processing components in Schematic Editor. All currently supported HIL devices are able to  

00:02:28

implement Modbus TCP. Modbus Client can also be implemented in SCADA through Modbus API,  

00:02:34

which is a Python wrapper from the pyModbus open-source library. With this,  

00:02:39

it is also possible to configure a Modbus Client with Virtual HIL or Standalone SCADA. 

00:02:44

The Modbus protocol standard defines four types of registers: discrete inputs, coils or discrete  

00:02:50

outputs, input registers, and holding registers. The differences between those registers are shown  

00:02:56

in this table. Discrete inputs and coils are the size of one bit. These usually represent contactor  

00:03:02

controls and feedbacks, as well as the status of components in a power system. Meanwhile, input and  

00:03:09

holding registers are sixteen bits long and are commonly used to represent analog variables such  

00:03:14

as voltage, current, frequency, and power.It is important to note that some registers  

00:03:19

are read only, which means that they can only be displayed and not written. These registers should  

00:03:24

be used for monitoring purposes. Other registers are read/write registers, which usually represent  

00:03:30

variables to be controlled from the remote client side. For example, a SCADA operator  

00:03:35

can change references for power or voltage in a power system through these registers. 

00:03:40

Although Modbus standard only specifies 1- or 16-bit registers,  

00:03:44

it is possible to use 32 bit or 64-bit registers in the Modbus Server component.  

00:03:50

This is done by combining 2 or 4 consecutive registers respectively. 

00:03:54

Modbus TCP defines some functions to access register data. These functions  

00:04:00

are clarified here in this table. Every Modbus request is done using one of these functions.  

00:04:05

In Modbus TCP, these are mapped as function codes, so every function has its own code.  

00:04:12

Every time the Client requests to read or to write a specific register address to a Server,  

00:04:17

it sends this function code in the message.Now let s look at how Modbus Server is implemented  

00:04:22

for HIL Devices. The Modbus Server component is a Signal processing component available in  

00:04:27

Schematic Editor, meaning it is executed at the model level. Moreover, it is implemented through  

00:04:33

a Linux operating system and executed in the embedded ARM processor of the HIL device. 

00:04:39

On the left, we can see how the component looks in Schematic Editor. The left side terminals  

00:04:44

are for registers that should be read from the model and parsed for the Client. These registers  

00:04:48

are all read-only: coil inputs, discrete inputs, holding registers inputs and input registers. 

00:04:55

The right-side terminals are for the registers that should be written in the  

00:04:58

model based on the client s requests. These registers are read/write registers such as:  

00:05:04

coil outputs and holding register outputs.By double clicking on the component,  

00:05:09

the Properties window will open. In the General tab, we can define the Modbus configuration  

00:05:14

name and execution rate. In the Network settings tab, we can define all IP, port,  

00:05:20

and ID settings. These can be configured as coming from a Python dictionary with predefined fields,  

00:05:26

directly from the dialog box, or from SCADA inputs. The dictionary is usually defined in the  

00:05:32

Namespace, either through a Model Initialization script or through the component mask.

00:05:37

Here we have a table summarizing the basic Modbus configuration parameters. 

00:05:42

Two versions of register maps can be used. Version 1 is a simpler version with less features whereas  

00:05:47

in Version 2, features like min, max, and scale values can be defined for each register.  

00:05:53

This table describes the version 1 parameters. 

00:05:57

The field name of these parameters should be scripted in the initialization panel of Schematic  

00:06:01

Editor, especially when all the configuration is done through the dictionary option.  

00:06:06

This table, as well as scripting examples and the differences between the two registers versions are  

00:06:11

available and explained in detail in the Modbus Device documentation in the Materials Tab. 

00:06:17

Register Map Version 2 refers to a newer method of defining register maps. In this method,  

00:06:22

registers are defined in a Python list where each register is defined as a dictionary. 

00:06:27

In comparison to Version 1, this version introduces the possibility  

00:06:31

to define more parameters for registers and allows input and output registers  

00:06:35

to have the same addresses value.Different register types have different  

00:06:40

fields that can be defined, but only the address field is mandatory. This table lists  

00:06:45

all the parameters for each register type with a description of allowed values. You can also  

00:06:50

find this in the Modbus Device documentation.Let s look at an example of this configuration  

00:06:55

scripted in the model initialization panel when using a Python dictionary as an input. 

00:07:01

The first script shows a parametrization according to register mapping version 1. Config 1 is the  

00:07:06

configuration name. In the beginning we have all the network parameters, such as port and IP  

00:07:11

addresses. At the end of the dictionary, we have the configuration of the Modbus Server registers.  

00:07:17

In this section it is important to properly setup the registers addresses accordingly,  

00:07:22

respecting the variable type and the number of registers combination to achieve it. 

00:07:26

For example, for coils and discretes, we have 1-bit registers, so it is simply required to type  

00:07:32

the number of the registers. Holding and input registers can have 16, 32, and 64-bit registers,  

00:07:40

so it is necessary to specify the number of registers and the type. For 32 and 64-bit  

00:07:45

registers, it is necessary to combine 2 or 4 registers and specify the type, as shown here. 

00:07:51

The second script shows the version 2 type register mapping. Here we can see  

00:07:56

that in the network parametrization remains the same as in version 1,  

00:08:00

but in the register setup the configuration looks more organized. It also allows for more input  

00:08:05

about the type of data to be exchanged.You can implement multiple Modbus Server  

00:08:10

components in the same HIL device. In this case, it is important to define another  

00:08:14

dictionary for each additional server and specify a different IP addresses for it. 

00:08:20

Now let s have a look at how to implement a Modbus Client. A Modbus Client instance can  

00:08:25

be implemented either at the model level with the Modbus Client component or in SCADA with  

00:08:29

Modbus API, running in the PC application. Let s look at the SCADA implementation first. 

00:08:35

Modbus API is a wrapper from the open-source Modbus library implementation pyModbus,  

00:08:41

and it can be implemented in HIL SCADA through Python scripts. 

00:08:44

When using Modbus API to send signals to the HIL device via SCADA, for instance, the user  

00:08:50

PC will be the Modbus client instance sending requests to the server in the HIL device. 

00:08:55

Moreover, this implementation has the advantage to work both with HIL,  

00:08:59

Virtual HIL, and standalone SCADA.This library supports all standard and  

00:09:05

advanced read and write functions, as well as 32- and 64-bit registers. 

00:09:10

Similar to Modbus Server, the Modbus Client implements the standard functions defined  

00:09:15

by the Modbus protocol for reading and writing the values of the registers. 

00:09:19

An example for how to use these functions is presented here. In this case,  

00:09:23

the read_input_registers function will read input registers consecutively beginning from your  

00:09:28

defined starting addresses start_address until a number of input registers equal to num is read.  

00:09:33

The write_multiple_registers function lets you write to the registers defined  

00:09:37

in start_address with the values defined in the following list. We will cover these actions in  

00:09:42

more detail in the following lessons.Advanced functions are also available for  

00:09:47

16-bit registers. The configuration is similar to the one defined in the server configuration  

00:09:52

in the initialization panel of the Schematic Editor, where you specify the list of addresses  

00:09:57

and group them based on the length and the type of registers. Then, you can put this string on  

00:10:02

the function argument and just pass the values that you want to read or write. In this way,  

00:10:07

you can read and write the whole configuration of the server in a single command. 

00:10:11

Now let s look into the Modbus Client device component in Schematic Editor.  

00:10:16

Like Modbus Server, this is implemented as a signal processing component and executed  

00:10:21

in the embedded Linux on the HIL device CPU.The Modbus Client in Schematic Editor has some  

00:10:26

advantage over the API implementation. With this you can test your Client instance faster, as it  

00:10:32

is executed in the HIL device and not or your PC, it is possible to interact directly with the model  

00:10:38

without the SCADA and it is easier to setup, because it does not require any scripting. 

00:10:43

On the left you can see how the component looks like in the Schematic Editor interface.  

00:10:47

In contrast to Modbus Server, the terminals are not fixed; each read and write request  

00:10:52

added from the dialog box will create a new terminal at the component interface. 

00:10:57

By opening the component properties, it is possible to configure the network of the Modbus  

00:11:02

component directly, through the Client setup box on the left and the Server setup box on the right.  

00:11:07

It is important to enter the correct Modbus Server IP addresses, otherwise the Client won t be able  

00:11:13

to reach it and stablish a connection.Request timeout and execution rate for the  

00:11:17

component are also configurable here.In the last section of the configuration panel, we  

00:11:23

can see a dialog box where all possible requests are implemented. By clicking the plus button,  

00:11:28

we can add requests, configure what function code is used, define the starting addresses, the number  

00:11:35

of registers to be read or write to, the requests transmission type, and the period of each one. 

00:11:40

It is important to mention that, for now, only 16-bit registers are  

00:11:45

implemented for the Modbus Client.In this lesson, we covered the basics of  

00:11:49

Modbus and Modbus TCP as a whole, as well as how these are implemented in the Typhoon HIL  

00:11:54

toolchain via Modbus Server and Modbus Client components. In the next lessons,  

00:11:59

we will look more into the practical uses of each of these components.

Please Wait!

Please wait... it will take a second!