Example Code

Basic MODBUS TCP/IP Read Holding Register using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Overview

SImple Vi to read a given value from a TCP/IP device using MODBUS protocol

 

Description

The Vi opens a TCP master and reads a specified holding register, returning the value of that register.

 

Steps to Implement or Execute Code

  1. Enter IP address of device
  2. Enter Starting address (no need to enter the code of 4 for the holding register.  Just enter the last digits of the address-1
  3. Enter amount (1)
  4. Enter 0 to achieve the first register value.

 

Requirements

Software

  1. LabVIEW 2014(or compatible)

Hardware

  1. TCP/IP Device

 

Additional Information or References

Modbus VI Final.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

 

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Member
Member
on

can you send the whole vi?

Member
Member
on

Hi

I have been searching for material, (explanations, examples etc.) to create a vi that will read and control a plc from a remote location. By this I mean that a plc controlled device that uses an HMI for operator input, located at one location but monitored and controlled by a VI using Modbus TCP from a remote location, for the purpose of recording data and even simple commands such as run, stop, and standby.

I'm using LV 2014.(32 bit), I've added NI Modbus Lib 1.2.1.42 (only after updating my JKI Package Manager to 2019!).

This example is great but I am looking for more understanding behind the Modbus master/slave functions and how to use networked shared variables to create a data file for evaluation and data reduction.

So if anyone can share a tutorial or recommend an appropriate knowledge base article etc I would be very happy to dive into  it

Thanks 

Gene