Creating Scripts

For general information on how to create a script, see Step-by-step > Configuring a Project > Configuration Workflows & Procedures > Configuring Scripts.

Copy an Example from the Library

  • The Scripts extension module is installed.
  • Two virtual data points are created for calculated values (for example: Average of two OPC data points). Refer to the Virtual Objects description for additional information.
  1. In System Browser, select Management View.
  1. Select Project > System Settings > Libraries > L1-Headquarters > BA > Software > Desigo Gateway Functionality Scripts > Scripts.
  1. Select the Script Editor tab.
  • The example scripts SXOpenMainScript, SXOpenFunction, SXOpenParser are displayed.
  1. Select the SXOpenMainScript.
  1. Open the Viewer expander.
  1. Select the Script Editor tab.
  1. Press CTRL+A to highlight all the content and CTRL+C to copy it.

Creating and Saving a Script

  • A new folder is created to save the Gateway Script.
  1. In System Browser, select Application View.
  1. Select Applications > Logics > Scripts.
  1. Select the Script Editor tab.
  1. Open the Editor expander.
  1. Delete the default entries.
  1. Press CTRL+V to paste content.
  1. Click Save As .
  1. In the Save object as dialog box, enter the name and description.
  1. Click OK.

When Does the Script Path Need to be Changed

The script path must be changed if the Scripts SXOpenFunction and SXOpenParser are modified for a project. The variable ConsoleOutput=true displays the results in the Console expander.

Script Path

Apply SXAdd Function with COV

The examples in the library were created for the communications from OPC to BACnet. The value (3) in Present_Value must be changed for communications from BACnet to OPC.

SXAdd Function with COV
  • The OPC and BACnet data points are imported.
  • The script is opened in System Manager in the Editor expander.
  1. In System Browser, select logical view.
  1. In the Editor expander, select the predefined function SXAvg and copy the template to the script.

Data Points Configuration

  1. Enter a unique subscription number (1) as a description.
  1. Drag the OPC data point from System Manager to the first subscription (2).
  1. (Optional) Another property can be defined instead of the default property Value (3).
  1. Enter the function using the corresponding description number (4). This number must be unique throughout the script. The Script editor does not check the numbers for uniqueness.
  1. Do not change the entry false (5).
  1. Drag the BACnet data point from System Manager to the first subscription (6).
    NOTE: A virtual data point can be assigned instead of a BACnet data point.
  1. Enter the calculation function (7) SXAdd.
  1. Enter an offset (8) to the data point value.

Editing Additional Data Points

  1. Create another SXAdd subscription or select a new script function.
  1. Repeat the steps as described in Data Points Configuration.
  1. Delete unneeded functions from the script.

Applying SXAvg Function with COV

The description is based on three OPC data points.

SXAvg Function with COV
  • The preconditions are described in SXAdd.
  1. In the Editor expander, select the predefined function SXAvg and copy the template to the script.
  1. Enter a unique subscription number (1) as a description.
  1. Enter a unique function number (2).
  1. Drag the OPC data point from System Manager to the first subscription (3).
  1. (Optional) Another property can be defined instead of the default property Value (4).
  1. Enter the function using the corresponding description number (5). This number must be unique throughout the script. The Script editor does not check the numbers for uniqueness.
  1. Do not change the entry false (6).
  1. In variable 1, enter the parameter (7) for the subscription data point (3).
  1. Drag the OPC data point from System Manager to the second variable (8).
  1. Drag the OPC data point from System Manager to the third variable (9).
  1. Drag the BACnet data point from System Manager to the first subscription (10).
    NOTE: A virtual data point can be assigned instead of a BACnet data point.
  1. Enter the calculation function (11) SXAvg.
  1. Enter the number (12) of data point values for calculation.
  1. The number of assigned data point variables (13) must match the numbers of variables (12). The remaining variable must be set to 0.

NOTE:
The average is only calculated if the value of the first subscription changes. Use the polling function to perform continuous averaging.

Applying the SXBetween Function with Polling

The examples in the library were created for communications from OPC to BACnet. The value (4) in Present_Value must be changed for communications from BACnet to OPC.

OPC Polling SXBetween
  • The preconditions are described in SXAdd.
  1. In the Editor expander, select the predefined function SXBetween and copy the template to the script.
  1. Enter a unique function name (1) as a description. The function name must be unique throughout the script.
  1. Enter the polling rate (2) in milliseconds. All data points assigned to this function are polled at the same polling rate.
  1. Drag the OPC data point from System Manager to the first read line (3).
  1. (Optional) Another property can be defined instead of the default property Value (4).
  1. Drag the BACnet data point from System Manager to the first read line (5).
  1. Enter the calculation function (6) SXBetween.
  1. Enter the minimum and maximum limit value (7) of the data point value for calculation.
  1. Create additional data points (lines 2 to 4) in this function or create a new function with a different polling rate.