- Start by creating a new project in LabVIEW:
- Launch LabVIEW (64-bit).
- Click on Create Project.
-
- Select FlexLogger IO Plug-in from the list of templates.

-
- 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.

- Prepare the Initialize.vi so the plug-in can read from one Modbus address and write to a different one:
- Open Initialize.vi and remove the Set Plugin Resample VI and Write Parameter VI. Press <Ctrl-B> to remove the broken wires.
- Remove the constants that are not connected to a VI.
- Modify the block diagram as shown in the image below:
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.
- 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.
- Delete the current Read Parameter.vi and press <Ctrl-B> to remove the broken wires. Remove the constants and the free labels as well.
- Place a Create Modbus Instance.vi on the block diagram. Configure the IP address of the Modbus device you will be connecting to.
- 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.
- 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.

-
- Press <Ctrl-V> to paste the TCP master instance indicator created in step c.
- Create an Enum control on the private data (.ctl) front panel, and include the following options. You can change its name to Modbus States:
-
- Right-click on the Modbus States Enum, and select Make Type Def.
- Modify the Cluster of class private data as shown in the image below:

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

- Open the Process.vi and delete the current contents except from the controls and indicators. Modify the VI as shown in the image below:
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.
- Modify the Read case of the Process.vi as shown in the images below:


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.
- Modify the Write case of the Process.vi as shown in the images below:


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.
- Modify the Error Handling case of the Process.vi as shown in the images below:


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.
- Save the changes on Process.vi and close it.
- Open the Cleanup Session.vi from the Project Explorer Window. Edit the VI as presented in the image below:

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.
- Repeat step 9 on the Finalize.vi. Please refer to the image below for more information:

- In the Project Explorer window, navigate to the Build Specifications. Right-click on the packed library and select Build.
- Launch FlexLogger and select File>>New>>Project to create a new project.

- 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
- Navigate to Add channels >> Plug-in >> Modbus Demo to add the plug-in that was created through this guide to FlexLogger.
- FlexLogger should display the channels that were added during the plug-in development.
