Array Tag Reading/Writing
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

 

Web Service Consumption

The following examples show you how you can read and write to Tags that are of type Array.

Reading an Array Tag:

         '
         'the following constants are used here to help make the code more readable
         'from an educational perspective.
         'Feel free to modify the contents of the values below.
         Const strPCName = ""
         Const strOPCServer = "SWToolbox.TOPServer"
         Const strTag = "Channel_1.Device_1.TagArray_1"
         Const strAccessPath = ""
         Const iDataType = 0

         Try
             '
             'define our OPC Web Client web-service mode
             Dim objOWC As New EasyOPCDANet.EasyDAWS

             '
             'define the object to receive the value, quality and timestamp
             Dim objTagVTQ As EasyOPCDANet.IVTQNet

             '
             'now to make the call to read the tag
             objTagVTQ = objOWC.ReadItem( _
               strPCName, _
               strOPCServer, _
               strTag)

             Dim strMessage As New System.Text.StringBuilder

             '
             'now to make sure the object is an array
             If IsArray(objTagVTQ.Value) Then

               '
               'now to get the value into an array
               Dim objArray As Array = objTagVTQ.Value

               '
               'now to store the values into a string for later
               'displaying to screen
               With strMessage
                   .Append("Value(s): ")
                   For i As Integer = 0 To objArray.GetLength(0) - 1
                     .Append(objArray(i))
                     If Not i = objArray.GetLength(0) - 1 Then .Append(", ")
                   Next
               End With

             Else
               '
               'display an error
               strMessage.Append("The Tag that was read is NOT an array!")
             End If

             '
             'display the message to screen
             MessageBox.Show(strMessage.ToString)

             '
             'now to destroy the objects
             objTagVTQ = Nothing
             objOWC = Nothing
             '
         Catch webex As Web.Services.Protocols.SoapException
             'display exception to screen
             If webex.InnerException Is Nothing Then
               MessageBox.Show(webex.Message)
             Else
               MessageBox.Show(webex.InnerException.Message)
             End If
         Catch ex As Exception
             '
             'display an exception to screen
             If ex.InnerException Is Nothing Then
               MessageBox.Show(ex.Message)
             Else
               MessageBox.Show(ex.InnerException.Message)
             End If
         End Try

Writing to an Array Tag:

         '
         'the following constants are used here to help make the code more readable
         'from an educational perspective.
         'Feel free to modify the contents of the values below.
         Const strPCName = ""
         Const strOPCServer = "SWToolbox.TOPServer"
         Const strTag = "Channel_1.Device_1.TagArray_1"
         Const iDataType = 0

         Try

             'define our OPC Web Client
             Dim objOWC As New OPCLabs.EasyOPCDANet.EasyDAWS

             'now to create an array of values to write to our tag
             Dim arrValues() As Object = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

             'now to write the array to the tag
             objOWC.WriteItemValue( _
               strPCName, _
               strOPCServer, _
               strTag, _
               arrValues)

             'now to make sure there was no error
             If Err.Number = 0 Then
               MessageBox.Show("Array Write successful!")
             Else
               MessageBox.Show("Error writing array (" & Err.Number & ") " & Err.Description)
             End If

             'now to dispose of our object
             objOWC = Nothing
            '
         Catch webex As Web.Services.Protocols.SoapException
             'display exception to screen
             If webex.InnerException Is Nothing Then
               MessageBox.Show(webex.Message)
             Else
               MessageBox.Show(webex.InnerException.Message)
             End If
         Catch ex As Exception
             '
             'display an exception to screen
             If ex.InnerException Is Nothing Then
               MessageBox.Show(ex.Message)
             Else
               MessageBox.Show(ex.InnerException.Message)
             End If
         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