¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.stylefeng.guns.opcua.init; |
| | | |
| | | import cn.stylefeng.guns.opcua.client.ClientHandler; |
| | | import cn.stylefeng.guns.opcua.controller.OpcuaConfController; |
| | | import cn.stylefeng.guns.opcua.entity.NodeEntity; |
| | | import cn.stylefeng.guns.opcua.model.params.OpcuaConfParam; |
| | | import cn.stylefeng.guns.opcua.model.result.OpcuaConfResult; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.CommandLineRunner; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | @Component |
| | | @Slf4j |
| | | public class OpcusConfigInit implements CommandLineRunner { |
| | | |
| | | @Autowired |
| | | private ClientHandler clientHandler; |
| | | |
| | | @Autowired |
| | | private OpcuaConfController opcuaConfController; |
| | | |
| | | @Override |
| | | public void run(String... args) throws Exception { |
| | | try { |
| | | OpcuaConfParam opcuaConfParam=new OpcuaConfParam(); |
| | | opcuaConfParam.setSubscribe(1); //设置æ¥è¯¢æ¡ä»¶ï¼æ¯å¦è®¢é
ç¶æä¸º1çæææ°æ®. |
| | | List<OpcuaConfResult> nodeslist=opcuaConfController.mylist(opcuaConfParam); |
| | | clientHandler.connect(); |
| | | if (nodeslist != null && nodeslist.size() > 0) { |
| | | for (OpcuaConfResult opcuaConfResult : nodeslist) { |
| | | List<NodeEntity> nodes = Stream.of(opcuaConfResult.getNode()) |
| | | .map(id -> NodeEntity.builder().index(2).identifier(id).build()).collect(Collectors.toList()); |
| | | clientHandler.subscribe(nodes); |
| | | } |
| | | log.info("åå§åOPC订é
" + nodeslist.size() + "æ¡ï¼"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.info("éªè´§ï¼æå¯å¨å¤±è´¥äºï¼"); |
| | | } |
| | | log.info("éªè´§ï¼æå¯å¨æåäºï¼"); |
| | | } |
| | | } |