|
@ -1,10 +1,17 @@ |
|
|
package org.nl.acs.device_driver.driver; |
|
|
package org.nl.acs.device_driver.driver; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.NumberUtil; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
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.opc.*; |
|
|
import org.nl.acs.udw.UnifiedDataAccessor; |
|
|
import org.nl.acs.udw.UnifiedDataAccessor; |
|
|
import org.nl.acs.udw.UnifiedDataAccessorFactory; |
|
|
import org.nl.acs.udw.UnifiedDataAccessorFactory; |
|
|
import org.nl.acs.udw.UnifiedDataAppService; |
|
|
import org.nl.acs.udw.UnifiedDataAppService; |
|
|
|
|
|
import org.nl.acs.utils.ReadUtil; |
|
|
import org.nl.config.SpringContextHolder; |
|
|
import org.nl.config.SpringContextHolder; |
|
|
import org.openscada.opc.lib.da.Group; |
|
|
import org.openscada.opc.lib.da.Group; |
|
|
import org.openscada.opc.lib.da.Item; |
|
|
import org.openscada.opc.lib.da.Item; |
|
@ -36,6 +43,43 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void checkcontrol2(Map<String, Object> 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<String, Object> itemValues) throws Exception { |
|
|
public void checkcontrol(Map<String, Object> itemValues) throws Exception { |
|
|
Group group = opcServerService.getServer(this.getOpcServer()); |
|
|
Group group = opcServerService.getServer(this.getOpcServer()); |
|
|
Map<String, Object> write = new HashMap(); |
|
|
Map<String, Object> write = new HashMap(); |
|
|