ContentThis section contains information about how to use remote tags methods.
The Remote Tags API allows the application to consume directly Assets and Tags defined in remote system such as OSIsoft PI System or OSIsoft PI AF (Asset Framework).
You can use that functionality in two ways:
The Drawing Tool object "Remote Assets" will display automatically the remote asset tree, and the configuration on DEVICES, as describe below, is executed.
There are methods on the Script which allows the dynamic binding to consume the remote data model.
In order to use the Remote Tag API, you need to make sure some requirements are met.
Feature Requirements
Project Settings
To enable the RemoteAssets
and RemoteTags
features in your Project, you must be configured for the Enterprise Family. To do so, go to Info → Settings, and select the correct family.
Otherwise, you may see an error message on your TraceWindow Logs, as shown in the image.
Device Configuration
In the Devices → Channels tab, create a new Channel for the desired communication protocol. Configure the ProtocolOptions
field with the necessary information if the driver requires it.
In the Devices → Nodes tab, create a node, assign it to our newly created channel, and fill in the Station
parameters as required by the driver.
There is no need to create communication Points when using the Remote Tags and Assets feature.
Server Startup Task
On Scripts → Tasks, select the default ServerStartup
task, and go to its Code Editor environment. Add the following call method:
The following code block defines a function that sets up the device node for RemoteTags and RemoteAssets services. It should only be invoked during the ServerStartup task and expects two parameters: the device node name for RemoteTags and the device node name for RemoteAssets.
Code Block |
---|
|
@Server.SetRemoteDeviceNode(string deviceNodeNameTags, string deviceNodeNameAssets) |
Code Block |
---|
|
string nodeRemoteTags = @Device.Node.<NodeForRemoteTags>.GetName();
string nodeRemoteAssets = @Device.Node.<NodeForRemoteAssets>.GetName();
@Server.SetRemoteDeviceNode(nodeRemoteTags, nodeRemoteAssets); |
This call method will enable some predefined methods available for Remote Tags and Assets in the chosen Node. These methods are described in the next sections.
RegisterElementToTag
This runtime method allows you to map a whole RemoteAsset remote asset to a Tagtag. In order to do this, you need to create a Template with the same structure of your asset.
This means that you will have a Template that contains the same elements your Asset does.
The following code snippet describes the RegisterElementToTag
method, which registers RegisterElementToTag
registers an element name to a tag within the RemoteAssets service. The function accepts three parameters: assetName
(the element name in the remote device), tagName
(the tag name in your project), and an optional readOnly
flag that indicates if the asset is read-only. The function returns a boolean flag indicating success (true) or failure (false). The function is called using the following method's syntax:
Code Block |
---|
|
@Client.RegisterElementToTag(assetName, tagName); |
Code Block |
---|
|
string assetName = "User\Motor" ;
string tagName = @Tag.Motor.GetName();
@Client.RegisterElementToTag(assetName, tagName); |
In the example, assetName
is assigned the value "User\Motor", and tagName
is assigned the value from @Tag.Motor.GetName()
. @Client.RegisterElementToTag(assetName, tagName)
Then, both are passed as parameters when the RegisterElementToTag
method is called.
Code Block |
---|
language | c# |
---|
title | For asynchronous execution use: |
---|
|
@Client.RegisterElementToTagAsync(assetName, tagName). |
When executing this method, you should see messages in the TraceWindow Logs stating that the Remote Asset was registered to a Parent Tag and its Template elements have their values updated.
RegisterRemoteTag
This method allows you to map a specific RemoteTag
remote tag to a Project Tag.
The following code snippet describes the RegisterRemoteTag
function, which registers a remote tag within the RemoteTags service.
The function accepts four parameters: remoteTagName
(the tag name in the remote device), tagName
(the tag name in your project), an optional readOnly
flag that indicates if the asset is read-only, and an optional onlyValueProperty
flag that indicates whether only the value property is used, ignoring Min
, Max
, EngUnits
, and Description properties
.
The function returns a boolean flag indicating success (true
) or failure (false
).
The function method is called using the following syntax:
Code Block |
---|
|
@Client.RegisterRemoteTag(remoteTagName, tagName). |
Code Block |
---|
|
string string remoteTagName remoteTagName = "User\Historian-MyTag";
string tagName = @Tag.DoubleTag.GetName();
@Client.RegisterRemoteTag(remoteTagName, tagName); |
In the example, remoteTagName
is assigned the value "User\Historian-MyTag", and tagName
is assigned the value from @Tag.DoubleTag.GetName()
.
Code Block |
---|
language | c# |
---|
title | For asynchronous execution use: |
---|
|
@Client.RegisterRemoteTagAsync(remoteTagName, tagName). |
When executing this method, you should see messages in the TraceWindow Logs stating that the remoteTagName
was registered and its value was updated.
Methods explanation
Code Block |
---|
|
Method's syntaxThe RefreshRemoteTags
performs a new reading on the registered elements within the RemoteTags service. The purpose of this function is to refresh the tag data configured in the service, and it does not require any parameters. The method's syntax is:
Example explanation |
Code Block |
---|
language | c# |
---|
title | For asynchronous execution use: |
---|
|
@Client.RegisterElementToTagAsyncRefreshRemoteTags(assetName, tagName).; |
TraceWindow check
UnregisterRemoteTag
The UnregisterRemoteTag
Methods explanation
removes remote tags from the registered list within the RemoteTags
service. The method's syntax is:
Code Block |
---|
|
Method's syntax@Client.UnregisterRemoteTag(remoteTagName); |
Code Block |
---|
|
Code example |
string remoteTagName = "User\Historian-MyTag";
string tagName = @Tag.DoubleTag.GetName();
@Client.UnregisterRemoteTag(remoteTagName); |
In the example, remoteTagName
is assigned the value "User\Historian-MyTag", and tagName
is assigned the value from @Tag.DoubleTag.GetName()
.Example explanation
Code Block |
---|
language | c# |
---|
title | For asynchronous execution use: |
---|
|
@Client.RegisterElementToTagAsyncUnregisterRemoteTagAsync(assetNameremoteTagName, tagName).; |
TraceWindow check
UnregisterElementToTag
UnregisterElementToTag
Methods explanation
Code Block |
---|
|
Method's syntaxThe UnregisterElementToTag
removes assets from the registered list within the RemoteAssets
service. It requires one parameter: assetName
, which is the asset name in the remote device. The function returns an integer with the value 0 if the operation is successful. The method's syntax is:
Example explanation
Code Block |
---|
language | c# |
---|
title | For asynchronous execution use: |
---|
|
@Client.RegisterElementToTagAsync(assetName, tagName). |
TraceWindow check
@Client.RegisterElementToTag(string assetName); |
In the the following example, assetName
is assigned the value "User\Motor
", and the function is called using @Client.UnregisterElementToTag(assetName)
.
UnregisterAllAssets
Methods explanation Code Block |
---|
|
Method's syntax |
Code Block |
---|
|
Code example |
Example explanation
string assetName = "User\Motor";
@Client.UnregisterElementToTag(assetName); |
Code Block |
---|
language | c# |
---|
title | For asynchronous execution use: |
---|
|
@Client.RegisterElementToTagAsyncUnregisterElementToTagAsync(assetName, tagName).; |
TraceWindow check
Methods explanation
UnregisterAllAssets
The UnregisterAllAssets
removes all remote assets from the registered list. The method's syntax is:
Code Block |
---|
|
Method's syntaxExample explanation
@Client.UnregisterAllAssets(); |
The UnregisterAllRemoteTags
removes all remote tags from the registered list. The method's syntax is:
Code Block |
---|
language | c# | title | For asynchronous execution use: |
---|
|
@Client.RegisterElementToTagAsyncUnregisterAllRemoteTags(assetName, tagName). |
TraceWindow check