admin
2024-01-10 7f291910791bdb9a545dc12ef36c3c359cfa4e59
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.OP130.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.OP130.OP130ServerInterface;
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 OP130ServerInterfaceImpl implements OP130ServerInterface {
27
28     private static Logger logger;
29     LogUtil logUtil = new LogUtil();
30     static {
31         logger = Logger.getLogger(OP130ServerInterfaceImpl.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  = "OP";//产线号
43     private static String LOCATION_CODE  = "OP130";//工位号
44     private static String GROUP_NAME  = "OP130_P";//工位号
45     private static List list = null;
46     private static Group group = null;
47     @Override
48     public synchronized void monitor() {
49         String ecpStr = "";//异常记录标记
50         try{
51             if(GlobalVariable.OP130_F_HEART_BEAT) {
52
53                 //PC读工单
54                 String isPLCStart = OPCUnit.read(opc.getOP130_J_PLC_START());//PLC开始
55                 if(isPLCStart.equals("true")){
56                     String isFinish = OPCUnit.read(opc.getOP130_J_PC_WRITE_ORDER());//PC下发工单完成
57                     if(isFinish.equals("false")){
58                         handleOrder();
59                     }
60                 }
61
62
63                 //PC完成
64                 String isPLCFinish = OPCUnit.read(opc.getOP130_J_PLC_FINISH());//PLC完成
65                 if(isPLCFinish.equals("true")){
66                     String isFinish = OPCUnit.read(opc.getOP130_J_PC_FINISH());//PC操作完成
67                     if(isFinish.equals("false")){
68                         handleInfo();
69                         handleFinsh();
70                     }
71                 }
72
73             }else{
74                 logger.info("OP130工位与PLC断开,请检查PLC或网络是否异常!");
75             }
76
77         }catch (Exception e) {
78             ecpStr ="出现异常:" + logUtil.getTrace(e);
79         }finally {
80             if(!"".equals(ecpStr)){
81                 logger.info(ecpStr+"\r\n");
82             }
83         }
84     }
85
86     //PC读工单
87     public void handleOrder() {
88         IN_TIME = DateTool.getLocalTimeForDate();
89         S_ORDER_CODE = OPCUnit.read(opc.getOP130_S_ORDER_CODE());//工单编号
90         S_PRODUCT_TYPE = OPCUnit.read(opc.getOP130_S_PRODUCT_CODE());//产品编号
91         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
92         S_SFC_CODE = OPCUnit.read(opc.getOP130_S_SFC_CODE());//总成编码
93         OPCUnit.write(opc.getOP130_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
94         logger.info("OP130工位,handleOrder PC处理完成!");
95     }
96
97     //PC读参数信息
98     public void handleInfo() throws Exception {
99         logger.info("OP130工位,handleInfo START!");
100
101         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
102             if(group != null){
103                 opc.getServer().removeGroup(group,true);
104             }
105             group = opc.getServer().addGroup(GROUP_NAME);
106
107             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
108             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
109             collectionParamConfParam.setLocationCode(LOCATION_CODE);
110             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
111             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
112
113
114             for(int i=0;i<list.size();i++){
115                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
116                 Item item = group.addItem(result.getGatherAddress());
117                 result.setItem(item);
118                 list.set(i,result);
119             }
120             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
121         }
122
123         if(null != list && list.size()>0) {
124             ParamCollectionService paramCollectionService = opc.paramCollectionService;
125             for (int i = 0; i < list.size(); i++) {
126                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
127                 Item item = result.getItem();
128                 String value = OPCUnit.read(item);//读参数值
129                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
130                 paramCollectionParam.setParamCode(result.getParamCode());
131                 paramCollectionParam.setParamName(result.getParamName());
132                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
133                 paramCollectionParam.setSfcCode(S_SFC_CODE);
134                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
135                 paramCollectionParam.setProductionLine(result.getProductionLine());
136                 paramCollectionParam.setLocationCode(result.getLocationCode());
137                 paramCollectionParam.setParamValue(value);
138                 paramCollectionParam.setParamLower(result.getParamLower());
139                 paramCollectionParam.setParamUpper(result.getParamUpper());
140                 paramCollectionParam.setParamStandard(result.getParamCentral());
141                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
142                 paramCollectionParam.setUnit(result.getUnit());
143                 paramCollectionService.add(paramCollectionParam);
144             }
145         }
146
147         logger.info("OP130工位,handleInfo END!");
148     }
149
150     //PC完成
151     public void handleFinsh() {
152         logger.info("OP130工位,handleFinsh PC处理开始!");
153
154         if("".equals(S_ORDER_CODE)){
155             IN_TIME = DateTool.getLocalTimeForDate();
156             S_ORDER_CODE = OPCUnit.read(opc.getOP130_S_ORDER_CODE());//工单编号
157             S_PRODUCT_TYPE = OPCUnit.read(opc.getOP130_S_PRODUCT_CODE());//产品编号
158             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
159             S_SFC_CODE = OPCUnit.read(opc.getOP130_S_SFC_CODE());//总成编码
160         }
161
162         //处理过站信息
163         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP130_S_PRODUCT_STATE_CODE());
164         PassingStationCollectionParam param = new PassingStationCollectionParam();
165         param.setWorkOrderNo(S_ORDER_CODE);
166         param.setProductCode(S_PRODUCT_CODE);
167         param.setSfcCode(S_SFC_CODE);
168         param.setProductionLine(PRODUCTION_LINE);
169         param.setLocationCode(LOCATION_CODE);
170         param.setInboundTime(IN_TIME);
171         param.setOutboundTime(DateTool.getLocalTimeForDate());
172         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
173         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
174         passingStationCollectionService.add(param);
175
176         OPCUnit.write(opc.getOP130_J_PC_FINISH(), "true"); //PC完成
177
178         logger.info("OP130工位,handleFinsh PC处理完成!");
179     }
180
181 }