Version New_in |
---|
8.0.5 | Update Script
The Update Script event runs after a project is saved or updated on the Gateway. This enables you to insert a script that will run every time a project is saved.
Image Removed
Shutdown Script
The Shutdown Script event runs at the shutdown of the project, which means it can be used as a way to trigger a script when the Gateway has to be restarted. It allows you to run a piece of code as the shutdown is occurring. After the script completes, the shutdown will finish.
Note that the Shutdown Script event only gets called if the Gateway is requested to shut down: if the computer power is lost abruptly (power outage, hard restart, etc.) this shutdown script will not run.
Image Removed
Gateway Shutdown Behavior
Similar to how a Startup Script
Image Added
This script now reports which resources were modified during a project save. The following parameters have been added:
Parameter | Description | Type |
---|
actor | The user or system responsible for the project update. | String |
resources | A dictionary that holds the following keys: Key | Description |
---|
added | List of dictionaries containing information about resources that were added to the project. | removed | List of dictionaries containing information about resources that were removed from the project. | modified | List of dictionaries containing information about resources that were modified. | manifestChanged | A boolean variable indicating whether or not a change has been made to the project settings on the Gateway. |
| Dictionary |
Since multiple Timer Scripts can be added, there are separate buttons that allow you to manage each Timer Script.
Image Removed
Image Added Add Timer Script - Adds a new Timer Script.
Image Removed
Image Added Remove Timer Script - Will delete the selected Timer Script.
Image Removed
Image Added Modify Timer Script - Will modify the settings for the selected Timer Script.
Timer Script Settings
Image Removed
Image Added
Below is an overview of the settings for a Timer Script.
- Name: The name of the Timer script. Names must be unique per project, so two timer scripts in the same project cannot have the same name.
- Delay: The delay period in milliseconds. The meaning of this setting is dependent on the Delay Type setting.
- Enabled: Allows you disable the Timer Script when set to false.
- Delay Type: Determines how the Delay setting is utilized.
- A Fixed Delay timer script (the default) waits for the given Delay between each script invocation. This means that the script's rate will actually be the delay plus the amount of time it takes to execute the script. This is the safest option since it prevents a script from mistakenly running continuously because it takes longer to execute the script than the delay.
- Fixed Rate scripts attempt to run the script at a fixed rate relative to the first execution. If the script takes too long, or there is too much background process, this may not be possible. See the documentation for java.util.Timer.scheduleAtFixedRate() for more details.
- Threading: Determines which thread this script should run in. In other words, this setting allows you to specify if you want this timer script to share execution resources or not. The rule of thumb here is that quick-running tasks should run in the shared thread, and long-running tasks should get their own dedicated thread.
- The Shared setting means that all timer scripts will share a thread. This is usually desirable, as it prevents creating lots of unnecessary threads: threads have some overhead, so a small amount of resources are used per thread. However, if your script takes a long time to run, it will block other timer tasks on the shared thread.
- The Dedicated setting will create a separate thread specifically for the timer script to use. This setting is desirable when your scripts executions must be as consistent as possible, as other timer scripts can't slowdown or otherwise impact the execution of a script in a separate thread.
Tag Change Script Interface
Tag List
Lists all of the available Tag Change scripts in the project. Two icons are available below the list:
Image Removed
Image Added Add Script - Adds a new Tag Change Script to the list.
Image Removed
Image Added Remove Script - Removes the currently selected script from the list.
The Tags tab contains settings for the script. See the Script Settings description below
- Script Name - The name of the script. Script names must be unique per project.
- Enabled - Determines if the script is active or not. Set to false to disable the script.
- Change Triggers - When the Tag changes, the script can trigger based on the Value, Quality, and/or Timestamp. Note that regardless of how many triggers changed, the script only executes once per tag, so leaving all triggers enabled will not trigger three executions each time the Tag changes.
- Tag Paths - A list of Tag paths to monitor. When any of the Tags listed in this area change, the script will trigger. Note that the list is not comma separated: new paths are specified each line.
New_in |
---|
|
As of release 8.0.5, wildcards can be used at the . For example, [provider]folder/*.
Image RemovedScript Tab
The Script tab is where the Python script associated with this event will be placed. Two icons are available below the list:
Image Removed Add Script - Adds a new Tag Change Script to the list.
Image Removed Remove Script - Removes the currently selected script from the list.
Image RemovedTag Change Objects
Tag Script Tab
The Script tab is where the Python script associated with this event will be placed.
Image Added
Tag Change Objects
Tag Change Scripts contain several built-in objects that are useful for inspecting the event, such as seeing what value the Tag changed to. These objects are listed below
: Panel |
---|
borderStyle | noneA variable that is a flag (0 or 1) which indicates whether or not the The boolean initialChange variable indicates if an event is due to
the or not. This is useful as you can filter out the event that is the
inital initial subscription, preventing a script from running when the values haven't actually changed.
Code Block |
---|
|
if not initialChange:
# Do something useful here |
The
newValue executionCount Value
An integer representing a number of event executions since gateway scripts were restarted (typically by applying a change to a script and saving the project).
Code Block |
---|
|
if executionCount <= 1:
pass |
The newValue Object
A QualifiedValue object that
contains the following methodsrepresents the current value on the tag.
Method | Description | Usage Example |
---|
getValue() | Returns the new value on the tag | newValue.getValue() |
getQuality() | Returns the new quality on the tag | newValue.getQuality() |
getTimestamp() | Returns the new timestamp value | newValue.getTimestamp() |
The
event This object offers some additional utility, such as accessing the previous values on A QualifiedValue object that represents the previous value of the tag.
Method | Description | Usage Example |
---|
getCurrentValue a QualifiedValue object (similar to the newValue object), representing the new values the previous value on the tag |
.event.getCurrentValue()getPreviousValue a QualifiedValue object, representing the values the previous quality on the tag |
before the change.eventgetPreviousValue.getValuegetTagPath | Returns the previous timestamp value | previousValue.getTimestamp() |
Returns a TagPath object, that can be further examened for details about the path The Event Object
This object offers some additional utility, such as accessing the previous values on the tag
that changed. See the TagPath Object table below. Additionally, the TagPath object can easily be turned into a string, providing quick access to the path of the tag that changed value.event.getTagPath() | getValue() | Returns the new value on the tag, similar to getCurrentValue(). This method is a convenient way to retrieve just the new value, without needing to interact with the QualifiedValue object returned by getCurrentValue(). | event.getValue() |
The TagPath Object
These methods are available on the TagPath object returned by event.getTagPath()
calls
Method | Description | Usage Example |
---|
getItemName() | Returns the name of the item at the end of the path, which can be used to get the name of the tag that changed.
Method/Attribute | Description | Usage Example |
---|
getCurrentValue() | Returns a QualifiedValue object (similar to the newValue object), representing the current value on the tag. | event.getCurrentValue().getValue() |
getPreviousValue() | Returns a QualifiedValue object, representing the values on the tag before the change. | event.getPreviousValue().getValue() |
getTagPath() | Returns a TagPath object, that can be further examined for details about the path on the tag that changed. See the TagPath Object table below. Additionally, the TagPath object can easily be turned into a string, providing quick access to the path of the tag that changed value. | event.getTagPath() |
.getItemNameSecurity - Allows you to specify security zone and role combinations that are allow to request this message handler. The Payload
Inside the message handler is your script. The script will have a single object available to it, the payload. The payload is a dictionary containing the objects that were passed into it. In essence, the payload is the mechanism that allows you to pass the message handler values.
The payload is simply a python dictionary, so extracting values involves specifying the key:
Code Block |
---|
language | py |
---|
title | Pseudocode - Payload Values |
---|
|
value1 = payload["MyFirstValue"] #"MyFirstValue" is the key that is associated with a value. We are taking the value associated with MyFirstValue, and assigning it to value1.
value2 = payload["MySecondValue"] #Similarly, we are taking the value associated with MySecondValue and assigning it to value2. |
Calling Message Handlers
Once you have your message handlers created, you can then call them from a script using one of three scripting functions: system.util.sendMessage, system.util.sendRequest, and system.util.sendRequestAsync. These functions allow you to call a message handler in any project, even if the project that the message handler resides on is different from the one you are calling it from. The message handler will then execute in the scope in which it was created, and will use any parameters that you pass in through the payload. Code Block |
---|
language | py |
---|
title | Pseudocode - Calling a Message Handler |
---|
|
project="test"
messageHandler="My Message Handler"
myDict = {'MyFirstValue': "Hello", 'MySecondValue': "World"}
results=system.util.sendMessage(project, messageHandler, myDict) |
Scroll html ignore |
---|
Iulink |
---|
URL | https://inductiveuniversity.com/video/script-messaging |
---|
Name | Script Messaging |
---|
|
getParentPath() | Returns the path to the Tag's parent folder. | event.getTagPath().getParentPath() |
Scroll html ignore |
---|
Iulink |
---|
URL | https://inductiveuniversity.com/video/tag-change-scripts |
---|
Name | Tag Change Scripts |
---|
|
|
Message Scripts
Message Handlers allow you to write a script that will run in the scope they are located in, but they can be invoked by making a call from other projects or even other Gateways. They can be called using three different scripting functions: system.util.sendMessage, system.util.sendRequest, and system.util.sendRequestAsync.
Image Removed
Under the list of handlers, three small buttons allow you to add, remove and manage your handlers.
Image Removed Add Message Handler - Will add a message handler.
Image Removed Remove Message Handler - Will delete the highlighted message handler.
Image Removed Modify Message Handler - Will modify the settings for the highlighted message handler.
Gateway Message Handler Settings
When adding or modifying a message handler, a Message Handler settings window will popup.
Image Removed
The following settings are available:
Name - The name of the message handler. Each message handler must have a unique name per project. Threading - Determines the threading for the message handler. Contains the following options:- Shared - The default way of running a message handler. Will execute the handler on a shared pool of threads in the order that they are invoked. If too many message handlers are called all at once and they take long periods of time to execute, there may be delays before each message handler gets to execute.
- Dedicated - The message handler will run on its own dedicated thread. This is useful when a message handler will take a long time to execute, so that it does not hinder the execution of other message handlers. Threads have a bit of overhead, so this option uses more of the Gateway's resources, but is desirable if you want the message handler to not be impeded by the execution of other message handlers.
Returns a QualifiedValue object (similar to the newValue object), representing the current value on the tag. This method is functionally identical to getCurrentValue(), and maintained mostly for backwards compatibility reasons. | event.getValue().getValue() |
changes | A RegularEnumSet typed attribute that describes what changed: the value, quality, or timestamp. Values in the set are TagChangeType objects, which can be converted to string with either Python's built-in str() or Java's toString(). | Code Block |
---|
| for i in event.changes:
if i.toString() == "ValueChange":
foo() |
|
tagPath | An attribute that describes the tag path on the tag that changed. Method/Attribute | Description | Usage Example |
---|
getItemName() | Returns the name of the item at the end of the tag path, which can be used to get the name of the tag that changed. | event.tagPath.getItemName() | getParentPath() | Returns the path to the Tag's parent folder. | event.tagPath.getParentPath() |
|
|
Gateway Scheduled Scripts
Scheduled scripts are events that execute at fixed times of the day, based off of the Gateway's system time. Configuration for the event is split between two tabs: Settings and Script .
Image Added
Settings Tab
The settings tab allows you to give the event a unique name and determine how often it executes. Schedules are driven by cron job scheduling.
The Common Settings dropdown contains several common selections, which can be further modified with the fields and dropdowns under each unit of time.
Each unit of time consists of a field, and corresponding dropdown. The dropdown is filled with suggestions and simple options, but more complex values can be provided in the field on the left. See Crontab Formatting Reference.
Script Tab
The script tab houses the Python script that will execute when the scheduled event executes.
Troubleshooting Gateway Scripts
While they are technically project resources, remember that Gateway Event Scripts technically run on the Gateway. Thus the Status section of the Gateway is useful for diagnosing issues with Gateway Event Scripts.