3 example functions, Example functions, Appendix – Lenze VisiWinNet VisiWinNET Smart Benutzerhandbuch
Seite 258
Appendix
Scripts
Example functions
l
258
SHP−VWNS DE/EN 6.1
6.4.3
Example functions
Reading and writing of variable values
A typical scenario is the reading of one or several variables if a trigger is activated. The
trigger often is a variable itself. The reading/writing is executed via the function
VWGet/VWSet.
’Sample VWGet/VWSet: Reading a byte field from Demo OPC Server
’increment elements and write back
Private Sub ItemServerArrayRead_Change(ByVal sender As System.Object, _
ByVal e As VisiWinNET.DataAccess.ChangeEventArgs)
Handles ItemServerArrayRead.Change
If e.Value = 1 Then
Dim xObj As Object = _
VisiWinNET.Services.AppService.VWGet("Ch1.Simulation.Array.Byte")
Dim x() As Byte = xObj
For i As Integer = 0 To x.Length − 1
Dim bt As Byte = x(i)
bt = bt + 1
x.SetValue(bt, i)
Next
VisiWinNET.Services.AppService.VWSet("Ch1.Simulation.Array.Byte", x)
End If
End Sub
During the course of a Change event, this function reads out the field
"Simulation.Array.Byte" from a demo OPC server from the variable core of a VarServer
component, increments the elements and writes the data field back. Further examples
with regard to the functions "VWGet"/"VWSet" can be found in the online help.
Evaluating bits in integer variable values
VisiWinNET
â
Smart contains functions which support the VB programmer during
handling bits from integer variable values.
’Toggles Bit 2 in process variable "MyBitModulatedValue"
If VisiWinNET.Services.AppService.VWGetBit("MyBitModulatedValue", 2) = True Then
VisiWinNET.Services.AppService.VWSetBit("MyBitModulatedValue", 2, False)
Else
VisiWinNET.Services.AppService.VWSetBit("MyBitModulatedValue", 2, True)
End If
This function accesses bit 2 in the "MyBitModulatedValue" process variable and changes
the value.