From a7c91f14d9a671a5ad1def32e2a88d4938ecba33 Mon Sep 17 00:00:00 2001 From: yantian yue <306727702@qq.com> Date: 星期五, 20 十月 2023 15:47:56 +0800 Subject: [PATCH] OPCUA更新 --- guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java | 36 +++++++++++++++++++++++++++++++----- 1 files changed, 31 insertions(+), 5 deletions(-) diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java index 44743ac..cfb7f26 100644 --- a/guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java @@ -51,6 +51,8 @@ // 瀹㈡埛绔疄渚� private OpcUaClient client = null; + public List<OpcuaConfResult> b = null; + @Autowired private ClientRunner clientRunner; @@ -113,8 +115,6 @@ return "鎵句笉鍒板鎴风锛屾搷浣滃け璐�"; } -// List<Node> ns = client.getAddressSpace().browse(new NodeId(2, "妯℃嫙閫氶亾涓�.妯℃嫙璁惧涓�")).get(); - // 鏌ヨ璁㈤槄瀵硅薄锛屾病鏈夊垯鍒涘缓 UaSubscription subscription = null; ImmutableList<UaSubscription> subscriptionList = client.getSubscriptionManager().getSubscriptions(); @@ -148,7 +148,7 @@ // 鍒涘缓鐩戞帶椤癸紝骞朵笖娉ㄥ唽鍙橀噺鍊兼敼鍙樻椂鍊欑殑鍥炶皟鍑芥暟 subscription.createMonitoredItems(TimestampsToReturn.Both, requests, (item, id) -> { item.setValueConsumer((i, v) -> { - handle(i.getReadValueId().getNodeId(), v.getValue()); + handle2(i.getReadValueId().getNodeId(), v.getValue()); }); }).get(); @@ -161,13 +161,13 @@ * @CreateTime 2023骞�10鏈�13鏃� */ - public void handle(NodeId id, Variant value){ + /*public void handle(NodeId id, Variant value){ long startTime = System.currentTimeMillis(); OpcuaConfParam opcuaConfParam=new OpcuaConfParam(); opcuaConfParam.setNode(id.getIdentifier().toString()); List<OpcuaConfResult> a=opcuaConfController.mylist(opcuaConfParam); - + log.info("鏁版嵁搴撹闂唬鐮佹墽琛屾椂闂达細" + (System.currentTimeMillis() - startTime) + "姣"); String str1 = id.getIdentifier().toString()+":"+value.getValue().toString(); try { Class<?> clazz = Class.forName(a.get(0).getRModule()); @@ -179,8 +179,34 @@ e.printStackTrace(); } log.info("浠g爜鎵ц鏃堕棿锛�" + (System.currentTimeMillis() - startTime) + "姣"); + }*/ + public void handle2(NodeId id, Variant value){ + long sTime = System.currentTimeMillis(); + if (b == null || 0 > b.size()) { + OpcuaConfParam opcuaConfParam=new OpcuaConfParam(); + opcuaConfParam.setSubscribe(1); + b=opcuaConfController.mylist(opcuaConfParam); + } + log.info("鏁版嵁搴撹闂唬鐮佹墽琛屾椂闂达細" + (System.currentTimeMillis() - sTime) + "姣"); + String str1 = id.getIdentifier().toString()+":"+value.getValue().toString(); + + OpcuaConfResult opcuaConfResult = b.stream() + .filter(customer ->id.getIdentifier().toString().equals(customer.getNode())) + .findAny() + .orElse(null); + try { + Class<?> clazz = Class.forName(opcuaConfResult.getRModule()); + Method method = clazz.getMethod(opcuaConfResult.getRFunction(), String.class); + + method.invoke(clazz.newInstance(), str1); + } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | + InvocationTargetException e) { + e.printStackTrace(); + } + log.info("浠g爜鎵ц鏃堕棿锛�" + (System.currentTimeMillis() - sTime) + "姣"); } + /** * @MethodName: write * @Description: 鍙樿妭鐐归噺鍐欏叆 -- Gitblit v1.9.3