Frequently Asked Question

Video: 7.2.2. Modbus device (server)
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

00:00:02

Hello and welcome to the demonstration of the Modbus Server component. 

00:00:06

In this lesson, we will see how to implement and configure Modbus Server on a HIL device. 

00:00:11

To start, let s open the Typhoon HIL Control Center Examples Explorer and  

00:00:15

choose the Modbus Server Setup example from the communication protocols section. 

00:00:39

This is a simple Modbus example model that demonstrates how to properly setup a Modbus  

00:00:44

TCP connection for real-time testing applications and how to connect inputs and outputs properly. 

00:00:51

Let s start with the Modbus configuration. The Modbus Device configuration is defined as  

00:00:56

a Python dictionary with predefined fields. The dictionary is usually defined in the Namespace,  

00:01:02

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

00:01:06

By pressing the button F8 from your keyboard you can easily access this panel. 

00:01:12

Each configuration dictionary has mandatory and optional fields that can be separated in  

00:01:16

the following groups: Network parameters, Register map, and Additional parameters. 

00:01:22

In network parameter fields, values such as IP address, Netmask, Port, and Gateway are defined. 

00:01:30

In the register map fields, register addresses,  

00:01:34

types, and values are defined.Let s start by defining a name for  

00:01:38

the dictionary. This should be properly set in the component dialog box too. 

00:01:44

Please note that it is also possible to define the network parameters directly from  

00:01:48

the dialog box or from SCADA inputs. Either of these will override the same parameters  

00:01:53

scripted in the initialization script.To enable the model to work on every network,  

00:01:59

the IP address in the configuration must be defined correctly. The IP address is set to  

00:02:04

192.168.0.209 in this example, but it needs to be changed according to the network domain. 

00:02:12

In order to check the current IP address of your PC, let s open the console by  

00:02:17

typing CMD in the Windows search tab. Open the application and type the command ipconfig. 

00:02:25

In the IPv4 address field you should get the current IP of your PC, highlighted here. Your  

00:02:31

Modbus Server IP should have the same first three numbers as here, but the fourth number should be  

00:02:36

different from any of the others on the network.Let s pick a number that s different from the  

00:02:41

current IP address and check if it is free in our network. Once we have our number,  

00:02:46

type the command ping followed by the IP you have chosen in the Command Prompt. If we see  

00:02:50

the message unreachable, that means that this is free, and we can use it for our Modbus Server.  

00:02:55

Let s put this new IP address in the ip_addr field in the Model Initialization script. 

00:03:02

Finally, the slave ID is also important when connecting the HIL device to a Modbus RTU external  

00:03:09

device, as this is required under Modbus RTU.After finishing network parameter configuration,  

00:03:15

we need to configure the register map. The type of register, number,  

00:03:20

and addresses must all be properly defined.There are two ways of configuring the registers  

00:03:25

for Modbus Server in HIL device, the first and the second version. 

00:03:31

Version 1 is a simpler version with less features whereas in Version 2,  

00:03:35

features like minimum, maximum, and scale values can additionally be defined for each register. 

00:03:42

The first version is presented here in this example. It refers  

00:03:46

to an older method of defining register maps. In this method,  

00:03:50

registers are defined in a string form where you can define the register addresses and types. 

00:03:56

Also, in this method, Coil and Holding registers are split into two parts, input and output.  

00:04:02

Reading the register value from the Client will sample the signal connected to the input of the  

00:04:07

Modbus Device component and writing the value to the register will update the output of the  

00:04:11

component. This means that the input and output registers cannot have the same register address,  

00:04:17

since a change on the input will automatically change the output value, which is not desired. 

00:04:22

In this version Coil and Discrete registers are defined simply by a list of address values between  

00:04:27

0 and 65535 as shown here. Although the Input and Holding registers are 16 bits long as defined by  

00:04:35

the Modbus protocol, multiple registers can be grouped together to represent 32- and 64-bit  

00:04:41

registers of different types.To specify the type of register,  

00:04:46

write u for unsigned integer, i for integer or f for floating point after the address value.  

00:04:51

If the type is not specified explicitly, the register will be defined as an unsigned integer.  

00:04:57

If the register is 16, 32, or 64-bit, the type must be specified after the closing bracket. 

00:05:05

In this example you can see a mixed configuration for holding and input registers. There is,  

00:05:11

for example, an unsigned integer of 16 bits, an integer of 64 bit shown by 4 16-bit registers  

00:05:18

grouped together, a float of 32 bits, and an unsigned integer in the input register setup. 

00:05:25

The Register Map Version 2, on the other hand,  

00:05:28

refers to a newer method of defining register maps. In this method,  

00:05:33

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

00:05:38

In comparison to Version 1, this version introduces the possibility to define more  

00:05:42

parameters for registers and allow input and output registers to have the same address value. 

00:05:48

An example of a register map is illustrated here in the Initialization Panel, below version 1. 

00:05:55

Different register types have different fields that can be defined,  

00:05:58

but only the addr field is mandatory.Now that we ve properly configured the  

00:06:03

Modbus Server device, let s go back to the model. It is important to note that the Modbus protocol  

00:06:09

components do not work on Virtual HIL, only on supported HIL 4- and 6-series devices.  

00:06:14

If we try to run this model in SCADA using virtual HIL, all values will simply remain at 0. 

00:06:22

To establish a connection to the Modbus device in your model, all devices that communicate  

00:06:27

using Modbus protocol must be connected to the same network. This can be established either by  

00:06:32

using an Ethernet switch to connect 2 or more devices, or by connecting a HIL directly to  

00:06:37

the device or a PC using an Ethernet cable.This model consists of a single Modbus Server  

00:06:43

Device and the main purpose is to write the input registers values from SCADA inputs.  

00:06:48

On the left side you have here four coil inputs, four discrete inputs,  

00:06:52

two holding registers inputs, and five input registers. Usually in a real application these  

00:06:58

are the variables that are read from the model to be sent to the Client, and they are read only. 

00:07:04

On the right side you have coil outputs and holding register outputs,  

00:07:08

usually these are the variables to be written to the model, from a Client request. If the output  

00:07:13

is a vector, it can be split to scalars using a Bus Split component as demonstrated here.  

00:07:19

Since there aren t any vector outputs in this example, we won t be using this feature. 

00:07:25

To monitor the output from the Modbus device, you can use a Probe component as used here. 

00:07:30

Let s compile and go to SCADA to monitor the inputs and outputs of the component! 

00:07:37

After compiling the model and loading to the HIL device you can open the pre-configured SCADA  

00:07:42

panel for this example. On the left side of the panel, you can set some input registers from SCADA  

00:07:47

inputs that are read from the input registers at the Modbus Server device in the schematic.  

00:07:52

On the right side, you can read some of the variables written  

00:07:55

out to the Modbus output registers, such as coils and holding registers. 

00:08:01

In order to stimulate this demo, you can use an external Modbus Client,  

00:08:05

such as QModMaster. QModMaster is a free implementation of a ModBus master application.  

00:08:12

A graphical user interface allows easy communication with ModBus RTU and TCP slaves.  

00:08:18

QModMaster also includes a bus monitor for examining all traffic on the bus.  

00:08:23

You can find a download link for this software in the Materials Tab. 

00:08:28

You can now run the model by clicking at the PLAY button,  

00:08:30

this allows the Modbus Server implement on the HIL device application to execute. 

00:08:35

Now we can open QModMaster and connect it to the Modbus Server from HIL device. 

00:08:42

First, let s click on the Options tab and then the Modbus TCP option. Let s properly setup the  

00:08:48

Modbus Server IP and port. For this we will use the same IP and port that we defined in the model.  

00:08:54

After that, in the main screen, let s configure Modbus Mode to  

00:08:58

TCP and the scan rate to our desired value. Let s use 1000 milliseconds. 

00:09:04

Now, we can select which Function Code we want to use for the Modbus Client request.  

00:09:10

Let s select Write Multiple Coils, choose the IP address that was configured in the  

00:09:14

Modbus Server in the schematic model, and choose the right number of coils to write. 

00:09:20

After that, let s hit the connect button,  

00:09:23

change the value to be written out in the dialog box, and click the button read/write. 

00:09:29

If we go back to the SCADA panel, we can see the LED turned green at the output coils.  

00:09:34

This means that the Client successfully performed the function code provided. 

00:09:39

Now, we can also trigger the reading request from the Client.  

00:09:42

Let s change the value of the Holding registers in the SCADA panel to an arbitrary number. 

00:09:57

After that, let s go back to QModMaster and select the read holding registers function code.  

00:10:03

Let s set the value as Decimal type and perform the read operation. 

00:10:07

Now we can read the two holding registers we defined previously: Holding register 0,  

00:10:12

which is a 16-bit unsigned value, and the holding register 1, which is a 32-bit integer value. 

00:10:19

We can also write from the QModMaster Modbus Client to  

00:10:22

the Holding registers output of the Modbus Server as shown here. 

00:11:03

In this lesson, we learned how to setup the Modbus Server component and interact  

00:11:07

with it using QModMaster as a Modbus Client. Feel free to play around and  

00:11:11

continue using this tool to test your model communication.

00:11:15

Thank you and see you in the next lesson.

Please Wait!

Please wait... it will take a second!