Browsing Programmatically on Web Server
Home Product
Details Free 
Demo Pricing &
Ordering Related
Products Support About Us

Please use our Code Center to obtain source-code and example projects/solutions:

http://codecenter.softwaretoolbox.com

 

Browsing Tags and Servers using the OPC Web Client ActiveX Controls

OPC Browsing

Take a look at the OPC Browsing Tutorial.

There are 3 browsers available:

  1. OPC Servers (see code for ASP or ASP.NET)
  2. Groups (aka BRANCHES) (see code for ASP or ASP.NET
  3. Tags (aka LEAVES) (see code for ASP or ASP.NET

Each of these browsers has its own dialog which can be called, or has methods available that allow you to programmatically accomplish the same result.

In this page you can see how to use these browsers via code using ASP or ASP.NET

OPC Server Browsing

ASP3

Copy the following code into a new .ASP file:

<%@ Language="vbscript" %>
<html>
<head>
<title> OPC Web Client Example - Browsing</title>
</head>

<body>
  <p><b>OPC Web Client Example</b></p>
  <p><b>Using OPC Server Browser Methods Programmatically</b></p>
<%
   Dim objOWC
   Set objOWC = CreateObject(" OPCLabs.EasyDA3.0")

   Dim ServerElements
   Set ServerElements = objOWC.BrowseServers()

   Dim Key
   For Each Key In ServerElements.Keys
       Response.Write "<br>"
       Response.Write "Key " & Key & ":"
  
       Dim ServerElement
       Set ServerElement = ServerElements.Item(Key)
  
       With ServerElement
           Response.Write "CLSID: " & .CLSID & "<br>"
           Response.Write "ProgID: " & .ProgID & "<br>"
           Response.Write "Description: " & .Description & "<br>"
           Response.Write "Vendor: " & .Vendor & "<br>"
           Response.Write "DA 10: " & .ImplementsDA10 & "<br>"
           Response.Write "DA 20: " & .ImplementsDA20 & "</p>"
       End With
   Next
%>

</body>
</html>

ASP.NET

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   'Put user code to initialize the page here
   Try
     Dim objOWC As New OPCLabs.EasyOPCDANet.EasyDACOM

     Dim ServerElements
     ServerElements = objOWC.BrowseServers()

     Dim key
     For Each key In ServerElements.Keys
       Dim server
       server = ServerElements.Item(key)

       Response.Write(server.ProgID & "<br>")
     Next
   Catch ex As Exception
     Response.Write("Error: " & ex.Message)
   End Try
End Sub

OPC Group Browsing

ASP

Copy the following code into a new HTML file:

<%@Language="vbscript" %>
<html>
<head>
<title>OPC Web Client Example - Browsing</title>
</head>

<body>
  <p><b><font size="3">OPC Web Client Example</font></b></p>
  <p><b><font size="2">Using OPC Server Groups/Branches Programmatically</font></b></p>
</body>
<%
   Dim EasyDA
   Set EasyDA = CreateObject("OPCLabs.EasyDA3.0")

   Dim BranchElements
   Set BranchElements = EasyDA.BrowseBranches("", "OPCLabs.KitServer.2", "")

   Dim Key
   For Each Key In BranchElements.Keys
     Response.Write "<p>"
     Response.Write "Key " & Key & ":" & "<br>"
  
     Dim BranchElement
     Set BranchElement = BranchElements.Item(Key)
  
     With BranchElement
       Response.Write "Name: " & .Name & "<br>"
       Response.Write "ItemID: " & .ItemID & "<br>"
       Response.Write "IsBranch: " & .IsBranch & "<br>"
       Response.Write "IsLeaf: " & .IsLeaf & "<br>"
       Response.Write "HasChildren: " & .HasChildren & "</p>"
     End With
   Next
%>

</html>

ASP.NET

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   'Put user code to initialize the page here
   Try
     Dim EasyDA As New OPCLabs.EasyOPCDANet.EasyDACOM

     Dim BranchElements As IDictionary
     BranchElements = EasyDA.BrowseBranches("", "OPCLabs.KitServer.2", "")

     For Each Key As Object In BranchElements.Keys
       Dim BranchElement
       BranchElement = BranchElements.Item(Key)

       If BranchElement.IsBranch Then
         Response.Write(BranchElement.ItemID & "<br>")
       End If
     Next

   Catch ex As Exception
     Response.Write("Error: " & ex.Message)
   End Try
End Sub

OPC Tag Browsing

ASP

Copy and paste the code below into a new HTML file:

<%@Language="vbscript" %>
<html>
<head>
<title> OPC Web Client Example - Browsing</title>
</head>

<body>
  <p><b><font size="3">OPC Web Client Example</font></b></p>
  <p><b><font size="2">Using OPC Server Tags Programmatically</font></b></p>
</body>
<%
   Dim EasyDA
   Set EasyDA = CreateObject("OPCLabs.EasyDA3.0")

   Dim LeafElements
   Set LeafElements = EasyDA.BrowseLeafs("", "OPCLabs.KitServer.2", "Simulation")

   Dim Key
   For Each Key In LeafElements.Keys
       Response.Write "<p>"
       Response.Write "Key " & Key & ":<br>"
  
       Dim LeafElement
       Set LeafElement = LeafElements.Item(Key)
  
       With LeafElement
           Response.Write "Name: " & .Name & "<br>"
           Response.Write "ItemID: " & .ItemID & "<br>"
           Response.Write "IsBranch: " & .IsBranch & "<br>"
           Response.Write "IsLeaf: " & .IsLeaf & "<br>"
           Response.Write "HasChildren: " & .HasChildren & "</p>"
       End With
   Next
%>
</html>

ASP.NET

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   'Put user code to initialize the page here
   '
   Try
     Dim objOWC As New OPCLabs.EasyOPCDANet.EasyDACOM

     Dim LeafElements As Object
     LeafElements = objOWC.BrowseLeafs("", "OPCLabs.KitServer.2", "Simulation")

     For Each Key As Object In LeafElements.Keys
       Dim LeafElement As Object = LeafElements.Item(Key)
       With LeafElement
         Response.Write("Tag: " & .Name & ", ItemID: " & .ItemID & "<br>")
       End With
     Next

   Catch ex As Exception
     Response.Write("Error: " & ex.Message)
   End Try
End Sub

Copyright Software Toolbox, Inc., 1996-2004, All Rights Reserved Worldwide.
148A East Charles Street, Matthews, North Carolina, USA 28105
Phone: 704-849-2773 or 1-888-665-3678 (US), Fax: 704-849-6388
sales@softwaretoolbox.com | support@softwaretoolbox.com