Get and Set Tag Properties
While the use of the CSV Import and Export method allows you to load and save Tag configurations in CSV format, there are many cases where you would prefer to programmatically read or update the configuration with more control. Using the GetTagProperties method you can retrieve Tag properties in array format. You can also pass arrays of values into the SetTagProperties method to update one or more tags in a single call. These methods are much more convenient as they do not require the construction of CSV strings.
GetTagProperties
Use this method to retrieve Tag properties from the OAS server. Data will be returned as a set of nested arrays, with each element representing a single tag. You have the option to return properties of each tag as an array of native values, or as a single CSV string.
VB
Dim myConfig as new OASConfig.Config()
' define Tag properties to return
Dim DesiredColumns As String() = New String(3) {}
DesiredColumns(0) = "Tag"
DesiredColumns(1) = "Value - Data Type"
DesiredColumns(2) = "Value - Value"
DesiredColumns(3) = "Value - Gain"
Dim TagNames As String() = New String(2) {}
TagNames(0) = "Ramp"
TagNames(1) = "Random"
TagNames(2) = "Sine"
Dim Groups As String() = New String(1) {}
Groups(0) = "PLC"
Groups(1) = "Tanks"
Dim values As Object() = Nothing
Dim ErrorString As String = ""
' return each Tag as an array of properties
values = myConfig.GetTagProperties(DesiredColumns, TagNames, Groups, False, "localhost", ErrorString)
If ErrorString <> "Success" Then
Console.WriteLine(ErrorString)
Else
For Each row As Object In values
Dim aRow As Object() = CType(row, Object())
Dim sRow As String = String.Join(","c, aRow)
Console.WriteLine(sRow)
Next
Console.WriteLine("--------------------------------")
End If
' return each Tag as a CSV string
values = myConfig.GetTagProperties(DesiredColumns, TagNames, Groups, True, "localhost", ErrorString)
If ErrorString <> "Success" Then
Console.WriteLine(ErrorString)
Else
For Each row As String In values
Console.WriteLine(row)
Next
Console.WriteLine("--------------------------------")
End If
C#
OASConfig.Config myConfig = new OASConfig.Config();
// define Tag properties to return
string[] DesiredColumns = new string[4];
DesiredColumns[0] = "Tag";
DesiredColumns[1] = "Value - Data Type";
DesiredColumns[2] = "Value - Value";
DesiredColumns[3] = "Value - Gain";
string[] TagNames = new string[3];
TagNames[0] = "Ramp";
TagNames[1] = "Random";
TagNames[2] = "Sine";
string[] Groups = new string[2];
Groups[0] = "PLC";
Groups[1] = "Tanks";
object[] values = null;
string ErrorString = "";
// return each Tag as an array of properties
values = myConfig.GetTagProperties(DesiredColumns, TagNames, Groups, false, "localhost", ref ErrorString);
if (ErrorString != "Success")
{
Console.WriteLine(ErrorString);
}
else
{
foreach (object row in values)
{
object[] aRow = (object[])row;
string sRow = string.Join(',', aRow);
Console.WriteLine(sRow);
}
Console.WriteLine("--------------------------------");
}
// return each Tag as a CSV string
values = myConfig.GetTagProperties(DesiredColumns, TagNames, Groups, true, "localhost", ref ErrorString);
if (ErrorString != "Success")
{
Console.WriteLine(ErrorString);
}
else
{
foreach (string row in values)
{
Console.WriteLine(row);
}
Console.WriteLine("--------------------------------");
}
SetTagProperties
Use this method to set Tag properties on the OAS server. The first element in the array should contain the properties to be set, and each additional element will contain the values for each Tag.
VB
Dim myConfig as new OASConfig.Config()
Dim PropertyValues As Object() = New Object(3) {}
Dim DesiredColumns As Object() = New Object(2) {}
DesiredColumns(0) = "Tag" ' Required
DesiredColumns(1) = "Value - Data Type"
DesiredColumns(2) = "Value - Gain"
PropertyValues(0) = DesiredColumns ' First record is the header
' All other records contain values for each tag to set.
Dim TagValues1 As Object() = New Object(2) {}
TagValues1(0) = "Ramp"
TagValues1(1) = "Double"
TagValues1(2) = 1.0
PropertyValues(1) = TagValues1
Dim TagValues2 As Object() = New Object(2) {}
TagValues2(0) = "Random"
TagValues2(1) = "Double"
TagValues2(2) = 1.0
PropertyValues(2) = TagValues2
Dim TagValues3 As Object() = New Object(2) {}
TagValues3(0) = "Sine"
TagValues3(1) = "Double"
TagValues3(2) = 1.0
PropertyValues(3) = TagValues3
Dim ErrorString As String = ""
Dim ResultString As String = myConfig.SetTagProperties(PropertyValues, "localhost", ErrorString)
If ErrorString <> "Success" Then
Console.WriteLine(ErrorString)
Else
Console.WriteLine(ResultString)
End If
C#
OASConfig.Config myConfig = new OASConfig.Config();
object[] PropertyValues = new object[4];
object[] DesiredColumns = new object[3];
DesiredColumns[0] = "Tag"; // Required
DesiredColumns[1] = "Value - Data Type";
DesiredColumns[2] = "Value - Gain";
PropertyValues[0] = DesiredColumns; // First record is the header
// All other records contain values for each tag to set.
object[] TagValues1 = new object[3];
TagValues1[0] = "Ramp";
TagValues1[1] = "Double";
TagValues1[2] = 1.0;
PropertyValues[1] = TagValues1;
object[] TagValues2 = new object[3];
TagValues2[0] = "Random";
TagValues2[1] = "Double";
TagValues2[2] = 1.0;
PropertyValues[2] = TagValues2;
object[] TagValues3 = new object[3];
TagValues3[0] = "Sine";
TagValues3[1] = "Double";
TagValues3[2] = 1.0;
PropertyValues[3] = TagValues3;
string ErrorString = "";
string ResultString = myConfig.SetTagProperties(PropertyValues, "localhost", ref ErrorString);
if (ErrorString != "Success")
{
Console.WriteLine(ErrorString);
} else
{
Console.WriteLine(ResultString);
}