wu
2024-01-18 4f3aa71ed602c1abbafa638591b20abc3c7be224
springboot-vue3/src/main/java/com/example/springboot/component/PlcInteractionState.java
New file
@@ -0,0 +1,101 @@
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(100);
            } 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);
//            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 ","x21 ","x21 ","x21 ","x21 ","x21 ","x21 ","x21 "};
//            List<String> 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<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("InteractionState");
            if (sendwServer != null) {
                for (WebSocketServer webserver : sendwServer) {
                    webserver.sendMessage(jsonObject.toString());
                }
            }
        }
    }
}