Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Example Program
NI Supported: Yes
Publish Date: Feb 10, 2009


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

Read Input Registers Using the Modbus Library for LabVIEW.

1 ratings | 5.00 out of 5
Print

Overview

This example shows how to use the Modbus library for LabVIEW to read analog inputs from a Modbus slave device. The Slave device we are communicating with as an example is the Watlow MLS300 Controller that is connected via serial port.

Downloads

Filename: modbusexample.zip
Requirements: View


Introduction to the Modbus Library for LabVIEW.

National Instruments provides a Modbus Library for LabVIEW that is designed to facilitate communication to a device that can use the Modbus protocol. Since Modbus is a serial communications protocol, the VISA driver can be used to send data over the serial port to communicate with a Modbus device. The Modbus library for LabVIEW is a set of VIs that take Modbus specific inputs and converts those to the appropriate VISA commands.

Using the Modbus Library for LabVIEW.

In this example, you will see that communicating with a Modbus device will involve initializing the port we are using, then using the query command, and finally closing the Port. This example can be modified very easily to write any outputs or read any inputs that the Modbus device makes available. The main parameters that will need to be changed are the Function Code and Starting Address. These 2 inputs to the Query VI are the inputs that tell LabVIEW which registers we are accessing and whether we are writing or reading values.

Determining parameters to use in this example for the Watlow MLS300.

The most challenging part of communicating with a Modbus device is figuring out what address to use and figuring out what to use for some of the other parameters. Generally, to figure this out, you will need to use the documentation for your Modbus device to figure this out. When using the Watlow MLS300, most of this information is located in either the MLS3XX Communications Specification or user manual. Both of these documents can be found on the Watlow web site

For example, if you wanted to read analog input 1 on the Watlow MLS300 controller, you would first have to make sure you are using the correct baud rate and slave address for the Watlow controller. To set parameters or determine the current values for parameters on the Watlow MLS300, you have to navigate through the menus on the controller interface. Information on how to navigate to these settings is located in the setup chapter (chapter 4) of the Watlow MLS300 user guide. For this example, we will use a baud rate of 19200 and a slave address of 1. These parameters have to be set on the controller and entered on the front panel of this example program.

Next you will have to enter information about the register you are trying to access. Since we are trying to read analog input 1 in this case, we need to find out the starting address for the analog inputs. In the Watlow MLS300 communication specification, under the Modbus communication chapter we can find the table shown below. The analog inputs are called "Process Variables". We can see that the starting address for process variables are 016B in Hex, which is 363 in decimal.

In the LV example program, on the front panel, we will enter the following:

Function code: Read Input Registers - Because we are reading analog input values
Starting Address: 363 or 016B - From the table in the communications specification
Quantity: 1 - Because we are reading 1 register.
Discrete Inputs and Data Inputs are going to be left blank because we are reading registers and not writing to them. If we were writing to analog outputs, we would put the data to write in the "Data Inputs".

Now when the example program is run, the reading of analog input 1 should be displayed in the "Register Outputs" array.

Notice:

In most cases, it is more efficient and easier to use OPC (OLE for process control) to communicate to these devices.  OPC is a tool that helps manager channels and communication with PLC's.  This includes communication with Modbus devices.  For more information on OPC, visit NI's web site and search for OPC.  

 

Requirements


Filename: modbusexample.zip

Software Requirements


Application Software: LabVIEW Base Development System 7.1
Language(s): LabVIEW

Hardware Requirements


Driver: NI-VISA 4.0

 
1 ratings | 5.00 out of 5
Print

Reader Comments | Submit a comment »

Utterly useless
No documentation. No help file. No descriptions of controls or indicators. If the example does not work with the device you're trying to communicate there is no way to diagnose the problem.
- John S Trembley, Monsanto Company. john.s.trembley@monsanto.com - Aug 19, 2009

Why hidden controls?
There is no good reason to have hidden controls on the front panel. That is not good LV style. Those hidden controls should be changed to diagram constants.
- Jul 7, 2009

 

Legal
This example program (this "program") was developed by a National Instruments ("NI") Applications Engineer. Although technical support of this program may be made available by National Instruments, this program may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this program with each new revision of related products and drivers. THIS EXAMPLE PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).