From 059083082a6d284821b70eb7bb6805763014c402 Mon Sep 17 00:00:00 2001 From: wujian <14790700720@163.com> Date: 星期六, 16 三月 2024 10:54:46 +0800 Subject: [PATCH] add PLC连接通信 add 扫码数据推送到前端 --- jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java | 136 ++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 121 insertions(+), 15 deletions(-) diff --git a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java index 2dd7941..f7313b2 100644 --- a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java +++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java @@ -3,20 +3,27 @@ import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; +import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig; import com.jcdm.main.da.paramCollection.domain.DaParamCollection; import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; +import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; +import com.jcdm.main.da.passingStationCollection.service.impl.DaPassingStationCollectionServiceImpl; import com.jcdm.main.plcserver.conf.OPCElement; import com.kangaroohy.milo.model.ReadWriteEntity; import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; import com.kangaroohy.milo.service.MiloService; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.text.Format; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; +@Slf4j @Component public class OPCUaSubscription implements SubscriptionCallback { @@ -26,12 +33,23 @@ public IDaParamCollectionService daParamCollectionService; + public DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl; + + public List<DaOpcuaConfig> lists; + + public static final HashMap<String,Integer> map = new HashMap<>(); + public OPCUaSubscription(MiloService miloService, IDaCollectionParamConfService collectionParamConfService, - IDaParamCollectionService daParamCollectionService) { + IDaParamCollectionService daParamCollectionService, + DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl, + List<DaOpcuaConfig> lists) { OPCUaSubscription.miloService = miloService; this.collectionParamConfService = collectionParamConfService; this.daParamCollectionService = daParamCollectionService; + this.passingStationCollectionServiceImpl = passingStationCollectionServiceImpl; + this.lists = lists; + } @@ -41,20 +59,82 @@ String ecpStr = "";//寮傚父璁板綍鏍囪 try { if(null != value) { + //1銆佹绱N鍙� + //2銆佽繃绔欏弬鏁伴噰闆� + //3銆佹壂鐮佹灙鏁版嵁鍥炰紶 + List<String> collect1 = lists.stream().filter(x -> OPCElement.SN_CHECK.equals(x.getrFunction())) + .map(DaOpcuaConfig::getNode).collect(Collectors.toList()); + List<String> collect2 = lists.stream().filter(x -> OPCElement.SAVE_DATA.equals(x.getrFunction())) + .map(DaOpcuaConfig::getNode).collect(Collectors.toList()); + if (collect1.contains(identifier)){ + //sn + this.SNRetrieval(identifier,value.toString()); + if (identifier.equals(OPCElement.OP120_ZZ_CODE_CHECK) && "1".equals(value.toString())){ + //鎬昏涓婄嚎鎵爜浼犺緭鏁版嵁 + log.info("-------鐩戝惉鍒�,{}鐨勬壂鐮佹灙鎵爜鐨凜ODE_CHECK鐨勪俊鍙�",identifier); + Integer i = map.getOrDefault(identifier + "鐨勬壂鐮佹灙鎵爜鐨凜ODE_CHECK鐨勪俊鍙�",0); + if (0==i){ + map.put(identifier + "鐨勬壂鐮佹灙鎵爜鐨凜ODE_CHECK鐨勪俊鍙�",i+1); + } + String[] parts = OPCElement.OP120_ZZ_CODE_CHECK.split("[.]"); + Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue(); + if (null != SNCodeObject){ + String SNCode = SNCodeObject.toString(); + passingStationCollectionServiceImpl.sendMessage(SNCode); + } + } + } + else if (collect2.contains(identifier)){ + //save + this.SaveData(identifier); + //杩斿洖plc淇濆瓨鎴愬姛 + String[] parts = identifier.split("[.]"); + if (parts.length==3){ + if ("SaveRequest".equals(parts[2])){ + ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeed", 1); + log.info("-------鐩戝惉鍒�,{}鐨剆aveRequest鐨勪俊鍙�",identifier); + Integer i = map.getOrDefault(identifier + "鐨剆aveRequest鐨勪俊鍙�",0); + if (0==i){ + map.put(identifier + "鐨剆aveRequest鐨勪俊鍙�",i+1); + } +// miloService.writeToOpcByte(entity); + }else if ("SaveRequestLast".equals(parts[2])){ + ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeedLast", 1); + log.info("-------鐩戝惉鍒�,{}鐨凷aveRequestLast鐨勪俊鍙�",identifier); + Integer i = map.getOrDefault(identifier + "鐨凷aveRequestLast鐨勪俊鍙�",0); + if (0==i){ + map.put(identifier + "鐨凷aveRequestLast鐨勪俊鍙�",i+1); + } +// miloService.writeToOpcByte(entity); + } + } + + + } //OP010淇濆瓨璇锋眰 - if (identifier.equals(OPCElement.OP010_SaveRequest) && "1".equals(value.toString())) { - //1銆佹洿鏂板伐鍗曟暟鎹� - //2銆佷繚瀛樿繃绔欓噰闆嗘暟鎹� - //3銆佷繚瀛樺弬鏁伴噰闆嗘暟鎹� - ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesSaveFeed, 1); - miloService.writeToOpcByte(entity); - } - //OP010璇锋眰妫�绱㈡潯鐮� - else if (identifier.equals(OPCElement.OP010_CodeCheck) && "1".equals(value.toString())) { - ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesCodeCheckFeed, 1); - miloService.writeToOpcByte(entity); - } +// if (identifier.equals(OPCElement.OP120_SaveRequestLast) && "1".equals(value.toString())) { +// this.SaveData(OPCElement.OP120_SaveRequestLast); +// //1銆佹洿鏂板伐鍗曟暟鎹� +// //2銆佷繚瀛樿繃绔欓噰闆嗘暟鎹� +// //3銆佷繚瀛樺弬鏁伴噰闆嗘暟鎹� +// ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesSaveFeed, 1); +// miloService.writeToOpcByte(entity); +// } +// else if (identifier.equals(OPCElement.OP120_ZZ_CODE_CHECK) && "1".equals(value.toString())){ +// //鎬昏涓婄嚎鎵爜浼犺緭鏁版嵁 +// String[] parts = OPCElement.OP120_ZZ_CODE_CHECK.split("[.]"); +// Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue(); +// if (null != SNCodeObject){ +// String SNCode = SNCodeObject.toString(); +// passingStationCollectionServiceImpl.sendMessage(SNCode); +// } +// } +// //OP010璇锋眰妫�绱㈡潯鐮� +// else if (identifier.equals(OPCElement.OP010_CodeCheck) && "1".equals(value.toString())) { +// ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesCodeCheckFeed, 1); +// miloService.writeToOpcByte(entity); +// } } @@ -69,8 +149,34 @@ } } + public void SNRetrieval(String Node, String value) throws Exception { + String[] parts = Node.split("[.]"); + if(value.equals("1")) { + //SN鍙锋绱� + Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue(); + if(null != SNCodeObject) { + String SNCode=SNCodeObject.toString(); + String a=passingStationCollectionServiceImpl.SelectSN(SNCode,parts[1]); + // 1:OK鍙敓浜� 2:NG涓嶅彲鐢熶骇 3:NG鍙繑宸� 4:PC妫�绱㈠け璐ワ紙鏃犺褰曪級5:PC妫�绱㈠け璐ワ紙杞欢锛� + ReadWriteEntity entity = new ReadWriteEntity(parts[0]+"."+parts[1]+".CodeCheckFeed", a); + log.info("-------鐩戝惉鍒�,{}鐨凜odeCheck鐨勪俊鍙�",Node); + Integer i = map.getOrDefault(Node + "鐨凜odeCheck鐨勪俊鍙�",0); + if (0==i){ + map.put(Node + "鐨凜odeCheck鐨勪俊鍙�",i+1); + } +// miloService.writeToOpcByte(entity); + DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); + PassingStationCollection.setSfcCode(SNCode); + PassingStationCollection.setLocationCode(parts[1]); + PassingStationCollection.setInboundTime(new Date()); + passingStationCollectionServiceImpl.insertDaPassingStationCollection(PassingStationCollection); + } + } + } + + public void SaveData(String Node) throws Exception { - /*String[] parts = Node.split("[.]"); + String[] parts = Node.split("[.]"); Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue(); if(null != SNCodeObject) @@ -108,6 +214,6 @@ } daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist); } - }*/ + } } } -- Gitblit v1.9.3