SubscribeToTag
Called to subscribe to a notification of a state change of a tag.
Function
number SubscribeToTag(name: string, updateRate: number, equipment: object, callback: function);
Parameters
Name | Type | Description |
---|---|---|
name | String | The tag name, this must exist within the tag manager. The name is case sensitive |
updaterate | Number | The number of milliseconds that represents the desired update rate of the subscription |
equipment | Object | An object that is associated with the subscription, this object will be the ’this’ reference within the callback function. If no object is required then ’null’ may be passed, this will cause the ’this’ reference to refer to the global object |
callback | Function | Reference to the callback function that will be invoked when an update occurs |
Return Value
A numeric identifier that is unique for this subscription, it may be saved for later use. It a required parameter of the function used to unsubscribe to updates
Example
Subscribe to a tag, then change its value, invoking the callback:
var _tag1;
function OnSimulationStart()
{
//-- subscribe to tag
_tag1 = SubscribeToTag("Tag1", 500, null, Tag1ValueChanged)
//-- set value = 5
SetTagValue(_tag1, 5);
}
function Tag1ValueChanged(name, id, value, quality)
{
if(quality == 192) // GOOD
{
LogDebug("New value for " + name + ": " + value)
}
else
{
LogError("Tag '" + name + "' has a bad quality: " + quality)
}
}
function OnSimulationStop()
{
//-- example to unsubscribe to Tag1
UnSubscribeToTag(_tag1);
}