Reading a Finder 6M series via Modbus RTU with Finder OPTA in CODESYS

Learn how to configure Finder OPTA in CODESYS to read data from a Finder 6M series via Modbus RTU.

Guide and Tutorial | Reading a Finder 6M series via Modbus RTU with Finder OPTA in CODESYS

Reading a Finder 6M series via Modbus RTU with Finder OPTA in CODESYS

Learn how to configure Finder OPTA in CODESYS to read data from a Finder 6M series via Modbus RTU.

Overview

Finder OPTA is equipped with an RS-485 port that allows communication with devices compatible with the Modbus RTU protocol, such as the Finder 6M series. In this tutorial, we will show step-by-step how to configure Finder OPTA in CODESYS to correctly read data from a Finder 6M series power analyzer.

Goals

  • Configure Finder OPTA via Ethernet to read registers from a Finder 6M series in CODESYS
  • Read registers from a Finder 6M series via Modbus RTU in CODESYS

Requirements

Before you begin, make sure you have:

To follow this tutorial, you will need to connect the Finder 6M series power analyzer to the power supply and provide a suitable load. You will also need to power Finder OPTA with a 12-24VDC/500mA power supply and properly configure the RS-485 serial connection. The diagram below shows the correct configuration of the connections between Finder OPTA and the Finder 6M series.

Connecting Opta and Finder 6M

The Modbus configuration of the Finder 6M series is determined by the position of the DIP switches, as indicated on page 6 of the user manual. In this tutorial the expected communication parameters are:

  • Modbus address: 1.
  • Baudrate: 38400.

We can set these values by setting both DIP switches of the Finder 6M series to the UP position, as shown in the figure below.

Finder 6M series diagram

Instructions

Creating a CODESYS Project

Open CODESYS.

Open CODESYS

Create a new project and choose Standard Project.

New project

Make sure the device is Finder Opta, then select the programming language (we will use ST).

Standard project

Identifying Finder OPTA via Ethernet

Now double-click on the Device (Finder Opta) entry in the Devices menu, a tab will open as shown below.

Device

Press the Scan Network button and ensure Finder OPTA device appears under the Gateway, then press OK.

Scan Network

Modbus Configuration

At this stage, we configure the RS-485 port and Modbus protocol parameters to ensure Finder OPTA can communicate with the Finder 6M series.

Right-click on Device (Finder Opta) and select Add device....

Device Menu

Now configure the Modbus RTU protocol on the RS-485 port of Finder OPTA. From the list select Modbus COM Port and click Add device.

Add Modbus COM port

Now set the serial port configuration values as follows:

  • COM port: 2, i.e., the RS-485 port of Finder OPTA.
  • Baud rate: 38400.
  • Parity: NONE.
  • Data bits: 8.
  • Stop bits: 1.

Set Modbus COM port

After setting the serial port values, right-click on Modbus_COM_Port(Modbus COM Port) and then on Add device.

Modbus COM port menu

From the list select Modbus Client, COM Port and click Add device. In this way you add a Modbus client communicating on the previously configured serial port, i.e. the Finder 6M series.

Add Modbus client

Then right-click on the newly added item Modbus_Client_COM_Port(Modbus Client, COM Port) and click Add device.

Modbus client menu

Select Modbus Server, COM port, then Add device to specify that the Finder 6M serie will act as server, while the Finder OPTA will act as client.

Add Server Modbus

Now click on the newly added item and make sure the Server address is set to 1, the Modbus address of the Finder 6M series.

Set Server Modbus

Finally, we configure a Modbus server channel, meaning we set the parameters that will be used by the program to read from the Finder 6M series. In the same screen click on Modbus Server Channel then on Add channel at the bottom right. In this tutorial we read the frequency value from the Finder 6M series. As defined in the device technical manual, the frequency value is stored in Input Registers 40085 and 40086 in float format. Therefore, set the channel values as follows:

  • Name: Frequency.
  • Access type: Read Input Registers (Function code 4).
  • Trigger: Cyclic.
  • Cycle time: 1000, meaning one read per second.
  • Offset: 84.
  • Length: 2.
  • Error handling: Keep last value.

The Finder 6M series technical manual counts addresses starting from 1 while CODESYS starts from 0. For this reason, to access Input Register 40085, we set the offset to 84.

Add Channel

After pressing OK, you will see the summary of the newly configured channel.

Set Channel

Preparing the ST Program

Now we write the ST program that reads the frequency value.

This program directly accesses the variable's memory address and interprets the content as a float value. This step is essential to obtain the actual measurement stored in the device and transform it into a readable and usable format. In CODESYS, the float format is denoted as REAL.

In the sidebar, click on PLC_PRG (PRG).

PLC PRG

At the top of the editor - section dedicated to variables declaration - insert the following code:

PROGRAM PLC_PRG
VAR
    words: ARRAY[0..1] OF WORD;
    ptr: POINTER TO REAL;
    frequency: REAL;
END_VAR

Program Variables

At the bottom of the editor - section dedicated to program logic - insert the following code:

// Interpret as float
ptr := ADR(words);
frequency := ptr^;

Program Code

Now it is necessary to associate the program variables with the Modbus channel, so that the variables contain the values read from the channel.

In the sidebar, double-click on Server_Modbus_COM_port. Now click on the section ModbusGenericSerialServer mapping I/O and in the table double-click the Variable cell to display the option button.

Add mapping

Click the options button to display the list of variables, expand Application and then PLC_PRG to access the variables previously defined in the ST program. Now click on the words variable and press OK to assign it to the Frequency channel.

Variable association

The summary shows the variable assigned to the Frequency channel. From now on, the variable words contains the bytes read from the registers of the Finder 6M series, representing the frequency value measured by the device. It's our ST program that transforms these bytes in float.

Variable Summary

Uploading the Program to Finder OPTA

At this stage, we download the program and the hardware configuration to Finder OPTA, so that it executes the code we just wrote, returning the frequency value read by the Finder 6M series.

Download the program and configuration to the device by pressing the green button at the top labeled Login.

Login

Once the download is over, the program will be downloaded on Finder OPTA. Execute it by pressing the Start button.

Start

The PLC_PRG tab displays the frequency value in real time, stored in the frequency variable, in this case 49.94 Hz.

Working

Conclusions

By following these steps, you have performed a Modbus RTU read from the registers of a Finder 6M series using Finder OPTA in CODESYS.

If you encounter issues, verify that the devices are wired correctly and that the Modbus parameters are configured as specified in the tutorial.