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

|
|
|
|
|

|
|
Web Service Consumption
The following example shows you how to write to a Tag using VB.NET while consuming the OPC Web Client Web Service.
Writing a Single Tag:
Simply copy and paste the following code into your application:
' '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.Random" Const iDataType = 0
Const iNewValue = 10
Try ' 'define our OPC Web Client Dim objOWC As New 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
MessageBox.Show("Write Successful!") Else
MessageBox.Show("Write Failed: " & Err.Number & ", " & Err.Description) End If '
'now to destroy the objects 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 Multiple Tags in a single transaction:
Try '
'create ourselves an opc web client object Dim EasyDA As New OPCLabs.EasyOPCDANet.EasyDAWS
'
'now create an array to receive our values into Dim Values As Array
'
'now request the read of multiple items 'I have actually broken this single instruction over multiple lines
'to try and make it more readable. 'You will notice that there are essentially 3 parameters:
' (1) the computer name for the opc server, which is blank in this case ' (2) the opc server
' (3) the array of items to read Values = EasyDA.ReadMultipleItemValues _ ( _
"", _ "OPCLabs.KitServer.2", _
New Object() {"Simulation.Random", _
"Trends.Ramp (1 min)", _
"Trends.Sine (1 min)", _
"Simulation.Register_I4"} _ )
'
'now to take a look at what we received If Not Values Is Nothing Then
'
'iterate thru the array For I As Integer = LBound(Values) To UBound(Values)
'
'lets check to make sure that the value is not an error code type If VarType(Values(I)) <> VariantType.Error Then
'
'no error here, so lets display the value to a textbox TextBox1.Text += "Element " & I & ": " & Values(I) & vbCrLf
Else
'
'lets call the "raiseError" method and raise the error returned in 'the value EasyDA.RaiseError(Values(I))
' 'display an error to the textbox TextBox1.Text += vbCrLf & "** " _
& Err.Source _ & ": " & Err.Description _
& " (0x" & Hex(Err.Number) & ")" _
& " **"
End If Next
End If
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
|
|

|
|
|
|

|
|
|