1、博图新建连接:
PLC_!
PLC_2
PLC_Changer_12
2、博图新建VB脚本:
connection_PLC1
Sub connection_PLC1()
'提示:
' 1. 使用 <CTRL+SPACE> 或 <CTRL+I> 快捷键打开含所有对象和函数的列表
' 2. 使用 HMI Runtime 对象写入代码。
' 示例:HmiRuntime.Screens("Screen_1")。
' 3. 使用 <CTRL+J> 快捷键创建对象引用。
'从此位置起写入代码:
'***************************
'**** Initialization ****
'***************************
'During initialization the default connection is
'saved into the memory of connections (connected_to).
If SmartTags("connected_to") = "" Then
SmartTags("connected_to") = "PLC_1"
End If
'*******************
'**** Reset ****
'*******************
'Reset of connection brake detection for PLC_1
SmartTags("con_state_PLC1") = 1
'*****************************
'**** Fault detection ****
'*****************************
'Incrementation of the brake detection value for the connection to PLC_2
If SmartTags("con_state_PLC2") <= 10 Then
SmartTags("con_state_PLC2") = SmartTags("con_state_PLC2") +1
End If
'**************************
'**** Switch over ****
'**************************
'is the limit of the status tag for the connection to PLC_2 reached, the connection to PLC_1 will
'switch the data connection.
'Function Usage: ChangeConnection Connection, Address, Slot, Rack
If SmartTags("con_state_PLC2") >= 11 Then
If SmartTags("connected_to") = "PLC_2" Then
ChangeConnection "PLC_Changer_12", "172.19.43.2", 2, 0
SmartTags("con_state_PLC2") = 100
SmartTags("connected_to") = "PLC_1"
ElseIf SmartTags("connected_to") = "PLC_1" Then
SmartTags("con_state_PLC2") = 100
End If
End If
'***************************
'**** Reintegration ****
'***************************
'after a full connection brake the first repaired connection will activate the data connection
If SmartTags("connected_to") = "connection lost" Then
ChangeConnection "PLC_Changer_12", "172.19.43.2", 2, 0
SmartTags("con_state_PLC2") = 100
SmartTags("connected_to") = "PLC_1"
End If
End Sub
connection_PLC2
Sub connection_PLC2()
'提示:
' 1. 使用 <CTRL+SPACE> 或 <CTRL+I> 快捷键打开含所有对象和函数的列表
' 2. 使用 HMI Runtime 对象写入代码。
' 示例:HmiRuntime.Screens("Screen_1")。
' 3. 使用 <CTRL+J> 快捷键创建对象引用。
'从此位置起写入代码:
'***************************
'**** Initialization ****
'***************************
'During initialization the default connection is
'saved into the memory of connections (connected_to).
If SmartTags("connected_to") = "" Then
SmartTags("connected_to") = "PLC_1"
End If
'*******************
'**** Reset ****
'*******************
'Reset of connection brake detection for PLC_2
SmartTags("con_state_PLC2") = 1
'*****************************
'**** Fault detection ****
'*****************************
'Incrementation of the brake detection value for the connection to PLC_1
If SmartTags("con_state_PLC1") <= 10 Then
SmartTags("con_state_PLC1") = SmartTags("con_state_PLC1") +1
End If
'**************************
'**** switch over ****
'**************************
'Is the limit of the status tag for the connection to PLC_1 reached,
'the connection to PLC2 will switch the data connection.
'Function Usage: ChangeConnection Connection, Address, Slot, Rack
If SmartTags("con_state_PLC1") >= 11 Then
If SmartTags("connected_to") = "PLC_1" Then
ChangeConnection "PLC_Changer_12", "172.19.43.1", 2, 1
SmartTags("con_state_PLC1") = 100
SmartTags("connected_to") = "PLC_2"
ElseIf SmartTags("connected_to") = "PLC_2" Then
SmartTags("con_state_PLC1") = 100
End If
End If
'***************************
'**** reintegration ****
'***************************
'After a full connection brake the first repaired connection will activate the data connection.
If SmartTags("connected_to") = "connection lost" Then
ChangeConnection "PLC_Changer_12", "172.19.43.1", 2, 1
SmartTags("con_state_PLC1") = 100
SmartTags("connected_to") = "PLC_2"
End If
End Sub
connection_lost()
Sub connection_lost()
'提示:
' 1. 使用 <CTRL+SPACE> 或 <CTRL+I> 快捷键打开含所有对象和函数的列表
' 2. 使用 HMI Runtime 对象写入代码。
' 示例:HmiRuntime.Screens("Screen_1")。
' 3. 使用 <CTRL+J> 快捷键创建对象引用。
'从此位置起写入代码:
'***************************
'**** Deactivation ****
'***************************
'If the connections are not able to reset there status tag back to "1" they will be marked with 100 (disabled).
If SmartTags("con_state_PLC1") >= 5 Then
SmartTags("con_state_PLC1") = 100
End If
If SmartTags("con_state_PLC2") >= 5 Then
SmartTags("con_state_PLC2") = 100
End If
'If both connections are marked with "disabled", the connection memory will be set to "connection_lost"
If SmartTags("con_state_PLC1") = 100 And SmartTags("con_state_PLC2") = 100 Then
SmartTags("connected_to") = "connection lost"
End If
'********************************
'**** Setting fault flag ****
'********************************
'In each cycle of 1 minute the status tags of the connections will be set to 5.
If SmartTags("con_state_PLC1") < 5 Then
SmartTags("con_state_PLC1") = 5
End If
If SmartTags("con_state_PLC2") < 5 Then
SmartTags("con_state_PLC2") = 5
End If
End Sub
3、建立脚本触发:
sunrtnj@163.com