Configuration in zenon

Previous chapterNext chapter Show allShow all    Hide allHide all

The following globalvariables have to be declared in zenon and have to be defined as 'externally visible'. As driver the Internal driver is used:

Watchdog_IN : DINT

Watchdog_OUT : DINT

zenOnStatus: INT

In addition these assignments must be set up:

VBA Script:

attention Attention

1. COPA-DATA or COPALP do not guarantee that the code which is mentioned here is correct. This code is only an Example.

 

2. We recommend that you do not adopt the Redundancy switching from this example. This can cause problems when using zenon sub projects!

If the straton Runtime is missing, the zenon Runtime should be closed!

You can copy the VBA script in the zenon VBA Editor (Zenrt32Objekte/thisProject) and edit it there accordingly.

Option Explicit
Public WithEvents zOLV As OnlineVariable
Public lTime As Long
Public bSTRATON_Lost As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Project_Active()
If zOLV Is Nothing Then
Set zOLV = thisProject.OnlineVariables.CreateOnlineVariables("OLV")
End If
If Not zOLV Is Nothing Then
zOLV.Add "Watchdog_OUT"
zOLV.Define
End If
lTime = GetTickCount 'lTime initialisieren
bSTRATON_Lost = False
End Sub


'Is activated on each change of the variable <Watchdog_OUT>
Private Sub zOLV_VariableChange(ByVal obVar As IVariable)
lTime = GetTickCount 'Time stamp in ms
bSTRATON_Lost = False
End Sub

'is executed every 5 seconds using time control (execute VBA Macro) ...
Public Sub Timer ()
Dim obFuncRed As RtFunction
Dim obFuncTerm As RtFunction
Set obFuncRed =thisProject.RtFunctions.Item("funcRed") 'Redundancy switching
Set obFuncTerm =thisProject.RtFunctions.Item("funcTerm") 'Exit program

'Have more than 15 s passed since the variable has changed
'This is only true for a cycle time of more than 100 ms. This value must be adjusted
'proportional to the cycle time.
If lTime < GetTickCount - 15000 Then
'Stops the switching between the two RTs.
'If straton is no longer available, it is switched to the other RT,
'because here straton is not running anymore and switched this RT back to here,
'is only switched back if in the mean time a straton
'RT has been running. Otherwise zenon is closed
If bSTRATON_Lost Then
If Not obFuncTerm Is Nothing Then
obFuncTerm.Start
End If
End If
bSTRATON_Lost = True
lTime = GetTickCount 'reset lTime
If Not obFuncRed Is Nothing Then
'execute zenon function 'funcRed' (Redundancy switching)
obFuncRed.Start
End If
End If
End Sub

Private Sub Project_SbToServer()
lTime = GetTickCount 'initialize lTime
End Sub

'Online variables container is deactivated and released..
Private Sub Project_Inactive()
If Not zOLV Is Nothing Then zOLV.Undefine
thisProject.OnlineVariables.DeleteOnlineVariables ('OLV')
Set zOLV = Nothing
End Sub

As described in the VBA script, in zenon functions funcRed, funcTerm and VBA_Call must be created:

funcRed:

funcTerm:

VBA_Call

The function VBA_Call must be executed by the time control in zenon:

Time control