cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.EOP090B.impl;
2
3
4 import cn.stylefeng.guns.modular.bs.collectionParamConf.model.params.CollectionParamConfParam;
5 import cn.stylefeng.guns.modular.bs.collectionParamConf.model.result.CollectionParamConfResult;
6 import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService;
7 import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
8 import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
9 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
10 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
11 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
12 import cn.stylefeng.guns.plcserver.opc.OPCComm;
13 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
14
15 import cn.stylefeng.guns.plcserver.server.EOP090B.EOP090BServerInterface;
16 import cn.stylefeng.guns.plcserver.tool.DateTool;
17 import cn.stylefeng.guns.plcserver.tool.LogUtil;
18 import org.apache.log4j.Logger;
19 import org.openscada.opc.lib.da.Group;
20 import org.openscada.opc.lib.da.Item;
21
22 import java.util.Date;
23 import java.util.List;
24
25
26 public class EOP090BServerInterfaceImpl implements EOP090BServerInterface {
27
28     private static Logger logger;
29     LogUtil logUtil = new LogUtil();
30     static {
31         logger = Logger.getLogger(EOP090BServerInterfaceImpl.class);
32     }
33
34     private OPCComm opc = OPCComm.getInstance();
35     private static Date IN_TIME = null;
36     private static String S_ORDER_CODE = "";//工单编号
37     private static String S_PRODUCT_CODE = "";//产品编号
38     private static String S_PRODUCT_TYPE= "";//产品类型
39     private static String S_PRODUCT_CODE_OLD = "";//产品编号
40     private static String S_SFC_CODE = "";//总成编码
41     private static String S_RIGHT_CODE  = "";//右壳体编码
42     private static String PRODUCTION_LINE  = "EOP";//产线号
43     private static String LOCATION_CODE  = "EOP090B";//工位号
44     private static String GROUP_NAME  = "EOP090B_P";//组名
45     private static List list = null;
46     private static Group group = null;
cf6bff 47
C 48     private int count = 0;
49
50     /**
51      * 设置心跳标志位,保存到全局变量
52      */
53     public void setHeartbeat(String value) {
54         if ("false".equals(value)) {
55             OPCUnit.write(opc.getEOP090B_F_HEART_BEAT(), "true");
56             GlobalVariable.EOP090B_F_HEART_BEAT = true;
57             count = 0;
58         } else {
59             count++;
60         }
61         // 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时
62         if (count > GlobalVariable.HEART_MAX_COUNT) {
63             GlobalVariable.EOP090B_F_HEART_BEAT = false;
64         }
65     }
66
71e81e 67     @Override
68     public synchronized void monitor() {
69         String ecpStr = "";//异常记录标记
70         try{
e0fac3 71            /* String isHeartBeat = OPCUnit.read(opc.getEOP090B_F_HEART_BEAT());
C 72             setHeartbeat(isHeartBeat);*/
cf6bff 73
71e81e 74             if(GlobalVariable.EOP090B_F_HEART_BEAT) {
75                 //PC读工单
76                 String isPLCStart = OPCUnit.read(opc.getEOP090B_J_PLC_START());//PLC开始
77                 if(isPLCStart.equals("true")){
78                     String isFinish = OPCUnit.read(opc.getEOP090B_J_PC_WRITE_ORDER());//PC下发工单完成
79                     if(isFinish.equals("false")){
80                         handleOrder();
81                     }
82                 }
83
84
85                 //PC完成
86                 String isPLCFinish = OPCUnit.read(opc.getEOP090B_J_PLC_FINISH());//PLC完成
87                 if(isPLCFinish.equals("true")){
88                     String isFinish = OPCUnit.read(opc.getEOP090B_J_PC_FINISH());//PC操作完成
89                     if(isFinish.equals("false")){
90                         handleFinsh();
e0fac3 91                         handleInfo();
71e81e 92                     }
93                 }
94
95             }else{
96                 logger.info("EOP090B工位与PLC断开,请检查PLC或网络是否异常!");
97             }
98
99         }catch (Exception e) {
100             ecpStr ="出现异常:" + logUtil.getTrace(e);
101         }finally {
102             if(!"".equals(ecpStr)){
103                 logger.info(ecpStr+"\r\n");
104             }
105         }
106     }
107
108     //PC读工单
109     public void handleOrder() {
110         IN_TIME = DateTool.getLocalTimeForDate();
111         S_ORDER_CODE = OPCUnit.read(opc.getEOP090B_S_ORDER_CODE());//工单编号
112         S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP090B_S_PRODUCT_CODE());//产品编号
113         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
114         S_SFC_CODE = OPCUnit.read(opc.getEOP090B_S_SFC_CODE());//总成编码
115         OPCUnit.write(opc.getEOP090B_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
116         logger.info("EOP090B工位,handleOrder PC处理完成!");
117     }
118
119     //PC读参数信息
120     public void handleInfo() throws Exception {
121         logger.info("EOP090B工位,handleInfo START!");
122
123         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
124             if(group != null){
125                 opc.getServer().removeGroup(group,true);
126             }
127             group = opc.getServer().addGroup(GROUP_NAME);
128
129             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
130             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
131             collectionParamConfParam.setLocationCode(LOCATION_CODE);
132             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
133             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
134
135
136             for(int i=0;i<list.size();i++){
137                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
138                 Item item = group.addItem(result.getGatherAddress());
139                 result.setItem(item);
140                 list.set(i,result);
141             }
142             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
143         }
144
145         if(null != list && list.size()>0) {
146             ParamCollectionService paramCollectionService = opc.paramCollectionService;
147             for (int i = 0; i < list.size(); i++) {
148                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
149                 Item item = result.getItem();
150                 String value = OPCUnit.read(item);//读参数值
151                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
152                 paramCollectionParam.setParamCode(result.getParamCode());
153                 paramCollectionParam.setParamName(result.getParamName());
154                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
155                 paramCollectionParam.setSfcCode(S_SFC_CODE);
156                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
157                 paramCollectionParam.setProductionLine(result.getProductionLine());
158                 paramCollectionParam.setLocationCode(result.getLocationCode());
159                 paramCollectionParam.setParamValue(value);
160                 paramCollectionParam.setParamLower(result.getParamLower());
161                 paramCollectionParam.setParamUpper(result.getParamUpper());
162                 paramCollectionParam.setParamStandard(result.getParamCentral());
163                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
164                 paramCollectionParam.setUnit(result.getUnit());
165                 paramCollectionService.add(paramCollectionParam);
166             }
167         }
168
169         logger.info("EOP090B工位,handleInfo END!");
170     }
171
172     //PC完成
173     public void handleFinsh() {
174         if("".equals(S_ORDER_CODE)){
175             IN_TIME = DateTool.getLocalTimeForDate();
176             S_ORDER_CODE = OPCUnit.read(opc.getEOP090B_S_ORDER_CODE());//工单编号
177             S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP090B_S_PRODUCT_CODE());//产品编号
178             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
179             S_SFC_CODE = OPCUnit.read(opc.getEOP090B_S_SFC_CODE());//总成编码
180         }
181         //处理过站信息
182         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getEOP090B_S_PRODUCT_STATE_CODE());
183         PassingStationCollectionParam param = new PassingStationCollectionParam();
184         param.setWorkOrderNo(S_ORDER_CODE);
185         param.setProductCode(S_PRODUCT_CODE);
186         param.setSfcCode(S_SFC_CODE);
187         param.setProductionLine(PRODUCTION_LINE);
188         param.setLocationCode(LOCATION_CODE);
189         param.setInboundTime(IN_TIME);
190         param.setOutboundTime(DateTool.getLocalTimeForDate());
191         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
192         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
193         passingStationCollectionService.add(param);
194
195         OPCUnit.write(opc.getEOP090B_J_PC_FINISH(), "true"); //PC完成
196
197         logger.info("EOP090B工位,handleFinsh PC处理完成!");
198     }
199
200 }