Integrating Communication Protocols Into a FlexLogger Plug-in

Updated Aug 27, 2026

Environment

Software

  • FlexLogger
  • LabVIEW
  • FlexLogger Plug-In Development Kit

FlexLogger Plug-ins provide a way to extend FlexLogger functionality and enable interaction with external devices and systems. Because plug-ins are developed in LabVIEW, you can use compatible LabVIEW functions, APIs, toolkits, and add-ons to implement communication with external instruments using protocols such as Modbus TCP/RTU, OPC UA, or TCP/IP.

This article explains how you can integrate communication protocols into your FlexLogger Plug-In, using Modbus TCP as an example. Before you can start following the steps, ensure you have installed LabVIEW (64-bit), FlexLogger, FlexLogger Plug-In Development Kit, and that they are compatible. Please note that the NI Modbus Library is utilized to integrate Modbus communication into the Plug-in. 

Keep in mind that additional requirements may apply depending on the communication protocol you want to implement. You should also verify that the required API, toolkit, or library is supported in the 64-bit version of LabVIEW installed on your system.

  1. Start by creating a new project in LabVIEW:
    1. Launch LabVIEW (64-bit).
    2. Click on Create Project.

This image presents the LabVIEW welcome screen with the Create Project button highlighted in red 

    1. Select FlexLogger IO Plug-in from the list of templates.

This image shows the FlexLogger IO Plug-in project template option highlighted in red

    1. Give your FlexLogger plug-in a name and complete the Description and Destination Directory (Source) fields. Additionally, in the Plug-in Template parameter, select Perform calculation. This template will allow you to generate data that can be visualized in FlexLogger and you will also be able to send data from FlexLogger to your device. 

This image shows how to setup the Plug-in template

 

  1. Prepare the Initialize.vi so the plug-in can read from one Modbus address and write to a different one:
    1. Open Initialize.vi and remove the Set Plugin Resample VI and Write Parameter VI. Press <Ctrl-B> to remove the broken wires.
    2. Remove the constants that are not connected to a VI. 
    3. Modify the block diagram as shown in the image below:

This image shows the final version of the initialize VI 

As presented in the image, two channels were created using the Create Channel_v2.vi. One for displaying the data retrieved from the Modbus Slave (Read Register) and one for passing data from FlexLogger to the slave (Write Register). Additionally, next to the Write Register channel, the Write Data Type.vi was placed to define the type of data that the user will be able to send to the plug-in. In this case, the data type has been set to DBL. 

 

  1. Modify the Configure Session.vi to add the Modbus Master TCP instance. If you are implementing a different communication protocol, you can create the corresponding session from here as well. 
    1. Delete the current Read Parameter.vi and press <Ctrl-B> to remove the broken wires. Remove the constants and the free labels as well.
    2. Place a Create Modbus Instance.vi on the block diagram. Configure the IP address of the Modbus device you will be connecting to.
    3. Create an indicator for the TCP master instance output of the Create Modbus Instance.vi. Open the Front Panel, select the indicator, and press <Ctrl-C> to copy it.
    4. In the Project Explorer Window look for the private data .ctl file that corresponds to the LabVIEW class associated to your plug-in. Right-click on it and select Open to edit it. 

This image shows how to edit the plugin's private data

    1. Press <Ctrl-V> to paste the TCP master instance indicator created in step c.
    2.  Create an Enum control on the private data (.ctl) front panel, and include the following options. You can change its name to Modbus States:

This image shows the Enum with Read, Write, and Error Handling options  

    1. Right-click on the Modbus States Enum, and select Make Type Def.
    2. Modify the Cluster of class private data as shown in the image below:

This image shows the cluster of class private data after adding both the Modbus Master instance and the Modbus States Enum

 

    1. Return to the Configure Session.vi and modify it as shown in the following image:

This image presents the final version of the configure session VI

 

  1. Open the Process.vi and delete the current contents except from the controls and indicators. Modify the VI as shown in the image below:

  This image shows the Process VI after removing the original contents. It is composed of a While Loop, Case Structure and an unbundle by name function that allows access to the private data. 

As presented in the image above, the Process.vi is composed of a While Loop and a Case Structure. The elements of the private data are being accessed through an Unbundle by Name function. According to the FlexLogger Plug-In Development Kit User Manual, the Process.vi is executed automatically in a loop by the FlexLogger data engine. Therefore, the Modbus States element that is connected to the Case Selector of the Case Structure will allow the code to navigate through the different states and switch between the Read, Write and Error Handling states that were defined from previous steps. 

 

  1. Modify the Read case of the Process.vi as shown in the images below:

This image shows the Read state VI. A Read Input Registers VI has been added and the error out from this function has been connected to an internal case structure which controls if the error handling is going to be executed

This image shows the second portion of the Read VI. It displays the Error case of the internal Case Structure that is inside of the main Case structure

As displayed in the images above, inside of the Read state, the Read Input Registers.vi has been utilized to retrieve the data from the input register with address "0". The error out output of this function has been connected to the case selector of a case structure than controls whether the plug-in will transition to the Error Handling or the Write case. If there is an error when trying to read from the input register, a "9999" value is displayed in FlexLogger so the user knows that a problem occurred without halting the plugin operation. 

 

  1. Modify the Write case of the Process.vi as shown in the images below:

 

This image shows the changes applied to the Write case of the Process VI.

 

This image shows the rest of changes applied to Write case of the process VI

 

According to the images above, the Read Latest Setpoints By Channel Identifier.vi has been placed inside of the Write case. This VI allows the plug-in to read data passed from the user through FlexLogger. This information is directly connected to the Write Single Holding Register.vi which allows writing this data to the Modbus Holding Register at address "1". The error out output of this VI is then connected to the case selector of a Case Structure, that controls whether the system needs to execute the Error Handling or the Read state. 

 

  1. Modify the Error Handling case of the Process.vi as shown in the images below:

This image shows the Error Handling case of the process VI.

This image shows the rest of the Error Handling case of the process VI

 

As presented in the images above, the Error Handling case uses the Shutdown.vi from the NI Modbus Library to clear the Modbus Master TCP reference that produced the error. Then, a new instance is created through the Create Modbus Instance.vi. The error out output of this function is connected to a Case Structure that determines whether the system executes the Read or the Error Handling case. 

 

  1. Save the changes on Process.vi and close it. 
  2. Open the Cleanup Session.vi from the Project Explorer Window. Edit the VI as presented in the image below:

 

This image shows how to configure the Cleanup Session VI. It contains the Shutdown VI from the NI Modbus Library to clear the Modbus Master reference

 

As presented in the image above, the Shutdown.vi is used to clear the Modbus TCP master instance as part of the shutdown sequence, that occurs when yo remove the plug-in from the FlexLogger project or close the project. 

 

  1. Repeat step 9 on the Finalize.vi. Please refer to the image below for more information:

This image shows the Finalize VI. The VI uses the Shutdown VI from the NI Modbus Library to release any Modbus references when the plug-in is removed from FLexLogger or the project is closed

  1. In the Project Explorer window, navigate to the Build Specifications. Right-click on the packed library and select Build. 

This image shows how to rebuild the Packed Library that contains the plugin after completing the chances 

 

  1. Launch FlexLogger and select File>>New>>Project to create a new project.

This image shows how to create a new project in FlexLogger

 

  1. Before adding your plug-in to FlexLogger, ensure there is a Modbus Slave already running on your host PC. You can run the Modbus Slave Example.vi that is installed with the NI Modbus Library and that can be found in the following directory C:\Program Files\National Instruments\<your_LabVIEW_Version>\vi.lib\NI\Modbus Library\Examples
  2. Navigate to Add channels >> Plug-in >> Modbus Demo to add the plug-in that was created through this guide to FlexLogger. 

This image shows how to add the Modbus Demo plugin that was created through this guide to FlexLogger 

 

  1. FlexLogger should display the channels that were added during the plug-in development. 

 

This image shows the plugin channels being displayed in NI MAX

If the communication between the Modbus Slave and the Modbus Demo FlexLogger plug-in is tested, the following behavior is observed:

 

  • If a new value is assigned to the Input Registers on the Modbus Slave, the information is updated in FlexLogger accordingly.

This image shows that if an input register value is modified on the slave, the value is updated in FlexLogger accordingly

 

  • If a value is manually entered for the Write Register channel in FlexLogger, the Modbus Slave updates the Holding Registers values accordingly after clicking on the Fetch Holding Registers button.

This image shows that the Holding registers values are updated after data is entered through the Write Register Channel on the Plugin

 

  • If the Modbus Slave Example VI is stopped, the plugin displays a "9999" value for the Read Register channel, meaning that there was a problem with the connection.

This image displays how a 9999 value is shown by the Read Register channel in the FlexLogger plugin after the Modbus slave Example VI is stopped.