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 three options for Modbus connectivity.
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 intending to 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 that 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) that 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 an 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
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.
Changelog:
22-March-2023: Removed mentions of SAPHIR add-on products "ModBusVIEW over TCP" and "ModBusVIEW over Serial" as they are no longer available.
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
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.
Thanks! I'd like to synchronize data derived from Modbus with my DAQ data; hope I'll manage to do it now.
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/ http://buyessays.cheap/
Its also on github: https://github.com/rfporter/Modbus-Master
Hi Christian:
I cannot get the latest version 1.2.1.42 from the VIPM to work in Serial Master RTU. Every time I attempt to read a holding register, it shows error 0x56 timeout. I am trying to communicate to a Test Equity Temp Chamber with a F4T controller trying to read holding register 2782.
I tried 2 alternatives and they both work: 1.) An external (non-Labview) program "modbus poll" and it works with the same setup.
2.) Earlier version of the modbus API version 1.2.1 from here: http://www.ni.com/example/29756/en/
Seems like there was a big change from jumping from the 1.2.1 polymorph VIs to the 1.2.1.42 LVOOP based VIs and somewhere in between the modbus serial read broke.
Regards,
Mike
I tried to download this library with VI package manager; it first says it cannot find any content, and tells me to search online, which I click, which opens a browser at vipm.io/package/ni_lib_modbus_library
When I then click "install with VIPM", another window opens of VI package manager 2020, with vipm://ni_lib_modbus_libary, but everything in that window is blank (verion, maintainer, labview version, os), only license is "not specified". I can't do anything more.
How can I install this package?
I had a similar problem. I was using the NI Modbus Library, and one day I tried running an application which uses it, and the dependency was just gone!
I can't reinstall using VIPM, and I can't even reset my password. I don't get the confirmation email.
I checked the location of the package file and it is accessible and downloadable. If necessary, you could download the package file (plus the spec and BMP files) to your local hard drive and install them in VIPM using the local copy.
http://download.ni.com/evaluation/labview/lvtn/vipm/packages/ni_lib_modbus_library/
Dear Christian
I tried to use the example for Serial modbus communication with an instrument (RKC PZ900), but I failed. I would like to know if there is any example having a typical instruction to address a slave at address 1, in double word, communicating on port COM10 for example ?
I found the problem with the VIPM download. For some reason, it lost all server information.
To fix it:
Tools -> Options -> Advanced
Click "Refresh Mirrors".
OK
Now it should be possible to search for
NI Modbus Library
and install it.
Regards,
Greg
Hi @MikeJJ,
Did you solve the issue?. I'm also facing intermittent timeout error 56 while using the library when the registers are being polled continuously.
Hi djac91,
Sorry I did not get back to you sooner, but no I found no solution except to use the older library that was not LVOOP based. I might try the new library again in the future and see if this error occurs again.
Regards,
Mike
hello there;
I want to read coils data with out using read control i.e. I need auto update reading.
best regards
Hello, I am trying to read the current of a wattmeter in u32 but the program only reads in u16 and the data overflows.
How could I do?
The .vi has password.
Use Join Number to combine two registers values into a U32.
Solved! Thank you very much crossrulz!