Modbus Tutorial For NI
Modbus Tutorial For NI
Overview
The Modbus industrial protocol was developed in 1979 to make communication possible between automation devices. Originally implemented as an application-level protocol intended to transfer
data over a serial layer, the protocol has expanded to include implementations over serial, TCP/IP, and the user datagram protocol (UDP). Today, it is a common protocol used by countless
devices for simple, reliable, and efficient communication across a variety of modern networks.
Table of Contents
1. The Request-Response Cycle
2. The Modbus Data Model
3. Modbus Function Codes
4. LabVIEW Modbus API
5. Modbus I/O Servers
6. NI OPC Servers With OPC I/O Servers or OPC UA
Introduction to Modbus
Modbus is typically used for Supervisory Control and Data Acquisition (SCADA)-style network communication between devices. For example, a large server may be used to master a
programmable logic controller (PLC) or programmable automation controller (PAC), while that PLC/PAC may in turn master a sensor, valve, motor, or any other embedded device.
To meet these needs, Modbus was designed as a request-response protocol with a flexible data and function modelfeatures that are part of the reason it is still in use today.
Data Type
Master Access
Slave Access
Coils
Boolean
Read/Write
Read/Write
Discrete Inputs
Boolean
Read-only
Read/Write
Holding Registers
Unsigned Word
Read/Write
Read/Write
Input Registers
Unsigned Word
Read-only
Read/Write
1/6
www.ni.com
Figure 2. The Mapping Between a Function Code, Data Ranges, and the Actual Memory of a Slave Device
The most common function codes are named after the conceptual data range they modify or access. For example, read holding registers takes the action of pulling data out of the memory
defined as holding registers and returning it to the master. Table 2 identifies the most common function codes.
2/6
www.ni.com
Figure 5. Modbus Master and Slave Palettes Showing the Function Codes
Finally, the Modbus instance is closed, de-allocating the memory associated with the instance. This also closes any references, including the TCP connection or NI-VISA serial references used by
the instance.
Only the master example has been discussed thus far; however, every example follows the same basic pattern familiar to most LabVIEW users: open, read/write, and close.
Finally, although the API does look the same, it is important to understand the key difference. If your device is a master, it must send a request across the network to the appropriate slave to
acquire data. The slave, on the other hand, has its own local data storage and can access it quickly.
3/6
www.ni.com
4/6
www.ni.com
Figure 8. A SCADA Application Using Modbus, NI OPC Servers, and OPC I/O Servers
You can also develop a similar architecture that uses the OPC UA driver included in the LabVIEW DSC Module in place of OPC I/O servers. However, the OPC UA driver is a low-level driver and
does not provide the ease of use afforded by OPC I/O servers.
To develop an application like this, you must first generate a valid configuration for NI OPC Servers to communicate with your slave devices. This is done by generating channelswhich define a
driver configurationand deviceswhich define an individual endpoint for that driver. After you have configured a device, you can then generate tags.
5/6
www.ni.com
6/6
www.ni.com