Reading Tags
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 OPC Web Client ActiveX Controls

Quick links within this page:

Objective

    To show OPC Tag values within a web-page.

Source Code for reading a single Tag:

    VBscript

<HTML>

<head>
<title>OPC Web Client Example, Single Tag Read Within Internet Explorer</title>
</head>

<body>

  <p>
  <input type="text" name="T1" size="20">
  <input type="button" value="Button" name="B3">
  </p>


</body>
<script language="vbscript">
 
  sub b3_onClick
   set opcwebclient = CreateObject(" OPCLabs.EasyDA3.0")
   set valueTimeQuality = opcwebclient.ReadItem("", "OPCLabs.KitServer.2", _
         "Simulation.Random", "", 0)
   if Err.Number = 0 then
     document.all.t1.value = valueTimeQuality.Value
   else
     msgbox "An error occurred: " & Err.Number
   end if
  end sub
 
</script>

</html>

    Simply place the above text under the "</body>" HTML tag and then save your HTML page. Now open that web-page directly from Internet Explorer and then click on the button.

    JAVASCRIPT

<HTML>

<head>
<title>OPC Web Client Example, Single Tag Read Within Internet Explorer</title>
</head>

<body>

  <p>
  <input type="text" name="T1" size="20">
  <input type="button" value="Button" name="B3" onClick="doRead();">
  </p>


</body>
<script language="javascript">
 function doRead()
 {
  try
  {
   var opcWebClient = new ActiveXObject("OPCLabs.EasyDA3.0");
   var valueTimeQuality = opcWebClient.ReadItem("", "OPCLabs.KitServer.2",
     "Simulation.Random", "", 0)
   document.all.T1.value = valueTimeQuality.Value;
  }
  catch(e)
  {
   alert(e)
  }
 }
</script>
</HTML

    With the above modification set, and with the Javascript code present, you can now save this web-page and load it directly into the web-browser.

Source code for reading multiple Tags in one transaction:

    VBscript

    <HTML>

    <head>
    <title>OPC Web Client Example, Read Multiple Tags Within Internet Explorer</title>
    </head>

    <body>

      <p>
      <textarea rows="11" name="S1" cols="33"></textarea>
      <input type="button" value="Button" name="B3">
      </p>


    </body>
    <script language="vbscript">
     
      sub b3_onClick
       'define an opc web client object
       Dim EasyDA
       Set EasyDA = CreateObject("OPCLabs.EasyDA3.0")

       'define an object to receive the values, as a collection
       Dim VTQs

       'make the call to do the read
       VTQs = EasyDA.ReadMultipleItems("", "OPCLabs.KitServer.2", _
       Array("Simulation.Random", "Trends.Ramp (1 min)", "Trends.Sine (1 min)", "Simulation.Register_I4"))

       'define a string to build a message with
       Dim strWriteValue
       strWriteValue = "Tag Read, data as follows: " & vbCrLf & vbCrLF

       'iterate thru collection, reading the tag read details
       'building-up a friendly message string

       Dim I
       For I = LBound(VTQs) To UBound(VTQs)

         'is this item an error?
         If VarType(VTQs(I)) <> 10 Then
         With VTQs(I)
           strWriteValue = strWriteValue & "Array Element #" & I & vbCrLf _
                 & "Value: " & .Value & vbCrLf _
                 & "Quality: " & .Quality & vbCrLf _
                 & "Timestamp: " & .TimeStamp
         End With
     
       Else
           'an error happened, handle gracefully
           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 & vbCrLf
      Next

      'write the message to the textbox
      document.all.s1.value = strWriteValue
    end sub
     
    </script>

    </html>

    JAVASCRIPT

    Feature not currently supported within Javascript due to the differences in Array handling for this development language. This feature will be made available in the next product release.

    Sign-up to our newsletter to receive product updates & other important information.

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