Read Tags IIS
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

 

Reading Tags using the OPC Web Client ActiveX Controls

Quick links within this page:

Objective

    To be able to read and display the value of an OPC Tag in a web page.

Reading a Single Tag:

    In order for our web-page to display anything, we need to tell the server to fetch the Tag value from the OPC Server and then to display it in the page.

    ASP

    First, you need to add the following line at the top of the page:

<%@ Language="vbscript" %>
<html>

<head>
<title>OPC Web Client Example, Single Tag Read from the Web Server</title>
</head>

<body>

  <p>The Tag is:
  <%
   Set opcWebClient = Server.CreateObject("OPCLabs.EasyDA3.0")
   Set valueTimeQuality = opcWebClient.ReadItem("", "OPCLabs.KitServer.2", _
     & "Trends.Ramp (1 min)")

       If Err.Number = 0 Then
         Response.Write valueTimeQuality.Value
       Else
         Response.Write "<font color=red>Error: " & Err.Number & ", " _
           & Err.Description & "</font>"
       End If

      Set valueTimeQuality = Nothing
       Set opcWebClient = Nothing
      %>
     
    </p>
    </body>
    </html>

    Save your page with a .ASP extension onto your web-server. Now launch your web-browser and connect to your web-page from your web-server. You should see the value of a tag in the page.

    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 objVTQ As VTQ3 = objOWC.ReadItem _
       ( _
         "", _
         "OPCLabs.KitServer.2", _
         "Simulation.Random")
     Response.Write("Value:" & objVTQ.Value _
           & "<br>")
     Response.Write("Qlty:" & objVTQ .Quality _
           & "<br>")
     Response.Write("Time:" & objVTQ .TimeStamp _
           & "<br>")
   Catch ex As Exception
     Response.Write("Error: " & ex.Message)
   End Try
  End Sub

Reading to Mulitple Tags:

    ASP

<%@Language="vbscript"%>
<html>

<head>
<title>OPC Web Client Example, Reading Multiple Tags</title>
</head>

<body>

  <p>Tag is:
<%
   Dim EasyDA
   Set EasyDA = CreateObject("OPCLabs.EasyDA3.0")

   Dim VTQs
   VTQs = EasyDA.ReadMultipleItems("", "OPCLabs.KitServer.2", _
   Array("Simulation.Random", "Trends.Ramp (1 min)", "Trends.Sine (1 min)", "Simulation.Register_I4"))

   Dim strWriteValue
   strWriteValue = "Tag Read, data as follows: " & "<br><br>"
   Dim I
   For I = LBound(VTQs) To UBound(VTQs)
     If VarType(VTQs(I)) <> 10 Then
     With VTQs(I)
       strWriteValue = strWriteValue & "Array Element #" & I & "<br>" _
& "Value: " & .Value & "<br>" _
             & "Quality: " & .Quality & "<br>" _
             & "Timestamp: " & .TimeStamp
     End With
 
   Else
       On Error Resume Next
       EasyDA.RaiseError VTQs(I)
       strWriteValue = strWriteValue & "** " & Err.Source & ": " & Err.Description & " (0x" _
             & Hex(Err.Number) & ")" & " **"
       On Error Goto 0
   End If
   strWriteValue = strWriteValue & vbCrLf & "<hr><br>"
  Next

  Response.Write strWriteValue
  %>

   </p>


</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
     'define an opc web client object
     Dim EasyDA As New OPCLabs.EasyOPCDANet.EasyDACOM

   'define a dictionary to receive the values
     Dim VTQs As IDictionary

   'Read the items
     VTQs = EasyDA.ReadMultipleItems _
       ( _
         "", _
         "OPCLabs.KitServer.2", _
         New String() _
           { _
             "Simulation.Random", _
             "Trends.Ramp (1 min)", _
             "Trends.Sine (1 min)", _
             " Simulation.Register_I4" _
           } _
         )

   'check if the dictionary contains anything
     If Not VTQs Is Nothing Then

       'now check if the returned item is an array type
       If IsArray(VTQs) Then

       'now iterate thru the collection
         For Each item As EASYOPCDALib.VTQ In VTQs

           'display the item to the browser
           Response.Write(item.Value & "<br>")
         Next
       End If
     End If

   Catch ex As Exception
     Response.Write("Err: " & 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