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