Reading
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

 

The following page contains source code to:

  • Read a single Tag
  • Read many tags within a single transaction
  • Read a Tag that is of type ARRAY

Reading a single Tag

    If you want a Tag's value ONLY:

    Dim EasyDA
    Set EasyDA = CreateObject("OPCLabs.EasyDA3.0")

    Dim Value
    Value = EasyDA.ReadItemValue("", " OPCLabs.KitServer.2", "Simulation.Random")
    WScript.Echo Value

    If you want a Tag's value, quality and the timestamp:

    Dim EasyDA
    Set EasyDA = CreateObject("OPCLabs.EasyDA3.0")

    Dim VTQ
    Set VTQ = EasyDA.ReadItem("", " OPCLabs.KitServer.2", "Simulation.Random")

    With VTQ
      WScript.Echo "Value: " & .Value
      WScript.Echo "Quality: " & .Quality
      WScript.Echo "Timestamp: " & .Timestamp
    End With

Reading multiple Tags within a single transaction

    If you are only interested in the value of the Tags:

    Dim EasyDA
    Set EasyDA = CreateObject("OPCLabs.EasyDA3.0")

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

    Dim I
    For I = LBound(Values) To UBound(Values)
       If VarType(Values(I)) <> 10 Then
           WScript.Echo "Element " & I & ": " & Values(I)
       Else
           On Error Resume Next
           EasyDA.RaiseError Values(I)
           WScript.Echo "** " & Err.Source & ": " & Err.Description & " (0x" & Hex(Err.Number) & ")" & " **"
           On Error Goto 0
       End If
    Next

    If you want the Tags values, qualities and timestamps:

    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 I
    For I = LBound(VTQs) To UBound(VTQs)
       WScript.Echo
       WScript.Echo "Element " & I & ":"
       If VarType(VTQs(I)) <> 10 Then
         With VTQs(I)
           WScript.Echo Space(4) & "Value: " & .Value
           WScript.Echo Space(4) & "Quality: " & .Quality
           WScript.Echo Space(4) & "Timestamp: " & .Timestamp
         End With
       Else
           On Error Resume Next
           EasyDA.RaiseError VTQs(I)
           WScript.Echo Space(4) & "** " & Err.Source & ": " & Err.Description & " (0x" & Hex(Err.Number) & ")" & " **"
           On Error Goto 0
       End If
    Next

Reading an Array-Tag

    set opcwebclient = CreateObject("OPCLabs.EasyDA3.0")
    set valueTimeQuality = opcwebclient.ReadItem("", "SWToolbox.TOPServer ", "Channel_1.Device_1.TagArray_1", "", 0)

      if err.number = 0 then

       objValue = valueTimeQuality.Value

       If IsArray(objValue) Then

         lowerBound = LBound(objValue)
         upperBound = UBound(objValue)

         For i = lowerBound To upperBound - 1
           WScript.Echo objValue(i)
         Next
       Else
         WScript.Echo valueTimeQuality.value
       End If

      else

       WScript.Echo "An error occurred: " & err.number

      end if

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