From 5e0888a8dc804a4df27ce033b6c3429e530a9ef9 Mon Sep 17 00:00:00 2001 From: admin <15939171744@163.com> Date: 星期三, 26 三月 2025 19:05:24 +0800 Subject: [PATCH] - --- billion-main/src/main/java/com/billion/main/plcServer/sub/OPCUaSubscription.java | 144 +++++++++++++++++++++++++---------------------- 1 files changed, 76 insertions(+), 68 deletions(-) diff --git a/billion-main/src/main/java/com/billion/main/plcServer/sub/OPCUaSubscription.java b/billion-main/src/main/java/com/billion/main/plcServer/sub/OPCUaSubscription.java index 62ceaf1..7d0b0b8 100644 --- a/billion-main/src/main/java/com/billion/main/plcServer/sub/OPCUaSubscription.java +++ b/billion-main/src/main/java/com/billion/main/plcServer/sub/OPCUaSubscription.java @@ -25,6 +25,7 @@ import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; import com.kangaroohy.milo.service.MiloService; import lombok.extern.slf4j.Slf4j; +import org.eclipse.milo.opcua.sdk.client.nodes.UaNode; import org.springframework.stereotype.Component; import java.text.SimpleDateFormat; @@ -100,14 +101,14 @@ if (Constants.ZERO.equals(valueString)){ miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(0).build()); //璇锋眰杩涚珯 - } else if (Constants.ONE.equals(valueString)){ + } if (Constants.ONE.equals(valueString)){ //1.1//棣栧伐绔� if(Constants.ONLINE.contains(device)){ miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build()); } //1.2//闄ら宸ョ珯鎵�鏈夊伐绔� else if( - Constants.TEST.contains(device) || +// Constants.TEST.contains(device) || Constants.PLC1.contains(device) || Constants.PLC2.contains(device) || Constants.PLC3.contains(device) || @@ -130,7 +131,6 @@ miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".EngineType").value(EngineType).build()); miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SerialNumber").value(SerialNumber).build()); } - //9L鍙戝姩鏈烘秱鑳惰建杩逛笅鍙� else if(Constants.OP080.equals(device) && Constants.PLC_4.equals(thoroughfare)){ // 1. 鍒濆鍖栧伐鍗曞璞″苟鏌ヨ宸ュ崟淇℃伅 @@ -183,7 +183,7 @@ } } //鍑虹珯淇濆瓨鏁版嵁 - } else if (Constants.TWO.equals(valueString)) { + } if (Constants.TWO.equals(valueString)) { OmProductionOrderInfo omProductionOrderInfo = new OmProductionOrderInfo(); OmOrderScheduling omOrderScheduling = new OmOrderScheduling(); Object SFCCode = miloService.readFromOpcUa(thoroughfare + "." + device + ".SFCCode").getValue(); @@ -282,55 +282,56 @@ if (Objects.equals(nowQty, getPreOrder2.getPlanQty().toString())){ omProductionOrderInfoService.updatePreStatus2(); } - }else if (Constants.OP020.equals(device)){ - final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - // 閬嶅巻 MaterialCode35 鍒� MaterialCode40 鍏�6缁勬暟鎹� - for (int i = 35; i <= 40; i++) { // 淇敼寰幆鑼冨洿 - // 鏋勫缓OPC UA鑺傜偣鍦板潃锛堜緥濡傦細PLC1.OP020.MaterialCode35锛� - String nodeId = "PLC1." + device + ".MaterialCode" + i; - // 鍒涘缓閲囬泦瀵硅薄 - DaMaterialCollection materialCollection = new DaMaterialCollection(); - materialCollection.setSfcCode(SFCCode.toString()); - materialCollection.setLocationCode(device); - // 璁剧疆鍙傛暟鍚嶇О锛堟椿濉�1鍒版椿濉�6锛� - int pistonNumber = i - 34; // 35鈫�1, 36鈫�2...40鈫�6 - materialCollection.setParamName("娲诲" + pistonNumber); - // 閫氳繃OPC UA璇诲彇鍙傛暟鍊� - ReadWriteEntity dataRead = miloService.readFromOpcUa(nodeId); - if (dataRead != null && dataRead.getValue() != null) { - materialCollection.setParamValue(dataRead.getValue().toString()); - } else { - materialCollection.setParamValue("N/A"); // 澶勭悊绌哄�兼儏鍐� - } - Date collectTime = new Date(); - ReadWriteEntity collectTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime");//杩涚珯鏃堕棿 - collectTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(collectTimeRead.getValue().toString()))); - materialCollection.setCollectTime( collectTime); - // 鎻掑叆鏁版嵁搴� - daMaterialCollectionService.insertDaMaterialCollection(materialCollection); - } - }else if (Constants.OP130.equals(device)){ - final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - // 閬嶅巻 MaterialCode35 鍒� MaterialCode40 鍏�6缁勬暟鎹� - String nodeId = "PLC1." + device + ".MaterialCode35" ; - // 鍒涘缓閲囬泦瀵硅薄 - DaMaterialCollection materialCollection = new DaMaterialCollection(); - materialCollection.setSfcCode(SFCCode.toString()); - materialCollection.setLocationCode(device); - materialCollection.setParamName("缂哥洊鐮�"); - // 閫氳繃OPC UA璇诲彇鍙傛暟鍊� - ReadWriteEntity dataRead = miloService.readFromOpcUa(nodeId); - if (dataRead != null && dataRead.getValue() != null) { - materialCollection.setParamValue(dataRead.getValue().toString()); - } else { - materialCollection.setParamValue("N/A"); // 澶勭悊绌哄�兼儏鍐� - } - Date collectTime = new Date(); - ReadWriteEntity collectTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime");//杩涚珯鏃堕棿 - collectTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(collectTimeRead.getValue().toString()))); - materialCollection.setCollectTime( collectTime); - // 鎻掑叆鏁版嵁搴� - daMaterialCollectionService.insertDaMaterialCollection(materialCollection); +// }else if (Constants.OP020.equals(device)){ +// final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// // 閬嶅巻 MaterialCode35 鍒� MaterialCode40 鍏�6缁勬暟鎹� +// for (int i = 35; i <= 40; i++) { // 淇敼寰幆鑼冨洿 +// // 鏋勫缓OPC UA鑺傜偣鍦板潃锛堜緥濡傦細PLC1.OP020.MaterialCode35锛� +// String nodeId = "PLC2." + device + ".MaterialCode" + i; +// // 鍒涘缓閲囬泦瀵硅薄 +// DaMaterialCollection materialCollection = new DaMaterialCollection(); +// materialCollection.setSfcCode(SFCCode.toString()); +// materialCollection.setLocationCode(device); +// // 璁剧疆鍙傛暟鍚嶇О锛堟椿濉�1鍒版椿濉�6锛� +// int pistonNumber = i - 34; // 35鈫�1, 36鈫�2...40鈫�6 +// materialCollection.setParamName("娲诲" + pistonNumber); +// // 閫氳繃OPC UA璇诲彇鍙傛暟鍊� +// ReadWriteEntity dataRead = miloService.readFromOpcUa(nodeId); +// if (dataRead != null && dataRead.getValue() != null && !Objects.equals(dataRead.getValue(), " ")) { +// materialCollection.setParamValue(dataRead.getValue().toString()); +// Date collectTime = new Date(); +// ReadWriteEntity collectTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime");//杩涚珯鏃堕棿 +// collectTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(collectTimeRead.getValue().toString()))); +// materialCollection.setCollectTime( collectTime); +// // 鎻掑叆鏁版嵁搴� +// daMaterialCollectionService.insertDaMaterialCollection(materialCollection); +// } else { +// log.info("娲诲鍙蜂负绌�: {}",materialCollection.getParamName() ); +// } +// } +// }else if (Constants.OP130.equals(device)){ +// final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// // 閬嶅巻 MaterialCode35 鍒� MaterialCode40 鍏�6缁勬暟鎹� +// String nodeId = "PLC3." + device + ".MaterialCode35" ; +// // 鍒涘缓閲囬泦瀵硅薄 +// DaMaterialCollection materialCollection = new DaMaterialCollection(); +// materialCollection.setSfcCode(SFCCode.toString()); +// materialCollection.setLocationCode(device); +// materialCollection.setParamName("缂哥洊鐮�"); +// // 閫氳繃OPC UA璇诲彇鍙傛暟鍊� +// ReadWriteEntity dataRead = miloService.readFromOpcUa(nodeId); +// if (dataRead != null && dataRead.getValue() != null && !Objects.equals(dataRead.getValue(), " ")) { +// materialCollection.setParamValue(dataRead.getValue().toString()); +// Date collectTime = new Date(); +// ReadWriteEntity collectTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime");//杩涚珯鏃堕棿 +// collectTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(collectTimeRead.getValue().toString()))); +// materialCollection.setCollectTime( collectTime); +// // 鎻掑叆鏁版嵁搴� +// daMaterialCollectionService.insertDaMaterialCollection(materialCollection); +// } else { +// log.info("缂哥洊鐮佷负绌�: {}",materialCollection.getParamName() ); +// } + } //鍑虹珯淇濆瓨 DaStationCollection daStationCollection = new DaStationCollection(); @@ -354,6 +355,7 @@ daCollectionParamConf1.setDescriptive("1"); List<DaCollectionParamConf> daCollectionParamConfList1 = daCollectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf1); for (DaCollectionParamConf conf : daCollectionParamConfList1) { + String index = String.valueOf(daCollectionParamConfList1.indexOf(conf)); String gatherAddress = conf.getGatherAddress(); String valueObj = null; ReadWriteEntity entity = miloService.readFromOpcUa(gatherAddress); @@ -363,6 +365,7 @@ valueObj = value.toString(); // 鏈�缁堣祴鍊� if (!Objects.equals(valueObj, " ")) { DaMaterialCollection materialCollection = new DaMaterialCollection(); + materialCollection.setRemark(index); materialCollection.setSfcCode(SFCCode.toString()); materialCollection.setLocationCode(device); materialCollection.setParamName(conf.getParameterSetName()); @@ -386,22 +389,27 @@ List<DaCollectionParamConf> daCollectionParamConfList2 = daCollectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf2); for (DaCollectionParamConf conf : daCollectionParamConfList2) { String gatherAddress = conf.getGatherAddress(); - String valueObj = miloService.readFromOpcUa(gatherAddress).getValue().toString(); // 鑾峰彇鍘熷鍊煎璞♀��:ml-citation{ref="4" data="citationList"} - if (!Objects.equals(valueObj, "0.0") && !Objects.equals(valueObj, "0")) { - DaParamCollection paramCollection = new DaParamCollection(); - paramCollection.setSfcCode(SFCCode.toString()); - paramCollection.setLocationCode(device); - paramCollection.setParamName(conf.getParameterSetName()); - paramCollection.setParamValue(miloService.readFromOpcUa(gatherAddress).getValue().toString()); - Date Time = new Date(); - ReadWriteEntity TimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime"); - Time = format.parse(TimeUtil.test(TimeUtil.stringProcessing(TimeRead.getValue().toString()))); - paramCollection.setCollectTime(Time); - daParamCollectionService.insertDaParamCollection(paramCollection); + try{ + Object valueObj = miloService.readFromOpcUa(gatherAddress).getValue(); // 鑾峰彇鍘熷鍊煎璞♀��:ml-citation{ref="4" data="citationList"} + if (!Objects.equals(valueObj, "0.0") && !Objects.equals(valueObj, "0") && valueObj != null ) { + DaParamCollection paramCollection = new DaParamCollection(); + paramCollection.setSfcCode(SFCCode.toString()); + paramCollection.setLocationCode(device); + paramCollection.setParamName(conf.getParameterSetName()); + paramCollection.setParamValue(miloService.readFromOpcUa(gatherAddress).getValue().toString()); + Date Time = new Date(); + ReadWriteEntity TimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime"); + Time = format.parse(TimeUtil.test(TimeUtil.stringProcessing(TimeRead.getValue().toString()))); + paramCollection.setCollectTime(Time); + daParamCollectionService.insertDaParamCollection(paramCollection); + } + else { + log.info("閲囬泦椤逛负绌�: {}", gatherAddress); + } + }catch (Exception e){ + log.error(e.getMessage()); } - else { - log.info("閲囬泦椤逛负绌�: {}", gatherAddress); - } + } } } -- Gitblit v1.9.3