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

OPC Browsing

GetListOfOPCServers

  • The GetListOfOPCServers Function returns a list of Registered OPC Servers from the Network Node as a String Array.
  • Returns empty String Array if no Registered Servers are found.
  • Returns Nothing if the OAS Service is not reachable.
  • NetworkNode is the name of the network node of the OAS Service to connect to. Leave blank for localhost connection.
  • Optional ErrorString will be set to Success when function is successful and an error message when in error.
C#
using System;

namespace OASDataSample
{
    class Program
    {
        static OASConfig.Config oasc = new OASConfig.Config();
        static void Main(string[] args)
        {
            string networknode = "";
            string[] OPCServers = null;
            string ErrorString = "";
            OPCServers = oasc.GetListOfOPCServers(networknode, ref ErrorString);
            if (ErrorString == "Success")
            {
                if (OPCServers.GetLength(0) < 1)
                {
                    Console.WriteLine("No OPC Servers Found");
                }
                else
                {
                    foreach (string OPCServer in OPCServers)
                    {
                        Console.WriteLine(OPCServer);
                    }
                }
            }
            else
            {
                Console.WriteLine(ErrorString);
            }
        }
    }
}
VB
Imports System

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

        Private Shared Sub Main(ByVal args As String())
            Dim networknode As String = ""
            Dim OPCServers As String() = Nothing
            Dim ErrorString As String = ""
            OPCServers = oasc.GetListOfOPCServers(networknode, ErrorString)

            If ErrorString = "Success" Then

                If OPCServers.GetLength(0) < 1 Then
                    Console.WriteLine("No OPC Servers Found")
                Else

                    For Each OPCServer As String In OPCServers
                        Console.WriteLine(OPCServer)
                    Next
                End If
            Else
                Console.WriteLine(ErrorString)
            End If
        End Sub
    End Class
End Namespace

GetOPCBranches

  • The GetOPCBranches Function returns a list of Branches from the OPC Servers as a String Array.
  • Returns empty String Array if no Branches are found.
  • Returns Nothing if the OAS Service is not reachable.
  • NetworkNode is the name of the network node of the OAS Service to connect to. Leave blank for localhost connection.
  • OPCServer is the name of the OPC Server to browse.
  • ReferencePath is a string of the branches path to browse.
  • Optional ErrorString will be set to Success when function is successful and an error message when in error.
C#
using System;

namespace OASDataSample
{
    class Program
    {
        static OASConfig.Config oasc = new OASConfig.Config();
        static void Main(string[] args)
        {
            string networknode = "";
            string opcserver = "";
            string[] OPCBranches = null;
            string refpath = "";
            string ErrorString = "";
            OPCBranches = oasc.GetOPCBranches(opcserver, refpath, networknode, ref ErrorString);
            if (ErrorString == "Success")
            {
                if (OPCBranches.GetLength(0) < 1)
                {
                    Console.WriteLine("No bramches found.");
                }
                else
                {
                    foreach (string OPCBranch in OPCBranches)
                    {
                        Console.WriteLine(OPCBranch);
                    }
                }
            }
            else
            {
                Console.WriteLine(ErrorString);
            }

        }
    }
}
VB
Imports System

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

        Private Shared Sub Main(ByVal args As String())
            Dim networknode As String = ""
            Dim opcserver As String = ""
            Dim OPCBranches As String() = Nothing
            Dim refpath As String = ""
            Dim ErrorString As String = ""
            OPCBranches = oasc.GetOPCBranches(opcserver, refpath, networknode, ErrorString)

            If ErrorString = "Success" Then

                If OPCBranches.GetLength(0) < 1 Then
                    Console.WriteLine("No bramches found.")
                Else

                    For Each OPCBranch As String In OPCBranches
                        Console.WriteLine(OPCBranch)
                    Next
                End If
            Else
                Console.WriteLine(ErrorString)
            End If
        End Sub
    End Class
End Namespace

GetOPCBranchesWithDisplayNames

  • The GetOPCBranchesWithDisplayNames Function returns a list of Branches from the OPC Servers both Display Names and Actual Names as a String Array.
  • Returns empty String Array if no Branches are found or if the OAS Service is not reachable.
  • OPCServer is the name of the OPC Server to browse.
  • ReferencePath is a string of the branches path to browse.
  • NetworkNode is the name of the network node of the OAS Service to connect to. Leave blank for localhost connection.
  • Optional ErrorString will be set to Success when function is successful and an error message when in error.
C#
using System;

namespace OASDataSample
{
    class Program
    {
        static OASConfig.Config oasc = new OASConfig.Config();
        static void Main(string[] args)
        {
            string networknode = "";
            string opcserver = "";
            string refpath = "";
            string[] OPCBranches = null;
            string ErrorString = "";
            OPCBranches = oasc.GetOPCBranchesWithDisplayNames(opcserver, refpath, networknode, ref ErrorString);
            if (ErrorString == "Success")
            {
                if (OPCBranches.GetLength(0) < 1)
                {
                    Console.WriteLine("No OPC Branches Found");
                }
                else
                {
                    foreach (string OPCBranch in OPCBranches)
                    {
                        Console.WriteLine(OPCBranch);
                    }
                }
            }
            else
            {
                Console.WriteLine(ErrorString);
            }
        }
    }
}
VB
Class Program
    Shared oasc As OASConfig.Config = New OASConfig.Config()

    Private Shared Sub Main(ByVal args As String())
        Dim networknode As String = ""
        Dim opcserver As String = ""
        Dim refpath As String = ""
        Dim OPCBranches As String() = Nothing
        Dim ErrorString As String = ""
        OPCBranches = oasc.GetOPCBranchesWithDisplayNames(opcserver, refpath, networknode, ErrorString)

        If ErrorString = "Success" Then

            If OPCBranches.GetLength(0) < 1 Then
                Console.WriteLine("No OPC Branches Found")
            Else

                For Each OPCBranch As String In OPCBranches
                    Console.WriteLine(OPCBranch)
                Next
            End If
        Else
            Console.WriteLine(ErrorString)
        End If
    End Sub
End Class

### [GetOPCItems](~/api/OASConfig.Config.yml#OASConfig_Config_GetOPCItems_System_String_System_String_)

 - The GetOPCItems Function returns a list of Items from the OPC Servers as a String Array.
 - Returns both the Display Name and Qualified Item Path of each OPC Item.
 - Returns empty String Array if no Items are found.
 - Returns Nothing if the OAS Service is not reachable.
 - NetworkNode is the name of the network node of the OAS Service to connect to. Leave blank for localhost connection.
 - OPCServer is the name of the OPC Server to browse.
 - ReferencePath is a string of the branches path to browse.
 - Optional ErrorString will be set to Success when function is successful and an error message when in error.

##### C#
```csharp
using System;

namespace OASDataSample
{
    class Program
    {
        static OASConfig.Config oasc = new OASConfig.Config();
        static void Main(string[] args)
        {
            string networknode = "";
            string opcserver = "";
            string refpath = "";
            string ErrorString = "";
            string[] OPCItems = null;
            OPCItems = oasc.GetOPCItems(opcserver, refpath, networknode,  ref ErrorString);
            if (ErrorString == "Success")
            {
                if (OPCItems.GetLength(0) < 1)
                {
                    Console.WriteLine("No OPC Items Found");
                }
                else
                {
                    foreach (string OPCItem in OPCItems)
                    {
                        Console.WriteLine(OPCItem);
                    }
                }
            }
            else
            {
                Console.WriteLine(ErrorString);
            }
        }
    }
}
VB
Imports System

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

        Private Shared Sub Main(ByVal args As String())
            Dim networknode As String = ""
            Dim opcserver As String = ""
            Dim refpath As String = ""
            Dim ErrorString As String = ""
            Dim OPCItems As String() = Nothing
            OPCItems = oasc.GetOPCItems(opcserver, refpath, networknode, ErrorString)

            If ErrorString = "Success" Then

                If OPCItems.GetLength(0) < 1 Then
                    Console.WriteLine("No OPC Items Found")
                Else

                    For Each OPCItem As String In OPCItems
                        Console.WriteLine(OPCItem)
                    Next
                End If
            Else
                Console.WriteLine(ErrorString)
            End If
        End Sub
    End Class
End Namespace

GetOPCItemProperties

  • The GetOPCItemProperties Function returns the values for the properties of the OPC Item specified as an Object Array.

  • Returns the array of values for the properties specified.

  • The length of the array returned is always 6. The values returned within the array depend on if the property attributes are set to be returned.

  • Element 0 = Data Type.

     0 = Double Float
     1 = Single Float
     2 = Signed Byte
     3 = Unsigned Byte
     4 = Short Integer
     5 = Unsigned Short Integer
     6 = Integer
     7 = Unsigned Integer
     8 = Long Integer
     9 = Unsigned Long Integer
     10 = Boolean
     11 = String
     12 = Array Double
     13 = Array Integer
     14 = Array String
     15 = Array Single
     16 = Array Byte
     17 = Array Bool
     18 = Object Type
    
  • Element 1 = Scan Rate.

  • Element 2 = Description.

  • Element 3 = Units.

  • Element 4 = Enumated Value.

  • Element 5 = Enumartion Strings, each one seperated by semicolon.

  • Returns empty Object Array if the OPC Item is not found or the OAS Service is not reachable.

  • OPCItem is the name of the OPC Server and OPC Item to get the properties from. The syntax is OPCServerOPCItem.

  • ReturnDataType should be set to True to return the Data Type

  • ReturnScanRate should be set to True to return the Scan Rate

  • ReturnDescription should be set to True to return the Description

  • ReturnUnits should be set to True to return the Units

  • ReturnEnumeratedValue should be set to True to return the Is Enemurated Value and the Enumerated Strings

  • NetworkNode is the name of the network node of the OAS Service to connect to. Leave blank for localhost connection.

  • Optional ErrorString will be set to Success when function is successful and an error message when in error.

C#
using System;

namespace OASDataSample
{
    class Program
    {
        static OASConfig.Config oasc = new OASConfig.Config();
        static void Main(string[] args)
        {
            object[] OPCItemProperties = null;
            string OPCItem = "";
            string ErrorString = "";
            string networknode = "";
            Boolean datatype = true;
            Boolean scanrate = true;
            Boolean description = true;
            Boolean units = true;
            Boolean enumval = true;

            OPCItemProperties = oasc.GetOPCItemProperties(OPCItem, datatype, scanrate, description, units, enumval, networknode, ref ErrorString);
            if (ErrorString == "Success")
            {
                if (OPCItemProperties.GetLength(0) < 6)
                {
                    Console.WriteLine("Invalid Length of Properties Array");
                }
                else
                {
                    if (datatype)
                    {
                        try
                        {
                            Console.WriteLine(OPCItemProperties[0].ToString());
                        }
                        catch
                        {
                            Console.WriteLine("Cannot convert Data Type to String");
                        }
                    }
                    if (scanrate)
                    {
                        try
                        {
                            Console.WriteLine(OPCItemProperties[1].ToString());
                        }
                        catch
                        {
                            Console.WriteLine("Cannot convert Scan Rate to String");
                        }
                    }
                    if (description)
                    {
                        try
                        {
                            Console.WriteLine(OPCItemProperties[2]);
                        }
                        catch
                        {
                            Console.WriteLine("Cannot convert Description to String");
                        }
                    }
                    if (units)
                    {
                        try
                        {
                            Console.WriteLine(OPCItemProperties[3]);
                        }
                        catch
                        {
                            Console.WriteLine("Cannot convert Units to String");
                        }
                    }
                    if (enumval)
                    {
                        try
                        {
                            Console.WriteLine(OPCItemProperties[4]);
                        }
                        catch
                        {
                            Console.WriteLine("Cannot convert Enumerated Value to String");
                        }
                        try
                        {
                            Console.WriteLine(OPCItemProperties[5]);
                        }
                        catch
                        {
                            Console.WriteLine("Cannot convert Enumerated Values to String");
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine(ErrorString);
            }
        }
    }
}
VB
Imports System

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

        Private Shared Sub Main(ByVal args As String())
            Dim OPCItemProperties As Object() = Nothing
            Dim OPCItem As String = ""
            Dim ErrorString As String = ""
            Dim networknode As String = ""
            Dim datatype As Boolean = True
            Dim scanrate As Boolean = True
            Dim description As Boolean = True
            Dim units As Boolean = True
            Dim enumval As Boolean = True
            OPCItemProperties = oasc.GetOPCItemProperties(OPCItem, datatype, scanrate, description, units, enumval, networknode, ErrorString)

            If ErrorString = "Success" Then

                If OPCItemProperties.GetLength(0) < 6 Then
                    Console.WriteLine("Invalid Length of Properties Array")
                Else

                    If datatype Then

                        Try
                            Console.WriteLine(OPCItemProperties(0).ToString())
                        Catch
                            Console.WriteLine("Cannot convert Data Type to String")
                        End Try
                    End If

                    If scanrate Then

                        Try
                            Console.WriteLine(OPCItemProperties(1).ToString())
                        Catch
                            Console.WriteLine("Cannot convert Scan Rate to String")
                        End Try
                    End If

                    If description Then

                        Try
                            Console.WriteLine(OPCItemProperties(2))
                        Catch
                            Console.WriteLine("Cannot convert Description to String")
                        End Try
                    End If

                    If units Then

                        Try
                            Console.WriteLine(OPCItemProperties(3))
                        Catch
                            Console.WriteLine("Cannot convert Units to String")
                        End Try
                    End If

                    If enumval Then

                        Try
                            Console.WriteLine(OPCItemProperties(4))
                        Catch
                            Console.WriteLine("Cannot convert Enumerated Value to String")
                        End Try

                        Try
                            Console.WriteLine(OPCItemProperties(5))
                        Catch
                            Console.WriteLine("Cannot convert Enumerated Values to String")
                        End Try
                    End If
                End If
            Else
                Console.WriteLine(ErrorString)
            End If
        End Sub
    End Class
End Namespace

OPCUABrowse

  • Returns two arrays.
  • The first array contains two objects: (1) a string array of folder names; (2) a string array of node IDs.
  • The second array contains six objects: (1) a string array of variable names; (2) a string array of variable node IDs; (3) a string array of variable namespaces; (4) a string array of variable descriptions; (5) a string array of variable data types; (6) a string array of variable ID types.
C#
using System;

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

            {
                string errorString = "";
                string serverURL = "opc.tcp://localhost:58728";
                string SecurityProfile = "opc.tcp://MSI:58728/ [None:None:Binary]";
                string NodeID = "";
                //NodeID = "ns=2;s=Local";
                NodeID = "ns=3;s=Tag_+_localhost_+__+__+_Ramp_+_Ramp_+_DoubleFloat";
                bool GetOnlyVariables = false;
                bool GetAllNodes = false;
                bool UseSecurity = false;
                bool UseUserSecurity = false;
                string UserName = "";
                string Password = "";
                string DomainNameOverride = "";
                bool AllowInvalidCertificate = false;
                object[] masterArray = oasc.OPCUABrowse(serverURL, SecurityProfile, NodeID, GetOnlyVariables, GetAllNodes, UseSecurity, UseUserSecurity, UserName, Password, DomainNameOverride, AllowInvalidCertificate, "localhost", ref errorString);
                if (errorString == "Success")
                {

                    object[] foldersArray = (object[])masterArray[0];
                    string[] localFolderNames = (string[])foldersArray[0];
                    string[] localFolderNodeIDs = (string[])foldersArray[1];
                    object[] variablesArray = (object[])masterArray[1];
                    string[] localVariableNames = (string[])variablesArray[0];
                    string[] localVariableNodeIDs = (string[])variablesArray[1];
                    string[] localVariableNamespaces = (string[])variablesArray[2];
                    string[] localVariableDescriptions = (string[])variablesArray[3];
                    string[] localVariableDataTypes = (string[])variablesArray[4];
                    string[] localVariableIdTypes = (string[])variablesArray[5];

                    Console.WriteLine("");
                    Console.WriteLine("LocalFolderNames:");
                    Console.WriteLine("");
                    foreach (string localFolderName in localFolderNames)
                    {
                        Console.WriteLine(localFolderName);
                    }
                    Console.WriteLine("---------------------------------------");
                    Console.WriteLine("localFolderNodeIDs:");
                    Console.WriteLine("");
                    foreach (string id in localFolderNodeIDs)
                    {
                        Console.WriteLine(id);
                    }
                    Console.WriteLine("---------------------------------------");
                    Console.WriteLine("localVariableNames:");
                    Console.WriteLine("");
                    foreach (string lvn in localVariableNames)
                    {
                        Console.WriteLine(lvn);
                    }
                    Console.WriteLine("---------------------------------------");
                    Console.WriteLine("localVariableNodeIDs:");
                    Console.WriteLine("");
                    foreach (string lvnid in localVariableNodeIDs)
                    {
                        Console.WriteLine(lvnid);
                    }
                    Console.WriteLine("---------------------------------------");
                    Console.WriteLine("localVariableNamespaces:");
                    Console.WriteLine("");
                    foreach (string lvsnsp in localVariableNamespaces)
                    {
                        Console.WriteLine(lvsnsp);
                    }
                    Console.WriteLine("---------------------------------------");
                    Console.WriteLine("localVariableDescriptions:");
                    Console.WriteLine("");
                    foreach (string lvdesc in localVariableDescriptions)
                    {
                        Console.WriteLine(lvdesc);
                    }
                    Console.WriteLine("---------------------------------------");
                    Console.WriteLine("localVariableDataTypes:");
                    Console.WriteLine("");
                    foreach (string lvdt in localVariableDataTypes)
                    {
                        Console.WriteLine(lvdt);
                    }
                    Console.WriteLine("---------------------------------------");
                    Console.WriteLine("localVariableIdTypes:");
                    Console.WriteLine("");
                    foreach (string lvidtp in localVariableIdTypes)
                    {
                        Console.WriteLine(lvidtp);
                    }
                    Console.WriteLine("---------------------------------------");
                }
                else
                {
                    Console.WriteLine(errorString);
                }

            }
        }
    }
}
VB
Imports System

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

        Public Shared Sub Main(ByVal args As String())
            If True Then
                Dim errorString As String = ""
                Dim serverURL As String = "opc.tcp://localhost:58728"
                Dim SecurityProfile As String = "opc.tcp://MSI:58728/ [None:None:Binary]"
                Dim NodeID As String = ""
                ' NodeID = "ns=3;s=Tag_+_localhost_+__+__+_Ramp_+_Ramp_+_DoubleFloat"
                NodeID = "ns=2;s=Local"
                Dim GetOnlyVariables As Boolean = False
                Dim GetAllNodes As Boolean = False
                Dim UseSecurity As Boolean = False
                Dim UseUserSecurity As Boolean = False
                Dim UserName As String = ""
                Dim Password As String = ""
                Dim DomainNameOverride As String = ""
                Dim AllowInvalidCertificate As Boolean = False
                Dim masterArray As Object() = oasc.OPCUABrowse(serverURL, SecurityProfile, NodeID, GetOnlyVariables, GetAllNodes, UseSecurity, UseUserSecurity, UserName, Password, DomainNameOverride, AllowInvalidCertificate, "localhost", errorString)
                If errorString = "Success" Then
                    Dim foldersArray As Object() = CType(masterArray(0), Object())
                    Dim localFolderNames As String() = CType(foldersArray(0), String())
                    Dim localFolderNodeIDs As String() = CType(foldersArray(1), String())
                    Dim variablesArray As Object() = CType(masterArray(1), Object())
                    Dim localVariableNames As String() = CType(variablesArray(0), String())
                    Dim localVariableNodeIDs As String() = CType(variablesArray(1), String())
                    Dim localVariableNamespaces As String() = CType(variablesArray(2), String())
                    Dim localVariableDescriptions As String() = CType(variablesArray(3), String())
                    Dim localVariableDataTypes As String() = CType(variablesArray(4), String())
                    Dim localVariableIdTypes As String() = CType(variablesArray(5), String())
                    Console.WriteLine("")
                    Console.WriteLine("LocalFolderNames:")
                    Console.WriteLine("")

                    For Each localFolderName As String In localFolderNames
                        Console.WriteLine(localFolderName)
                    Next

                    Console.WriteLine("---------------------------------------")
                    Console.WriteLine("localFolderNodeIDs:")
                    Console.WriteLine("")

                    For Each id As String In localFolderNodeIDs
                        Console.WriteLine(id)
                    Next

                    Console.WriteLine("---------------------------------------")
                    Console.WriteLine("localVariableNames:")
                    Console.WriteLine("")

                    For Each lvn As String In localVariableNames
                        Console.WriteLine(lvn)
                    Next

                    Console.WriteLine("---------------------------------------")
                    Console.WriteLine("localVariableNodeIDs:")
                    Console.WriteLine("")

                    For Each lvnid As String In localVariableNodeIDs
                        Console.WriteLine(lvnid)
                    Next

                    Console.WriteLine("---------------------------------------")
                    Console.WriteLine("localVariableNamespaces:")
                    Console.WriteLine("")

                    For Each lvsnsp As String In localVariableNamespaces
                        Console.WriteLine(lvsnsp)
                    Next

                    Console.WriteLine("---------------------------------------")
                    Console.WriteLine("localVariableDescriptions:")
                    Console.WriteLine("")

                    For Each lvdesc As String In localVariableDescriptions
                        Console.WriteLine(lvdesc)
                    Next

                    Console.WriteLine("---------------------------------------")
                    Console.WriteLine("localVariableDataTypes:")
                    Console.WriteLine("")

                    For Each lvdt As String In localVariableDataTypes
                        Console.WriteLine(lvdt)
                    Next

                    Console.WriteLine("---------------------------------------")
                    Console.WriteLine("localVariableIdTypes:")
                    Console.WriteLine("")

                    For Each lvidtp As String In localVariableIdTypes
                        Console.WriteLine(lvidtp)
                    Next

                    Console.WriteLine("---------------------------------------")
                Else
                    Console.WriteLine(errorString)
                End If
            End If
        End Sub
    End Class
End Namespace

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