You are here: Core Reference > Coding > Scripting > Using a Script to Access Aggregates

Using a Script to Access Aggregates

You can use a script to access the aggregates (and aggregate properties) of database items. This is especially useful for setting historic features and changing certain configuration settings via a script.

Example:

The following example can be used to locate a channel and change its connection type to serial by accessing the ConnectionPoint aggregate. For this example, a Modbus channel is used (this would require the Simple Modbus driver to be installed on a 'real' system).

  • Sub SetConnTypeSerial()
    • Set modbusChan = Server.FindObject(Server.ThisObject.Parent.FullName & ".Modbus Channel 1")
    • modbusChan.Interface.ConnectionPoint = 0
    • comPort = InputBox("Please enter a valid COM Port:")
    • modbusChan.Interface.ConnectionPoint.Port = comPort
  • End Sub

Where:

  • Set modbusChan = Server.FindObject(Server.ThisObject.Parent.FullName & "Modbus Channel 1") is used to search for the database item named 'Modbus Channel 1'. The script is set to search in the same Group as the Mimic that contains the script (it searches in the Parent Group of the current object, which is the Mimic that contains the script). The ServerObject that is returned by the FindObject function is stored in the variable named 'modbusChan'.
  • modbusChan.Interface.ConnectionPoint = 0 is used to access the ConnectionPoint aggregate of the 'Modbus Channel 1' database item (the 'Modbus Channel 1' database item is a channel and is represented by the ServerObject that is stored in the modbusChan variable).
  • comPort = InputBox("Please enter a valid COM Port:") is used to display a prompt window. The prompt window requests that the user enters a valid COM port. The entry that is made by the user is stored in the comPort variable.
  • modbusChan.Interface.ConnectionPoint.Port = comPort sets the Port parameter for the ConnectionPoint aggregate of the 'Modbus Channel 1' item. The Port parameter is set to be the same as the user entry that is stored in the comPort variable.

ClearSCADA 2015 R2