Reference Design Content

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Modbus API

The current version of this library is provided in VI Package Manager.

 

Link to Most Recent Version attached below

 

Overview

 

Modbus is a commonly used protocol for industrial communication. At present, National Instruments provides four options for Modbus connectivity.

 

(1) Modbus I/O server, available through the LabVIEW Real-Time Module or the LabVIEW Datalogging and Supervisory Control (DSC) Module.which provides a high-level API for accessing Modbus data. Learn more at Connect LabVIEW to Any PLC With Modbus

 

(2) A free Modbus library available for download which is very low-level, and provides control over Modbus not offered by I/O servers at the expense of the connection management and request scripting offered by that higher-level API. **This Library is Unsupported**

(3) This NI Labs Modbus API release which is intended as a replacement and expansion of the free Modbus library functionality. **This Library is Unsupported**

(4) The Modbus API available through the LabVIEW Real-Time Module or the LabVIEW Datalogging and Supervisory Control (DSC) Module. This is a version of the NI Labs Modbus API which is now supported and maintained by National Instruments R&D.

 

In addition, an NI Alliance Partner SAPHIR has two released LabVIEW add-on products called ModBusVIEW over TCP and ModBusVIEW over Serial available on the LabVIEW Tools Network.

 

Description

 

Modbus is an application-level protocol which defines a set of functions used for interaction between a master [client] device, such as an HMI or PAC, and a slave [server] device, like a PLC, gateway, or sensor. Every interaction between master and slave is a request-response interaction. That is, the master initiates all communication and is responsible for sending requests to which the slave must respond. A number of function codes are pre-defined by the protocol for both setting and getting data on a slave, but other functions may be defined by the user. One goal of this NI Labs release is to provide a better platform for users wishing support additional function codes on either the master or slave sides of the protocol, and to allow users to customize behavior more readily if a particular device does not adhere to the specification. In this library, the request generation and response parsing code is defined by the master function definition.

 

The pre-defined function codes focus on 4 main types of data: coils, discrete inputs, holding registers, and input registers. Coils and discrete inputs are two sets of 65,536 boolean values which can be accessed by the master. Master devices have full read/write access to coils, but discrete inputs are read-only from the point of view of the master. Holding registers and input registers are two sets of 65,536 integer values (16-bit, unsigned) which can be accessed by the master. As with the boolean values, holding registers are read/write while input registers can only be written by the slave device itself. Each bank of values is addressed by a single U16 integer, meaning that the address ranges from 0 to 65,535.

 

Besides these 4 types of data, later versions of the specification added a new type of data, called objects. These objects are simply strings which can be stored in the memory of the device and which contain device identification data. The definition and meaning of objects 0x00 through 0x06 is defined by the specification, and objects 0x07 through 0x7F are reserved. However, objects 0x80 through 0xFF can be defined by the slave device and chosen to store any data chosen by the device manufacturer. The first three objects are called "basic" objects, all other specified objects are "regular", and device-defined objects are "extended". For more information, view the Modbus specification.

 

These data sets are contained in the slave data model. The default Modbus implementation is called the standard data model, but other data models can be generated to override the standard model. This data model also defines how the slave will respond to master requests.

 

Wrapping this Modbus protocol data unit (PDU) is an application data unit (ADU) which defines the full packet sent out across the network. There are three main variants, IP, RTU, or ASCII, but it is straightforward to implement a new packet format. IP is intended to be used with a TCP/IP network, while RTU and ASCII are binary and human readable packets for a serial network. In this library's implementation, the packet format is independent of the network. For historical reasons, because Modbus was originally developed for serial networks, the PDU is limited to 253 bytes. For RTU and ASCII ADUs, this creates an ADU size of 256 bytes. The IP ADU contains additional information and is 260 bytes long. In this library, the code set associated with the ADU is called the transmission data unit and the code associated with the PDU is called the Modbus data unit. The network across which the ADU is transferred is defined by the network protocol family of classes.

 

All functions in this library are wrapped by a API class which includes an implementation of master and slave functionality. This API is what is shown on the palette. The object-oriented nature of the code makes it easy to modify API behavior, or even core function behavior, as necessary.

 

Using the Library

 

This library is distributed as a VI package, meaning that it requires JKI's VI Package Manager for installation. Once installed, the Modbus API will be available on the Data Communication function palette and the Add-ons Palette. Each palette (master and slave) contains a basic example of the functionality of the API. The master example demonstrates basic connection and error handling, as well as the ability to set and get certain data items from the slave. The slave example demonstrates setting and getting data, as well as the retrieval of properties related to the background connection handler including the status of the handler, and the number and status of all current connections.

 

Requirements

 

Software

  • LabVIEW 2012 or later
  • NI-VISA for Modbus serial communication

Support

 

At present, this library is experimental and unsupported. Please see the licensing notice below. For the discussion around this API, please visit the NI LabVIEW Modbus API Discussion.

 

NI Labs Licensing Notice

 

Because the software technology available on NI Labs is experimental and has not yet been released for large-scale commercial use or fully tested by NI, the terms of the NI Labs license agreements vary from the standard NI software license terms. Further, the license terms for specific NI Labs technology may vary. Please carefully read the terms of the license agreement included with each NI Labs download before accepting those terms. This library uses the NI Sample Code License.

 

Known Issues

 

 

Release Notes

 

[1.0.9.22] Warning: A VI was renamed in this version to make it consistent with the rest of the library naming scheme. Specifically Write Multiple Registers was renamed to Write Multiple Holding Registers. In addition to this change, documentation was correct with respect to the default parity and Read Exception Status correctly checks to make sure that the ADU is a serial ADU.

 

Download

 

The current version of this library is provided in VI Package Manager.

 

Source Code

 

The source code for the LabVIEW Modbus API is hosted on the following GitHub repo.

 

https://github.com/NISystemsEngineering/LabVIEW-Modbus-API

 

Please submit issues on the GitHub repo for any bug reports or feature suggestions, or submit a pull request if you make enhancements to the API.

 

Comments
Member EricLM
Member
Is there a public repository for the source code for this? I could not find it on the NI Github site. I have a need to modify the VIs and they are password protected.
Member Porter
Member

The Plasmionique Modbus Master library is similar to this API but open source (and does not include Modbus slave).

Find the latest release here: https://lavag.org/files/file/286-plasmionique-modbus-master/

Its also on github: https://github.com/rfporter/Modbus-Master

Active Participant Christian_L
Active Participant

The LabVIEW Modbus API is now hosted on the following GitHub repo.

 

https://github.com/NISystemsEngineering/LabVIEW-Modbus-API

 

Please submit issues with any bug reports or feature suggestions, or submit a pull request if you make enhancements to the API.

authored by
Christian L, CLA
Principal Development Manager - Partner Program
Applications Engineering Senior Manager - Data Acquisition, Control, and Real-Time Test
National Instruments - Austin, TX