Send data that is input from a Modbus TCP-compatible device at regular intervals

This section describes the processing of sending data that is input from a Modbus TCP-compatible device at a specified interval.

This process outputs results such as the following:

Example

The values of the script variable are sent to an external system at an interval longer than the input interval of the Modbus TCP-compatible device.

Description of the processing

Create a script to send data that is input from a Modbus TCP-compatible device to an external destination at a specified interval that is different from the input interval.

For example, if data is input from a sensor at an interval of 0.01 seconds, and that data is sent to an external destination at the same interval, there is a danger of the data volume becoming excessively large. As a countermeasure, create the following streams in one script.

  • Using "script variable" of HULFT IoT EdgeStreaming, the input from the Modbus TCP-compatible device is received by a script variable.

  • The values of the script variables are then sent to an external system at an interval longer than the input interval of the Modbus TCP-compatible device.

= Remarks =

The optimal interval at which the obtained data is sent to the external system is determined by the required granularity of the data for visualization and analysis that are performed in the subsequent systems.

Key features

Read holding registers

This component can be used to set the properties to read the holding registers.

It can be set from Industrial equipment > Modbus > Read holding registers of the tool palette.

Periodic event

This component can be used to set the interval at which events are executed.

It can be set from Basic > Basic > Periodic event of the tool palette.

Send operation

This component can be used to set the properties of the Send operation.

It can be set from Generic protocol > HTTP > Send of the tool palette.

Operation procedure

In this example, a script that sends temperature data to the external system at one-minute intervals is created.

1. Place an operation that reads the holding register values from Modbus TCP-compatible devices.

  1. Drag and drop Industrial equipment > Modbus > Read holding registers from the tool palette onto the script canvas.

    The New Read holding registers operation dialog box is displayed.

  2. Configure the settings to read the holding register values from Modbus TCP-compatible devices.

    Name

    Enter any value (single-byte alphanumeric characters, underscores).

    Destination

    Click Add in the connection destination list to display the New Modbus TCP connection settings dialog box.

    Host

    Enter the host name or IP address of the Modbus TCP-compatible device that you want to connect to.

    Port

    Enter the port number of the Modbus TCP-compatible device that you want to connect to.

    Timeout

    Enter the timeout value for the Modbus TCP-compatible device that you want to connect to.

    Data-holding format

    Select the data-holding format of the Modbus TCP-compatible device that you want to connect to.

    Click Finish.

    You are returned to the New Read holding registers operation dialog box.

    Slave ID

    Enter the slave ID of the Modbus TCS-compatible device that you want to connect to.

    Interval

    Enter the interval at which to get values from the holding registers.

    In this example, "0.01" is entered.

    Starting address

    Enter the starting address of the holding registers that you want to read.

    Number of registers

    This number is automatically set when you set the data type.

    Data type

    Select the type of the value set in the holding register.

    In this example, the temperature data is assumed to be used. Therefore, select Single-precision real number.

    Name

    Set any value to represent the data that can be obtained from the line.

    = Remarks =

    This name is only used for display on the screen.

  3. Click Finish.

    The Read holding registers operation icon appears on the script canvas.

2. Save the values obtained from Modbus TCP-compatible devices and create script variables to be used for reference when sending data to an external destination.

  1. Right-click a script in Project Explorer and select New > Script variable from the menu.

    The New Script variable dialog box is displayed.

  2. Set the script variables.

    Variable name

    Enter any value (single-byte alphanumeric characters, underscores).

    Variable type

    Select the data type that you want to save or view.

    In this example, Floating point number is selected to save or view the temperature data obtained from the temperature sensor.

    Initial value

    Enter the default value of the script variable.

    In this example, "0" is entered.

  3. Click Finish.

    The script variable is displayed directly under the script.

3. Set a Mapper.

  1. Drag and drop Conversion > Basic > Mapping from the tool palette onto the script canvas.

  2. Drag and drop the Read holding registers operation icon onto the mapping_1 icon.

    A stream flow is now drawn from Read holding registers operation to Mapping.

4. Save the values to the script variables.

  1. Double-click the mapping icon to open the Mapper editor.

  2. Drag and drop hr_05000_05001 of the input source onto temperature of the output destination.

    The element hr_05000_05001 and the script variable temperature are connected by a mapping link.

    The configuration for mapping_1 is now completed.

 

In the previous procedure, we created a stream processing to obtain temperatures from the holding registers of Modbus TCP-compatible devices and save them to script variables.

5. Create a stream processing to get values from script variables and send them to an external system with REST API at regular intervals.

  1. Drag and drop Basic > Basic > Periodic event from the tool palette onto the script canvas.

    The New Periodic event operation dialog box is displayed.

  2. Set the interval at which to send data to the external system.

    Name

    Enter any value (single-byte alphanumeric characters, underscores).

    Interval

    Enter the interval at which to send values to the external system (unit: seconds).

    In this example, "60" is entered

  3. Click Finish.

    The Periodic Event operation icon is placed on the script canvas.

  4. Drag and drop Generic protocol > HTTP > Send from the tool palette onto the script canvas.

    The New Send operation dialog box is displayed.

  5. Configure the settings of the REST API of the external system.

    Name

    Enter any value (single-byte alphanumeric characters, underscores).

    Input data

    Select the icon name of the Periodic Event operation that you placed earlier.

    URL

    Set the URI for REST API.

    Method

    Set the HTTP method (POST or PUT) for REST API.

    Header

    Set the request header that is necessary to send a request to REST API.

  6. Click Finish.

    The Send operation icon is placed on the script canvas.

    The Periodic Event operation icon and the Send operation icon are connected by a stream flow (an orange dashed line).

  7. Right-click the stream flow that connects Periodic Event operation to Send operation, and select Add mapping from the menu.

    Mapper is placed in between Periodic Event operation and Send operation.

  8. Double-click the mapping_2 icon placed earlier to open the Mapper editor.

  9. In Output destination, set the input schema of the Send operation.

    = Remarks =

    For the configuration methods, refer to Transfer collected file data using HTTP.

    In this example, set the schema as follows:

6. Drag and drop temperature of the Input source onto temperature of the Output destination.

7. Save the script.

For information about how to save a script, refer to First Step Guide.