提交 | 用户 | 时间
|
71e81e
|
1 |
package cn.stylefeng.guns.plcserver.server.EOP070.callback; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.plcserver.opc.GlobalVariable; |
|
4 |
import cn.stylefeng.guns.plcserver.opc.OPCComm; |
|
5 |
import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit; |
|
6 |
import org.jinterop.dcom.common.JIException; |
|
7 |
import org.jinterop.dcom.core.JIVariant; |
|
8 |
import org.openscada.opc.lib.da.DataCallback; |
|
9 |
import org.openscada.opc.lib.da.Item; |
|
10 |
import org.openscada.opc.lib.da.ItemState; |
|
11 |
|
|
12 |
public class DataCallBack_EOP070_F_HEART_BEAT implements DataCallback { |
|
13 |
|
|
14 |
private OPCComm opc = OPCComm.getInstance(); |
|
15 |
private int count = 0; |
|
16 |
|
|
17 |
@Override |
|
18 |
public void changed(Item item, ItemState itemState) { |
|
19 |
// 读取心跳变量的值 |
|
20 |
try { |
|
21 |
if (itemState.getValue().getType() == JIVariant.VT_BOOL) { |
|
22 |
boolean value = itemState.getValue().getObjectAsBoolean(); |
|
23 |
setHeartbeat(value); |
|
24 |
} |
|
25 |
} catch (JIException e) { |
|
26 |
e.printStackTrace(); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
/** |
|
31 |
* 设置心跳标志位,保存到全局变量 |
|
32 |
*/ |
|
33 |
public void setHeartbeat(boolean value) { |
|
34 |
if (!value) { |
|
35 |
OPCUnit.write(opc.getEOP070_F_HEART_BEAT(), "true"); |
|
36 |
GlobalVariable.EOP070_F_HEART_BEAT = true; |
|
37 |
count = 0; |
|
38 |
} else { |
|
39 |
count++; |
|
40 |
} |
|
41 |
// 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时 |
|
42 |
if (count > GlobalVariable.HEART_MAX_COUNT) { |
|
43 |
GlobalVariable.EOP070_F_HEART_BEAT = false; |
|
44 |
} |
|
45 |
} |
|
46 |
|
|
47 |
} |