Skip to content

Communication driver

Models the communication with the gateway in order to connect to different software.

Mandatory children

  • type: The type of driver. Each driver has its required setup data.
  • enable: Enable or disable the driver.
    • Var: smtk_bool
    • Doc: (bool)
    • Type: input
    • Default value: false
  • setup_data: Setup for the driver in JSON (more info below).
    • Var: smtk_string
    • Type: input
    • Default value: {}
  • update_input: Update the inputs to the driver from the system in JSON. It contains the variables names as keys and their values.
    • Var: smtk_string
    • Type: input
    • Default value: {}
  • update_output: Update the outputs from the driver to the system in JSON. It contains the variables names as keys and their values.
    • Var: smtk_string
    • Type: output
    • Default value: {}
  • status: The status of the driver (connecting, connected, standby, running, error).
    • Var: smtk_string
    • Type: output
    • Default value: none
  • info: Debug messages from the driver.
    • Var: smtk_string
    • Type: output
    • Default value: none

Setup data

The setup data is a JSON string that must contain two mandatory items:

Parameters

These values exposes the configuration or context used by the drivers to connect to other platforms. All the drivers share two common parameters (rpi and force_write) and each of them can also defined their own ones.

The parameters are defined by a dict that may include several items following the next format {parameter_name: parameter_value}, i.e:

{
    "rpi": 35, // Common ->  How often vars are read and write in ms. Default = 50.
    "force_write": 0.5, // Common ->  Used to periodically (in s) re-write variables. Default = 1.0.
    "ip": "192.168.0.1", // Driver specific
    "port": 1234 // Driver specific
}

Variables

These are the variables to be accessed in the controller, read and written through the driver. They are defined by a dict that may include several definitions following the next format {address: {'datatype':str, 'size':int, 'operation':str}:

  • address (str): It can be used as name, tag, id, or simply to identify the variable.
  • datatype (str): It is used to define the variable data type (bool, byte, int, word, dword, qword, float, str).
  • size (int): It defines if the variable is an array. If not defined it is asumed is not an array or dimension 1.
  • operation (str): It defines if the variable should be written or read by the driver in the controller (read, write).

An example of two variables input and output definition:

{
    "input": {
        "datatype": "byte", 
        "size": 1, 
        "operation": "write"
    },
    "output": {
        "datatype": "byte", 
        "size": 2, "operation": "read"
    }
}

Result

Now, combining these two blocks together, a complete SETUP msg would look like the following example:

{
    "parameters": {
        "rpi": 35,
        "force_write": 0.5,
        "ip": "192.168.0.1",
        "port": 1234
    },
    "variables": {
        "input": {
            "datatype": "byte", 
            "size": 1,
            "operation": "write"
        },
        "output": {
            "datatype": "byte", 
            "size": 2, 
            "operation": "read"
        }
    }
}

Tip

You will find specific examples of the setup_data, update_input and update_output in the different drivers documentation