Modbus Overview
Modbus Overview
blog
Modbus
With Practical LabVIEW Examples
Hans-Petter Halvorsen
Contents
• Modbus
• Modbus in LabVIEW
• LabVIEW Examples
– LabVIEW Coils Examples
– LabVIEW Discrete Input Registers Examples
– LabVIEW Input Registers Examples
– LabVIEW Holding Registers Examples
https://www.halvorsen.blog
Modbus
RTU
Slave
Master
SCADA DSC
Slave
Master
PC Slave
Sensors and Actuators
A remote terminal unit (RTU) is a microprocessor-controlled electronic
device that interfaces objects in the physical world to a DCS or SCADA System
Master/Slave
Client Request Server
Master Slave
Response
Note! The terms “Master” and “Slave” used in Modbus has been
replaced with the terms “Client” and “Server”. The LabVIEW Modbus
package still use the old terms, so they will also be used in this Tutorial
Master/Slave
• Modbus protocol is defined as a master/slave
protocol, meaning a device operating as a
master will poll one or more devices operating
as a slave.
• This means a slave device cannot volunteer
information; it must wait to be asked for it.
• The master will write data to a slave device’s
registers and read data from a slave device’s
registers. A register address or register reference
is always in the context of the slave’s registers.
Master/Slave
Client
Write Data Server Registers
Master
Slave
Polling/Request
Client
Read Data Data Stored in Registers
Master
Modbus protocol is defined as a master/slave protocol, meaning a device operating as a master will poll
one or more devices operating as a slave. This means a slave device cannot volunteer information; it must
wait to be asked for it. The master will write data to a slave device’s registers and read data from a slave
device’s registers. A register address or register reference is always in the context of the slave’s registers.
Modbus Register Types
• Coil (Discrete Output)
– Coils are 1-bit registers, used to control discrete
outputs, Read or Write
• Discrete Input (Read Only)
– 1-bit registers
• Input Register (Read Only)
• Holding Register (Read/Write)
Access Levels
• In SCADA systems, it is common for embedded devices to have
certain values defined as inputs, such as gains or proportional
integral derivative (PID) settings, while other values are
outputs, like the current temperature or valve position.
• To meet this need, Modbus data values are divided into four
ranges
• In many cases, sensors and other devices generate data in
types other than simply Booleans and unsigned integers.
• It is common for slave devices to convert these larger data
types into registers. For example, a pressure sensor may split a
32-bit floating point value across two 16-bit registers.
Access Levels
Register Type Data Type Master Access Slave Access
Coils Bit (Boolean) Read/Write Read/Write
Discrete Input Bit (Boolean) Read-only Read/Write
Input Register Unsigned Word Read-only Read/Write
Holding Register Unsigned Word Read/Write Read/Write
...
...
...
128 Slave Master Slave
Modbus TCP/IP
• Modbus TCP/IP follows the OSI Network
Model and can be used in an ordinary
Ethernet network
• Modbus TCP requires that you know or
define IP addresses on the network
• Modbus TCP/IP uses Port 502
https://www.halvorsen.blog
Modbus in LabVIEW
LabVIEW Examples
LabVIEW Coils
Examples
Hans-Petter Halvorsen Table of Contents
LabVIEW Coils Example
In this Example we Create 3 different LabVIEW Applications:
LabVIEW App #2 LabVIEW App #1
LabVIEW App #3
LabVIEW App #1
LabVIEW App #2 Registers
Master Read Data Slave
(Client) (Server)
Request
LabVIEW Input
Registers Examples
Hans-Petter Halvorsen Table of Contents
LabVIEW Input Registers Examples
In this Example we Create 2 different LabVIEW Applications:
LabVIEW App #1
LabVIEW App #2 Registers
Master Read Data Slave
(Client) (Server)
Request
LabVIEW Holding
Registers Examples
Hans-Petter Halvorsen Table of Contents
LabVIEW Holding Registers Example
In this Example we Create 3 different LabVIEW Applications:
LabVIEW App #3
Memory Type Data Type Master Access Slave Access
Holding Register Unsigned Word Read/Write Read/Write
LabVIEW Holding Registers Example
Modbus Slave
Modbus Master (Write)
Modbus Master (Read)
Alt Solution
• How do you deal with Decimal/Floating-point
Numbers?
• Previously we implemented a simple solution by
multiplying and dividing with 100, which worked fine
for 2 decimal numbers
• In Modbus, the default practice is to split a 32-bit
floating point value across two 16-bit registers.
• The disadvantage is that we need to use 2 Modbus
register for representing one number
32-bit floating point across two 16-bit registers
Here we have split a 32-bit floating point value across two 16-bit registers
32-bit floating point across two 16-bit registers
Here we get the 32-bit floating point from two 16-bit registers
Modbus Master (Write)
Modbus Master (Read)
Modbus Registers Summary
Register Type Data Type Master Access Slave Access
Coils Bit (Boolean) Read/Write Read/Write
Discrete Input Bit (Boolean) Read-only Read/Write
Input Register Unsigned Word Read-only Read/Write
Holding Register Unsigned Word Read/Write Read/Write
E-mail: hans.p.halvorsen@usn.no
Web: https://www.halvorsen.blog