Loading API Index...
Open Automation Software API Documentation
Show / Hide Table of Contents

Get Tag Values By Group

GetTagValuesByGroup

The GetTagValuesByGroup Function returns an array of Tag Names and Values for all of the Tags in the specified group. Tag Names and Values alternate within the array.

  • GroupName is the name of the Group that you want to retrieve the tags for. Leaving this blank will return all tags in the service.
  • NetworkNode is the node you wish to connect to. Leave this blank for localhost.
  • ErrorString will return Success or a message.
  • Returns Empty Array if service is not reachable.
  • The returned array of objects will contain first the tag name followed by the value.
  • If the data quality of the Tag value is bad the individual returned value will be null.
C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OASDataSample
{
    class Program
    {
        static OASConfig.Config oasc = new OASConfig.Config();
        static void Main(string[] args)
        {

            object[] tagNamesAndValues = null;
            string tagName = null;
            string valueStr = null;
            string errorMess = "";
            string groupName = "";
            string networkNode = "";

            tagNamesAndValues = oasc.GetTagValuesByGroup(groupName, networkNode, ref errorMess);
            if (errorMess == "Success")
            {
                Int32 numberOfTags = Convert.ToInt32(tagNamesAndValues.GetLength(0) / 2);
                Int32 tagIndex = 0;
                Int32 itemIndex = 0;

                for (tagIndex = 0; tagIndex < numberOfTags; tagIndex++)
                {
                    tagName = tagNamesAndValues[itemIndex].ToString();
                    itemIndex += 1;
                    if (tagNamesAndValues[itemIndex] == null)
                    {
                        Console.WriteLine(tagName + " = Bad Quality");
                    }
                    else
                    {
                        try
                        {
                            valueStr = tagNamesAndValues[itemIndex].ToString();
                            Console.WriteLine(tagName + " = " + valueStr);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(tagName + " = Value Cannot Be Converted To String");
                        }
                    }
                    itemIndex += 1;
                }
            }
            else if(errorMess == "There are no Tags to Export")
            {
                Console.WriteLine(errorMess);
            }
            else
            {
                Console.WriteLine("Error: " + errorMess);
            }
       
    }
    }
}
VB
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks

Namespace OASDataSample
    Class Program
        Shared oasc As OASConfig.Config = New OASConfig.Config()

        Public Shared Sub Main(ByVal args As String())
            Dim tagNamesAndValues As Object() = Nothing
            Dim tagName As String = Nothing
            Dim valueStr As String = Nothing
            Dim errorMess As String = ""
            Dim groupName As String = ""
            Dim networkNode As String = ""
            tagNamesAndValues = oasc.GetTagValuesByGroup(groupName, networkNode, errorMess)

            If errorMess = "Success" Then
                Dim numberOfTags As Int32 = Convert.ToInt32(tagNamesAndValues.GetLength(0) / 2)
                Dim tagIndex As Int32 = 0
                Dim itemIndex As Int32 = 0

                For tagIndex = 0 To numberOfTags - 1
                    tagName = tagNamesAndValues(itemIndex).ToString()
                    itemIndex += 1

                    If tagNamesAndValues(itemIndex) Is Nothing Then
                        Console.WriteLine(tagName & " = Bad Quality")
                    Else

                        Try
                            valueStr = tagNamesAndValues(itemIndex).ToString()
                            Console.WriteLine(tagName & " = " & valueStr)
                        Catch ex As Exception
                            Console.WriteLine(tagName & " = Value Cannot Be Converted To String")
                        End Try
                    End If

                    itemIndex += 1
                Next
            ElseIf errorMess = "There are no Tags to Export" Then
                Console.WriteLine(errorMess)
            Else
                Console.WriteLine("Error: " & errorMess)
            End If
        End Sub
    End Class
End Namespace

Back to top Copyright (c) Open Automation Software. All rights reserved.