Flow to Save Multiple Register Values

Estimated reading time: 2 minutes

Use Case for Saving Register Values from Multiple PLCs

  • Collect raw data from various PLC registers.
  • Aggregate the data at regular intervals.
  • Save the aggregated data for use by other applications.

Note: Even though data is collected at regular intervals, collection from each register does not happen simultaneously. In order to aggregate multiple values, separate processing blocks are needed to save values to global variables, which then can be accessed by all flows, functions, and nodes.

Example Flow for Saving Multiple Values

Goal: Collect data from different types of inputs and use multiple nodes in a flow to save values in a database or simply save values to a CSV file.

The following example saves register values to a comma-separated-values file. A similar method could be used to save values in a MySQL database.

Steps to Create a Flow to Save Values from Multiple Inputs

The procedure shown here is a high-level description of the steps that need to be taken. Use these steps as a basis for configuring a flow specific to your requirements.

See also…

A similar method can be used to save values to a MySQL database. See Save Multiple Register Values to MySQL.

To save values from multiple registers to a CSV file:

  1. Interrogate a PLC register for a value.
    1. Use a Datahub Subscribe node.
    2. Configure the node with a DeviceHub raw topic.
    3. This will be Output 1. The collected value will be the first global value to be saved, as described in Step 2.

  2. Wire a Function node to the Datahub Subscribe node.

  3. Edit the Function node and add the following lines to save the value to a Global Variable (output1), which can be accessed by other flows, nodes, and functions:

    var temp = (JSON.parse(msg.payload)).value;
    global.set("output1",temp);
    return msg;
    
  4. Repeat steps 1 through 3 for other PLC registers, resulting in Datahub Subscribe nodes: Output 2 through Output 4 (for this example).
    Note that in some cases, you may have a need to set a value to Null, as shown in the following example.

    var temp = (JSON.parse(msg.payload)).value;
    global.set("output4",null);
    return msg;
    
  5. Use an Inject node to inject a timestamp every 10 seconds to read the global variable values.

  6. Wire a Function node to the Inject node.
  7. Edit the Function node to set up the format for the CSV file.

    //create CSV
    var temp = global.get("output1") + "," + global.get("output2") + ","+global.get("output3") + ","+global.get("output4");
    msg.payload = temp;
    return msg;
    
  8. Wire a File node to the Function node and edit it, as shown below.
    Note: Be sure to Save the flow.

Configure the FTP Server Service

Once the CSV file has been populated, export the file via the OT Link Platform FTP Server Service. See FTP Server.