From f3862f0f7387f97e642167c5cda98f7e10fc3065 Mon Sep 17 00:00:00 2001 From: cl <418351270@qq.com> Date: 星期四, 01 八月 2024 08:20:52 +0800 Subject: [PATCH] 修改采集参数 --- jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java | 3 + jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java | 65 +++++++++++++++++++++++++++++++- jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java | 2 + 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java b/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java index c8ff710..8b7a85b 100644 --- a/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java +++ b/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java @@ -30,6 +30,8 @@ public static final String RECORD_CHECK_CODE_2= "RecordCheckCode2"; public static final String RECORD_DATA= "RecordData"; public static final String RECORD_SN= "RecordSN"; + + public static final String SCREW = "Screw"; public static final String ONE= "1"; public static final String ZERO= "0"; public static final String TWO= "2"; diff --git a/jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java b/jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java index 10a1fd3..bde0358 100644 --- a/jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java +++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java @@ -53,6 +53,9 @@ @Override public void run(ApplicationArguments args) throws Exception { + //PLC鍒癕ES鐗╂枡杞崲 + Constants.materialMap.put("1","9900199052A"); + Constants.materialMap.put("2","9900199053B"); OPCUaSubscription opcUaSubscription = new OPCUaSubscription( miloService, daPassingStationCollectionService, 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 60c0d5a..b6b30da 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 @@ -104,6 +104,7 @@ if (Constants.RECORD_DATA.equals(tab)) { //鍑哄叆绔� if (Constants.ONE.equals(valueString)) {//鍏ョ珯 Integer recordDataDone = 11; + miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StartTime").value(new Date()).build()); miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build()); } else if(Constants.TWO.equals(valueString)){//鍑虹珯 Integer result = 21; @@ -135,7 +136,6 @@ } }else if (Constants.RECORD_SN.equals(tab)){//璇锋眰浜у搧搴忓垪鍙� if (Constants.ONE.equals(valueString)){ - Integer result = 11; //杩涚珯PLC缁欎骇鍝佺被鍨嬶紝MES璇诲彇浜у搧绫诲瀷 Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//浜у搧绫诲瀷 if (ObjectUtil.isNotNull(productTypeObjcet)){ @@ -146,10 +146,22 @@ receivingWorkOrders(thoroughfare, device,materialCode); }); }else{ - result = 12; + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(12).build()); } - miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(result).build()); + } + }else if(Constants.SCREW.equals(tab)){ + List<String> list = new ArrayList<>(); + String[] suffixes = {"Torque", "Angle", "TorqueResult", "AngleResult"}; + + for (String suffix : suffixes) { + String string = thoroughfare + "." + device + "." + suffix; + list.add(string); + } + List<ReadWriteEntity> list1 = miloService.readFromOpcUa(list); + List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList()); + String joinedString = String.join(",", collect.toString()); + WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString)); } }catch (Exception e) { log.error(e.getMessage()); @@ -334,6 +346,7 @@ if(!productNum.isEmpty() && !orderNum.isEmpty()){ miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ModuleCode").value(productNum).build()); miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build()); + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(11).build()); } } catch (Exception e) { @@ -384,4 +397,50 @@ throw new RuntimeException(e); } } + + public static String TightenTheConversionOkNg(String param){ + // 鍘婚櫎棣栧熬鐨勬柟鎷彿锛岀劧鍚庢寜鐓ч�楀彿鍒嗗壊瀛楃涓� + String[] parts = param.substring(1, param.length() - 1).split(","); + + // 鍒涘缓涓�涓柊鐨凷tringBuilder鏉ユ瀯寤烘浛鎹㈠悗鐨勫瓧绗︿覆 + StringBuilder sb = new StringBuilder(); + sb.append('['); // 娣诲姞宸︽柟鎷彿 + + for (int i = 0; i < parts.length; i++) { + String part = parts[i].trim(); // 鍘婚櫎鍙兘鐨勭┖鏍� + float value; + try { + value = Float.parseFloat(part); // 灏濊瘯灏嗗瓧绗︿覆杞崲涓烘诞鐐规暟 + String replacement; + if(i<2){ + replacement = part; + }else{ + if (value == 1f) { + replacement = "OK"; + } else{ + replacement = "NG"; + } + } + /* if (value == 1f) { + replacement = "OK"; + } else if (value == 2f) { + replacement = "NG"; + } else { + replacement = part; // 濡傛灉涓嶆槸1鎴�2锛屽垯淇濇寔涓嶅彉 + }*/ + sb.append(replacement); + if (i < parts.length - 1) { + sb.append(','); // 娣诲姞閫楀彿锛堥櫎浜嗘渶鍚庝竴涓厓绱狅級 + } + } catch (NumberFormatException e) { + // 濡傛灉杞崲澶辫触锛屽垯淇濇寔鍘熸牱锛堟垨杩涜鍏朵粬閿欒澶勭悊锛� + sb.append(part); + if (i < parts.length - 1) { + sb.append(','); + } + } + } + sb.append(']'); // 娣诲姞鍙虫柟鎷彿 + return sb.toString(); + } } -- Gitblit v1.9.3