Writing to Tags in 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

 

Web Based Applications using the OPC Web Client Web Service

Objective

    Write to a Tag and/or to a number of Tags from a web-page.

Source code - Writing a Single Tag

    ASP.NET

          '
         '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 = "OPCLabs.KitServer.2"
         Const strTag = "Simulation.Register_I4"
         Const iDataType = 0
         Const iNewValue = 10

         Try
             '
             'define our OPC Web Client using the Web Service
             Dim objOWC As New OPCLabs.EasyOPCDANet.EasyDAWS
             '
             'now to make the call to read the tag
             objOWC.WriteItemValue(strPCName, strOPCServer, strTag, iNewValue)
             '
             'now to show the value to the screen
             If Err.Number = 0 Then
               Response.Write("Write Successful!")
             Else
               Response.Write("Write Failed: " & Err.Number & ", " & Err.Description)
             End If
             '
             'now to destroy the objects
             objOWC = Nothing
             '
         Catch ex As Exception
            '
             'display an exception to screen
     
          Response.Write(ex.Message)
         End Try

Writing to Multiple Tags in a single transaction

    ASP.NET

         Try
             'create an array of strings - for the Tags
             Dim strTags() As String = New String() _
                   { _
                     "Simulation.Register_I4", _
                     "Simulation.Register_R8", _
                     "Simulation.Register_BSTR" _
                   }

             'create an array of values, to write
             Dim strValues() As String = New String() _
                   { _
                     "1", _
                     "2", _
                     "3" _
                   }

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

             'make the call to write the tags values
             objOWC.WriteMultipleItemValues _
               ( _
                 "127.0.0.1", _
                 "OPCLabs.KitServer.2", _
                 strTags, _
                 strValues _
               )

             'any errors occur?
             If Err.Number = 0 Then
               Response.Write("Write=SUCCESS!")
             Else
               Response.Write("Write=FAILED!")
             End If

         Catch ex As Exception
             'send exception messages to the browser
             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