| | |
| | | public void handle(NodeId id, Variant value){ |
| | | if (b == null || 0 > b.size()) { |
| | | DaOpcuaConfig opcuaConfParam=new DaOpcuaConfig(); |
| | | opcuaConfParam.setSubscribe(1L); |
| | | opcuaConfParam.setSubscribe("Y"); |
| | | b=daOpcuaConfigService.selectDaOpcuaConfigList(opcuaConfParam); |
| | | } |
| | | //使用Stream API在List<T>中查找元素 |
| | |
| | | .findAny() |
| | | .orElse(null); |
| | | try { |
| | | Class<?> clazz = Class.forName(daOpcuaConfig.getrModule()); |
| | | Class<?> clazz = Class.forName("com.jcdm.main.da.opcuaconfig.cert.MethodName"); |
| | | Method method = clazz.getMethod(daOpcuaConfig.getrFunction(), new Class[] { String.class, String.class }); |
| | | if (value.isNull()){ |
| | | method.invoke(clazz.newInstance(),new Object[] { |
| | | new String(id.getIdentifier().toString()), new String("") }); |
| | | }else{ |
| | | method.invoke(clazz.newInstance(),new Object[] { |
| | | new String(id.getIdentifier().toString()), new String(value.getValue().toString()) }); |
| | | } |
| | | } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | |
| | | InvocationTargetException e) { |
| | | e.printStackTrace(); |
| | |
| | | /** |
| | | * 方法描述: 读取多个点位的值 |
| | | * |
| | | * @param keys 点位集合 |
| | | * @param nodeIdList 点位集合 |
| | | * @return {@link List<DataValue>} |
| | | * @throws |
| | | */ |
| | | public static List<DataValue> readValues(Set<String> keys){ |
| | | List<NodeId> nodeIdList=new ArrayList<>(500); |
| | | keys.forEach(e->{ |
| | | NodeId nodeId = new NodeId(2, e); |
| | | nodeIdList.add(nodeId); |
| | | }); |
| | | public static List<DataValue> readValues(List<NodeId> nodeIdList){ |
| | | try { |
| | | List<DataValue> dataValues=client.readValues(0.0, TimestampsToReturn.Both,nodeIdList).get(); |
| | | return dataValues; |
| | |
| | | log.info("Value={}", value); |
| | | |
| | | Variant variant = value.getValue(); |
| | | log.info("Variant={}", variant.getValue()); |
| | | |
| | | log.info("BackingClass={}", BuiltinDataType.getBackingClass(variant.getDataType().get())); |
| | | if(null == variant.getValue()) |
| | | { |
| | | return null; |
| | | }else{ |
| | | return variant.getValue().toString(); |
| | | } |
| | | |
| | | return variant.getValue().toString(); |
| | | } |
| | | |
| | | |