Skip to content

Application Development

To build the application (the code which actually does the data processing to comply with the application objectives), you must edit the file:

Python: $HOME/edgesdkexample/app.py

C#: $HOME/edgesdkexamplecsharp/app.cs

The app.py (taking python as example) application file looks like this:

import math
from classes.variablemodel import quality_enum


def app(logger, config, server, vars, db, event):

    while (True):
            #
            # wait for event
            #
            event.wait()
            event.clear()

            #
            ################## YOUR APPLICATION START HERE ###########################

            #
            # read required variables 
            #
            v1 = db.get_value("var1")
            v2 = db.get_value("var2")
            v3 = db.get_value("var3")

            #
            # do some calculations (example)
            #
            if v1.quality == quality_enum.OK and v2.quality == quality_enum.OK and v3.quality == quality_enum.OK:
                result1 = v1.value * 2.0
                result2 =(v1.value + v2.value + v3.value)/3
                result3 = math.sqrt(v1.value**2 + v2.value**2 + v3.value**2)

            #
            # Write back results
            #
            db.set_value("out1", result1, quality_enum.OK)
            db.set_value("out2", result2, quality_enum.OK)
            db.set_value("out3", result3, quality_enum.OK)

            #
            ################## YOUR APPLICATION ENDS HERE ###########################

Important

There are two (2) API calls in this code:

  1. db.get_value (tag_name) - Gets the last data scanned by the Modbus Client for such tag name.

    where:

    tag_name (string) - name of the variable (according to vars.json file configuration)

    This call returns a realtime_data object that has the following structure:

    realtime_data:
        value (object)  # value
        dtype (string)  # data type (boolean, integer, float)
        quality (enum)  # (OK, OLD, BAD, UNKNOWN)
        timestamp (datetime) # scan timestamp in UTC time
    
  2. db.set_value (tag_name, quality) - Set new value to that tag_name that must be transmitted out by the Modbus Client.

    where:

    tag_name (string) - Name of the variable (defined in vars.json). Tag must be configured as writable in vars.json.

    quality (enum) - The quality type to set the new data to. It can be either:

    quality_enum.OK,
    quality_enum.OLD,
    quality_enum.BAD,
    quality_enu.UNKNOWN