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

|
|
Back to Services Source Examples
 |
|
|
|

|
|
Reading Tags in an NT Service application using OPC Web Client Web Service
Reading Single Tags
Try ' 'define our OPC Web Client dim objOWC As EasyDAWS = New EasyDAWS
' 'define the object to receive the value, quality and timestamp Dim objTagVTQ As IVTQNet ' 'now to make the call to read the tag 'NOTE: that we are using "readItem" and NOT "readItemValue". This is because
'I DO WANT the quality & timestamp values objTagVTQ = objOWC.ReadItem( _ txtPC.Text, _ txtOPC.Text, _
txtTag.Text) ' 'now to show the value to the screen, but lets do the right thing here and
'check the QUALITY of the TAG first!!!! ' '0 = bad '192 = good If Not objTagVTQ Is Nothing Then
If objTagVTQ.Quality >= 192 Then MessageBox.Show("Value: " & objTagVTQ.Value.ToString) Else
MessageBox.Show("Value: " & objTagVTQ.Value.ToString _ & " is NOT GOOD quality, quality : " _
& objTagVTQ.Quality.ToString) End If End If '
'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
Reading Multiple Tags
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
|
|

|
|
|
|

|
|
|