Top  | Previous | Next

Tag Change Scripts

Tag Change scripts are available in both Gateway and Client scopes. Each tag change script can be given a list of tag paths. Whenever one of these tags changes, the tag change script will execute. They will also get an initial execution whenever the scripting system starts up.

 

Each tag change script can be given a name for organizational purposes. To specify multiple tag for a given script, enter them one per line in the tag paths text area. To quickly import many tags, you can drag-and-drop tags from the SQLTags Browser window onto this text area.

 

These scripts receive three special variables in their namespace when they are run: event, initialChange and newValue. The intialChange variable is a flag (0 or 1) that indicates whether or not this event is due to initially subscribing or not. The event variable is a TagChangeEvent object, which itself contains the properties: tag, tagPath, and tagProperty. The third, newValue, is the new value for the tag property that is subscribed. These values are objects themselves that contain a value, quality, and timestamp. The following example script should be a good starting point.

Example

print "Received tag change event for %s" % event.tagPath

 

value = newValue.value

quality = newValue.quality

timestamp = newValue.timestamp

 

print "value=%s, quality=%s, timestamp=%s" %(value, quality, timestamp)

 

Tip: The TagPath object that you access via event.tagPath is itself a complex object. You can turn it into a string if you want the whole tag path by using the str() function. You can also access individual parts of the tag path. The most useful is usually the itemName property, which is the name of the tag represented by the path. To get the name of the tag, you can use event.tagPath.itemName.