| | |
| | | |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | public class PlcInteractionState extends Thread { |
| | | private Configuration config; |
| | | |
| | |
| | | config = new Configuration("config.properties"); |
| | | } |
| | | |
| | | |
| | | // 创建一个自定义的 S7 控制器消息处理器对象 |
| | | MessageHandler customS7Control = new MessageHandler(); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void run() { |
| | | while (this != null) { |
| | | try { |
| | | Thread.sleep(100); |
| | | // this.readValue(); |
| | | // String PlcAddress = this.name; |
| | | // Integer Plccount = this.count; |
| | | |
| | | List<String> addresses = Arrays |
| | | .asList(config.getProperty("PlcInteractionState.MESImporttask").split(",")); |
| | | |
| | | List<String> arraylist = S7control.getinstance().readStringsandword(addresses); |
| | | // System.out.println(arraylist); |
| | | List<String> addresses2 = Arrays |
| | | .asList(config.getProperty("PlcInteractionState.PLCImporttask").split(",")); |
| | | |
| | | List<String> arraylist2 = S7control.getinstance().readStringsandword(addresses2); |
| | | |
| | | List<String> addresses3 = Arrays |
| | | .asList(config.getProperty("PlcInteractionState.MESProductiontask").split(",")); |
| | | |
| | | List<String> arraylist3 = S7control.getinstance().readStringsandword(addresses3); |
| | | |
| | | List<String> addresses4 = Arrays |
| | | .asList(config.getProperty("PlcInteractionState.PLCProductiontask").split(",")); |
| | | |
| | | List<String> arraylist4 = S7control.getinstance().readStringsandword(addresses4); |
| | | |
| | | List<String> addresses5 = Arrays |
| | | .asList(config.getProperty("PlcInteractionState.MEStaskinformation").split(",")); |
| | | List<String> arraylist5 = S7control.getinstance().readStringsandword(addresses5); |
| | | |
| | | List<String> addresses6 = Arrays |
| | | .asList(config.getProperty("PlcInteractionState.MEStaskinformation2").split(",")); |
| | | List<String> arraylist6 = S7control.getinstance().readStringsandword(addresses6); |
| | | |
| | | // String[] values = { ".x11","x21 ","x21 ","x21 ","x21 ","x21"}; |
| | | // List<String> arraylist = new ArrayList<>(Arrays.asList(values)); |
| | | // String[] values2 = { ".x11 ","x21 ","x21 ","x21 ","x21 ","x21 ","x21 "}; |
| | | // List<String> arraylist2 = new ArrayList<>(Arrays.asList(values2)); |
| | | // String[] values3 = { ".x11 ","x21 ","x21 ","x21 ","x21 ","x21 "}; |
| | | // List<String> arraylist3 = new ArrayList<>(Arrays.asList(values3)); |
| | | // String[] values4 = { ".x11 ","x21 ","x21 ","x21 "}; |
| | | // List<String> arraylist4 = new ArrayList<>(Arrays.asList(values4)); |
| | | // String[] values5 = { ".x11 ","x21 ","x21 ","b02","x21 ","x21 "}; |
| | | // List<String> arraylist5 = new ArrayList<>(Arrays.asList(values5)); |
| | | // |
| | | // String[] values6 = { "x21 ","x21 ","x21 ","x21 ","x21 ","x21 ","x21 "}; |
| | | // List<String> arraylist6 = new ArrayList<>(Arrays.asList(values6)); |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | // System.out.println(arraylist6); |
| | | JSONArray jsonArray = new JSONArray(); |
| | | jsonArray.put(arraylist); |
| | | jsonArray.put(arraylist2); |
| | | jsonArray.put(arraylist3); |
| | | jsonArray.put(arraylist4); |
| | | jsonArray.put(arraylist5); |
| | | jsonArray.put(arraylist6); |
| | | jsonObject.put("zuhe1", jsonArray); |
| | | |
| | | // WebSocketServer sendwServer = |
| | | // WebSocketServer.sessionMap.get("ManualonePosition"); |
| | | // if (sendwServer != null) { |
| | | // sendwServer.sendMessage(jsonObject.toString()); |
| | | // } |
| | | |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("InteractionState"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | if(webserver!=null&&webserver.session.isOpen()){ |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | }else{ |
| | | log.info("InteractionState is closed"); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // this.readValue(); |
| | | // String PlcAddress = this.name; |
| | | // Integer Plccount = this.count; |
| | | |
| | | |
| | | |
| | | List<String> addresses = Arrays.asList(config.getProperty("PlcInteractionState.MESImporttask").split(",")); |
| | | |
| | | List<String> arraylist = S7control.getinstance().readStringsandword(addresses); |
| | | // System.out.println(arraylist); |
| | | List<String> addresses2 = Arrays.asList(config.getProperty("PlcInteractionState.PLCImporttask").split(",")); |
| | | |
| | | List<String> arraylist2 = S7control.getinstance().readStringsandword(addresses2); |
| | | |
| | | List<String> addresses3 = Arrays.asList(config.getProperty("PlcInteractionState.MESProductiontask").split(",")); |
| | | |
| | | List<String> arraylist3 = S7control.getinstance().readStringsandword(addresses3); |
| | | |
| | | |
| | | List<String> addresses4 = Arrays.asList(config.getProperty("PlcInteractionState.PLCProductiontask").split(",")); |
| | | |
| | | List<String> arraylist4 = S7control.getinstance().readStringsandword(addresses4); |
| | | |
| | | |
| | | List<String> addresses5 = Arrays.asList(config.getProperty("PlcInteractionState.MEStaskinformation").split(",")); |
| | | List<String> arraylist5 = S7control.getinstance().readStringsandword(addresses5); |
| | | |
| | | List<String> addresses6 = Arrays.asList(config.getProperty("PlcInteractionState.MEStaskinformation2").split(",")); |
| | | List<String> arraylist6 = S7control.getinstance().readStringsandword(addresses6); |
| | | |
| | | |
| | | // String[] values = { ".x11","x21 ","x21 ","x21 ","x21 ","x21"}; |
| | | // List<String> arraylist = new ArrayList<>(Arrays.asList(values)); |
| | | // String[] values2 = { ".x11 ","x21 ","x21 ","x21 ","x21 ","x21 ","x21 "}; |
| | | // List<String> arraylist2 = new ArrayList<>(Arrays.asList(values2)); |
| | | // String[] values3 = { ".x11 ","x21 ","x21 ","x21 ","x21 ","x21 "}; |
| | | // List<String> arraylist3 = new ArrayList<>(Arrays.asList(values3)); |
| | | // String[] values4 = { ".x11 ","x21 ","x21 ","x21 "}; |
| | | // List<String> arraylist4 = new ArrayList<>(Arrays.asList(values4)); |
| | | // String[] values5 = { ".x11 ","x21 ","x21 ","b02","x21 ","x21 "}; |
| | | // List<String> arraylist5 = new ArrayList<>(Arrays.asList(values5)); |
| | | // |
| | | // String[] values6 = { "x21 ","x21 ","x21 ","x21 ","x21 ","x21 ","x21 "}; |
| | | // List<String> arraylist6 = new ArrayList<>(Arrays.asList(values6)); |
| | | |
| | | |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | // System.out.println(arraylist6); |
| | | JSONArray jsonArray = new JSONArray(); |
| | | jsonArray.put(arraylist); |
| | | jsonArray.put(arraylist2); |
| | | jsonArray.put(arraylist3); |
| | | jsonArray.put(arraylist4); |
| | | jsonArray.put(arraylist5); |
| | | jsonArray.put(arraylist6); |
| | | jsonObject.put("zuhe1", jsonArray); |
| | | |
| | | |
| | | // WebSocketServer sendwServer = WebSocketServer.sessionMap.get("ManualonePosition"); |
| | | // if (sendwServer != null) { |
| | | // sendwServer.sendMessage(jsonObject.toString()); |
| | | // } |
| | | |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("InteractionState"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |