Read Tag Array 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 Array Tags using the OPC Web Client ActiveX Controls

The following example shows you how you can create a scripted-application that runs from the Web Server.
This example uses the following development languages: ASP, ASP.NET and PHP..

Objective

    The web-page we will create will simply display the values of a Tag that is an array

    This example assumes that you have the Software Toolbox TOPServer installed, and a modified version of the default project "simdemo.opf" which can be downloaded here.

Source code

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 Array-Tag Read from the Web Server</title>
      </head>

      <body>

        <p>The Tag values are: </p>
      <%
      'define an opc web client
        Set opcWebClient = Server.CreateObject("OPCLabs.EasyDA3.0")

      'define a variable to receive the tag value and then read the tag
        Set valueTimeQuality = opcWebClient.ReadItem("", "SWToolbox.TOPServer", _
         & "Channel_1.Device_1.TagArray_1")

    'now check the status of the read
      If Err.Number = 0 Then

       'ok, the read was a success, but have we read an Array Tag?
       If IsArray(valueTimeQuality) Then
           '
           'yes, this value is an array, good, proceed by iterating thru collection
           '
           Dim theTag
           For Each theTag In valueTimeQuality.Value
               Response.Write theTag & "<br>"
           Next
           '
       Else

         'this is not an array, so just display the value
         Response.Write valueTimeQuality.Value
       End If

      Else
       'error occurred doing the read
       Response.Write "<font color=red>Error: " & Err.Number & ", " _
         & Err.Description & "</font>"
      End If
      Set valueTimeQuality = Nothing
      Set opcWebClient = Nothing
    %>
    </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 values of the tag in the web-page.

    ASP.NET

    This example requires the TOPServer OPC Server along with the modified "simdemo.opf" project opened so as to be able to utilize a Tag of type Array.

   'Put user code to initialize the page here
   Try

   'create an opc web client
     Dim objOWC As New OPCLabs.EasyOPCDANet.EasyDACOM

   'create a vtq object and then read the tag
     Dim objVTQ As OPCLabs.EasyOPCDANet.IVTQNet = objOWC.ReadItem( _
       "", _
       "SWToolbox.TOPServer", _
       "Channel_1.Device_1.TagArray_1 ")

   'were there any errors?
     If Err.Number = 0 Then

       'is the value we read an Array?
       If IsArray(objVTQ.Value) Then

           'we have an array, so lets iterate thru the collection
         For Each value As Object In objVTQ.Value
           Response.Write(value.ToString & "<br>")
         Next

       Else

       'this is not an array but a single value, so display it
         Response.Write("Tag not an array! Value=" & objVTQ.Value)
       End If

     Else

       'an error occurred
       Response.Write("Error reading tag: " & Err.Number)
     End If

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

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