|
Please use our Code Center to obtain source-code and example projects/solutions:
http://codecenter.softwaretoolbox.com
|
|
|

|
|
|
|
|

|
|
 Writing to Array Tags using the OPC Web Client ActiveX Controls
The following example shows you how you can create a scripted-application that runs from the webserver itself. This example uses the following development languages: ASP, ASP.NET and PHP.
Objective
The web-page will have a button only. 10 values will be written to the Array-Tag upon clicking the button. A message will be displayed indicating the success/failure of the write transaction.
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 value in the textbox
Our click-event handler will instantiate the OPC Web Client, make the call to read the value and then display it in the textbox. Here goes:
ASP
The following code segment (for this example) is the actual web-page, no HTML or anything else is required.
<%@Language="vbscript" %> <%On Error Resume Next '
'create an array and populate it with some values Dim objArray(9) For i=0 To 9 objArray(i) = i Next ' 'now create an instance of the OPC Web Client
Set opcWebClient = Server.CreateObject("OPCLabs.EasyDA3.0") ' 'perform the write instruction opcWebClient.WriteItemValue "", "SWToolbox.TOPServer
", "Channel_1.Device_1.TagArray_1", objArray ' 'check if an error exists, if so then display an error If Err.Number = 0 Then
Response.Write "<p>The Tag write happened successfully</p>" Else Response.Write "<p><font color=red>Error writing to Array-Tag: " _ & Err.Number
& "<br>" & Err.Description & "</font></p>" End If ' 'clean-up Set opcWebClient = Nothing %>
ASP.NET
This example requires the SWToolbox.TOPServer OPC Server along with the modified "simdemo.opf" project opened so as to be able to utilize a Tag of type Array.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here
' ' '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.EasyDACOM '
'now to create an array of values to write to our tag Dim arrValues() As Integer = {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 Response.Write("Array Write successful!") Else Response.Write("Error (" & Err.Number & ") " & Err.Description) End If '
'now to dispose of our object objOWC = Nothing ' Catch ex As Exception ' 'display an exception to screen Response.Write(ex.Message)
End Try End Sub
|
|

|
|
|
|

|
|
|