Frequently Asked Question
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.
Hello and welcome to the demonstration of the Modbus Server component.
In this lesson, we will see how to implement and configure Modbus Server on a HIL device.
To start, let s open the Typhoon HIL Control Center Examples Explorer and
choose the Modbus Server Setup example from the communication protocols section.
This is a simple Modbus example model that demonstrates how to properly setup a Modbus
TCP connection for real-time testing applications and how to connect inputs and outputs properly.
Let s start with the Modbus configuration. The Modbus Device configuration is defined as
a Python dictionary with predefined fields. The dictionary is usually defined in the Namespace,
either through a Model Initialization script or through the component mask.
By pressing the button F8 from your keyboard you can easily access this panel.
Each configuration dictionary has mandatory and optional fields that can be separated in
the following groups: Network parameters, Register map, and Additional parameters.
In network parameter fields, values such as IP address, Netmask, Port, and Gateway are defined.
In the register map fields, register addresses,
types, and values are defined.Let s start by defining a name for
the dictionary. This should be properly set in the component dialog box too.
Please note that it is also possible to define the network parameters directly from
the dialog box or from SCADA inputs. Either of these will override the same parameters
scripted in the initialization script.To enable the model to work on every network,
the IP address in the configuration must be defined correctly. The IP address is set to
192.168.0.209 in this example, but it needs to be changed according to the network domain.
In order to check the current IP address of your PC, let s open the console by
typing CMD in the Windows search tab. Open the application and type the command ipconfig.
In the IPv4 address field you should get the current IP of your PC, highlighted here. Your
Modbus Server IP should have the same first three numbers as here, but the fourth number should be
different from any of the others on the network.Let s pick a number that s different from the
current IP address and check if it is free in our network. Once we have our number,
type the command ping followed by the IP you have chosen in the Command Prompt. If we see
the message unreachable, that means that this is free, and we can use it for our Modbus Server.
Let s put this new IP address in the ip_addr field in the Model Initialization script.
Finally, the slave ID is also important when connecting the HIL device to a Modbus RTU external
device, as this is required under Modbus RTU.After finishing network parameter configuration,
we need to configure the register map. The type of register, number,
and addresses must all be properly defined.There are two ways of configuring the registers
for Modbus Server in HIL device, the first and the second version.
Version 1 is a simpler version with less features whereas in Version 2,
features like minimum, maximum, and scale values can additionally be defined for each register.
The first version is presented here in this example. It refers
to an older method of defining register maps. In this method,
registers are defined in a string form where you can define the register addresses and types.
Also, in this method, Coil and Holding registers are split into two parts, input and output.
Reading the register value from the Client will sample the signal connected to the input of the
Modbus Device component and writing the value to the register will update the output of the
component. This means that the input and output registers cannot have the same register address,
since a change on the input will automatically change the output value, which is not desired.
In this version Coil and Discrete registers are defined simply by a list of address values between
0 and 65535 as shown here. Although the Input and Holding registers are 16 bits long as defined by
the Modbus protocol, multiple registers can be grouped together to represent 32- and 64-bit
registers of different types.To specify the type of register,
write u for unsigned integer, i for integer or f for floating point after the address value.
If the type is not specified explicitly, the register will be defined as an unsigned integer.
If the register is 16, 32, or 64-bit, the type must be specified after the closing bracket.
In this example you can see a mixed configuration for holding and input registers. There is,
for example, an unsigned integer of 16 bits, an integer of 64 bit shown by 4 16-bit registers
grouped together, a float of 32 bits, and an unsigned integer in the input register setup.
The Register Map Version 2, on the other hand,
refers to a newer method of defining register maps. In this method,
registers are defined in a Python list where each register is defined as a dictionary.
In comparison to Version 1, this version introduces the possibility to define more
parameters for registers and allow input and output registers to have the same address value.
An example of a register map is illustrated here in the Initialization Panel, below version 1.
Different register types have different fields that can be defined,
but only the addr field is mandatory.Now that we ve properly configured the
Modbus Server device, let s go back to the model. It is important to note that the Modbus protocol
components do not work on Virtual HIL, only on supported HIL 4- and 6-series devices.
If we try to run this model in SCADA using virtual HIL, all values will simply remain at 0.
To establish a connection to the Modbus device in your model, all devices that communicate
using Modbus protocol must be connected to the same network. This can be established either by
using an Ethernet switch to connect 2 or more devices, or by connecting a HIL directly to
the device or a PC using an Ethernet cable.This model consists of a single Modbus Server
Device and the main purpose is to write the input registers values from SCADA inputs.
On the left side you have here four coil inputs, four discrete inputs,
two holding registers inputs, and five input registers. Usually in a real application these
are the variables that are read from the model to be sent to the Client, and they are read only.
On the right side you have coil outputs and holding register outputs,
usually these are the variables to be written to the model, from a Client request. If the output
is a vector, it can be split to scalars using a Bus Split component as demonstrated here.
Since there aren t any vector outputs in this example, we won t be using this feature.
To monitor the output from the Modbus device, you can use a Probe component as used here.
Let s compile and go to SCADA to monitor the inputs and outputs of the component!
After compiling the model and loading to the HIL device you can open the pre-configured SCADA
panel for this example. On the left side of the panel, you can set some input registers from SCADA
inputs that are read from the input registers at the Modbus Server device in the schematic.
On the right side, you can read some of the variables written
out to the Modbus output registers, such as coils and holding registers.
In order to stimulate this demo, you can use an external Modbus Client,
such as QModMaster. QModMaster is a free implementation of a ModBus master application.
A graphical user interface allows easy communication with ModBus RTU and TCP slaves.
QModMaster also includes a bus monitor for examining all traffic on the bus.
You can find a download link for this software in the Materials Tab.
You can now run the model by clicking at the PLAY button,
this allows the Modbus Server implement on the HIL device application to execute.
Now we can open QModMaster and connect it to the Modbus Server from HIL device.
First, let s click on the Options tab and then the Modbus TCP option. Let s properly setup the
Modbus Server IP and port. For this we will use the same IP and port that we defined in the model.
After that, in the main screen, let s configure Modbus Mode to
TCP and the scan rate to our desired value. Let s use 1000 milliseconds.
Now, we can select which Function Code we want to use for the Modbus Client request.
Let s select Write Multiple Coils, choose the IP address that was configured in the
Modbus Server in the schematic model, and choose the right number of coils to write.
After that, let s hit the connect button,
change the value to be written out in the dialog box, and click the button read/write.
If we go back to the SCADA panel, we can see the LED turned green at the output coils.
This means that the Client successfully performed the function code provided.
Now, we can also trigger the reading request from the Client.
Let s change the value of the Holding registers in the SCADA panel to an arbitrary number.
After that, let s go back to QModMaster and select the read holding registers function code.
Let s set the value as Decimal type and perform the read operation.
Now we can read the two holding registers we defined previously: Holding register 0,
which is a 16-bit unsigned value, and the holding register 1, which is a 32-bit integer value.
We can also write from the QModMaster Modbus Client to
the Holding registers output of the Modbus Server as shown here.
In this lesson, we learned how to setup the Modbus Server component and interact
with it using QModMaster as a Modbus Client. Feel free to play around and
continue using this tool to test your model communication.
Thank you and see you in the next lesson.