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

The following example shows you how you can create a scripted-application that runs from within Internet Explorer itself.
This example uses the following development languages: vbscript and javascript

Syntactically speaking, reading a regular (single-value) Tag or an Array-Tag is requires the exact same coding as far as requesting the data. The only difference is with the return value and how you access the values of the array.

Objective

    The web-page we will create will have a button and a textbox only. The value of the Array-Tag will be shown in the textbox upon clicking the button. Each value of the array will be shown with comma's separating the values, i.e.

    1, 2, 3, 4, 5, 6

    This example assumes that you have the Software Toolbox TOPServer installed along with a customized "simdemo.opf" project that contains Tags of type Array. You can download our test project here..

Source code

In order for our web-page to do anything, we now need to add some scripting that will:
    • respond to the button being clicked
    • perform the tag read request
    • display the values of the Array-Tag in the textbox

    Our click-event handler will instantiate the OPC Web Client, make the call to read the Tag Array and then display it's values in the textbox. Here goes:

    IMPORTANT: When working with Tag arrays, it is IMPORTANT that your application/script detect that a value is an array prior to treating the object as if it were an array. You will see in our examples (below) that this is how we suggest and recommend your applications/scripts work too.

    VBSCRIPT

<html>

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

<body>

  <p>Simply click on the button to the right
  <input type="text" name="T1" size="50">
  <input type="button" value="Button" name="B3">
  </p>


</body>
<Script language="vbscript">
sub b3_onClick
  '
  'first, instantiate the OPC Web Client control

  set opcwebclient = CreateObject("OPCLabs.EasyDA3.0")
  '
  'second, perform the read and capture the data into the "valueTimeQuality" object

  set valueTimeQuality = opcwebclient.ReadItem("", "SWToolbox.TOPServer", "Channel_1.Device_1.TagArray_1")
  '
  'check if an error occurred

  if Err.Number = 0 then
   '
   'no errors, proceed....
   '
   'get the value into a temporary variable

   objValue = valueTimeQuality.Value
  '
   'check to see if the object is an array holder

   If IsArray(objValue) Then
     '
     'get the bounds of the arrays into variables for use later

     lowerBound = LBound(objValue)
     upperBound = UBound(objValue)
   '
     'iterate thru each element of array and display the value contents
     'to the textbox

     For i = lowerBound To upperBound - 1
       document.all.t1.value = document.all.t1.value & objValue(i)
       If i < (upperBound - 1 )then document.all.t1.value = document.all.t1.value & ", "
     Next
   Else
     '
     'the object was NOT an array, so it's a single value only

     document.all.t1.value = valueTimeQuality.Value
   End If
  '
  else
    '
   'an error occurred

   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

    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