From 116210d39e8fca7402c19fe7ab3911a2315f10c3 Mon Sep 17 00:00:00 2001 From: "USER-20220102CG\\noblelift" <546428999@qq.com> Date: Tue, 10 Sep 2024 20:20:17 +0800 Subject: [PATCH] =?UTF-8?q?rev=20=E9=A9=B1=E5=8A=A8=E4=BF=A1=E5=8F=B7?= =?UTF-8?q?=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BeltConveyorDeviceDriver.java | 2 +- .../driver/AbstractOpcDeviceDriver.java | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/belt_conveyor/BeltConveyorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/belt_conveyor/BeltConveyorDeviceDriver.java index fe9ac51..2095577 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/belt_conveyor/BeltConveyorDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/belt_conveyor/BeltConveyorDeviceDriver.java @@ -776,7 +776,7 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements luceneExecuteLogService.deviceExecuteLog(logDto); logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); try { - this.checkcontrol(itemMap); + this.checkcontrol2(itemMap); } catch (Exception e) { e.printStackTrace(); } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java index 008b431..973c886 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java @@ -1,10 +1,17 @@ package org.nl.acs.device_driver.driver; +import cn.hutool.core.util.NumberUtil; import lombok.extern.slf4j.Slf4j; +import org.eclipse.milo.opcua.sdk.client.OpcUaClient; +import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; +import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId; +import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode; +import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; import org.nl.acs.opc.*; import org.nl.acs.udw.UnifiedDataAccessor; import org.nl.acs.udw.UnifiedDataAccessorFactory; import org.nl.acs.udw.UnifiedDataAppService; +import org.nl.acs.utils.ReadUtil; import org.nl.config.SpringContextHolder; import org.openscada.opc.lib.da.Group; import org.openscada.opc.lib.da.Item; @@ -36,6 +43,43 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc } + public void checkcontrol2(Map itemValues) throws Exception { + OpcUaClient client = null; + try { + client = ReadUtil.createClient(); + client.connect().get(); + Iterator it = itemValues.keySet().iterator(); + + while (it.hasNext()) { + String key = (String) it.next(); + Object o = itemValues.get(key); + if (o == null || "".equals(o)) { + break; + } + //节点 + NodeId nodeId = new NodeId(2, key); + //创建数据对象,此处的数据对象一定要定义类型,不然会出现类型错误,导致无法写入 + DataValue nowValue = null; + if(NumberUtil.isDouble(String.valueOf(o))){ + nowValue = new DataValue(new Variant(Double.valueOf(o.toString())), null, null); + } else if (NumberUtil.isNumber(String.valueOf(o))) { + nowValue = new DataValue(new Variant(Integer.valueOf(o.toString())), null, null); + } else { + nowValue = new DataValue(new Variant(String.valueOf(o)), null, null); + } + //写入节点数据 + StatusCode statusCode = client.writeValue(nodeId, nowValue).join(); + System.out.println( key +" 信号写入结果:" + statusCode.isGood()); + } + client.disconnect(); + }catch (Exception e) { + client.disconnect(); + throw new RuntimeException(e); + } + } + + + public void checkcontrol(Map itemValues) throws Exception { Group group = opcServerService.getServer(this.getOpcServer()); Map write = new HashMap();