springboot-vue3/src/main/java/com/example/springboot/component/Plcsign.java
@@ -1,8 +1,8 @@
package com.example.springboot.component;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -12,19 +12,19 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
public class Plcsign extends Thread {
  // 用于存储应用程序的配置信息
  private Configuration config;
    public Plcsign() throws IOException {
        config = new Configuration("config.properties");
    }
  String name = "";
  Integer count = 0;
  public void readValue() {
    String str = "";
    BufferedReader bufferedReader = null;
@@ -41,20 +41,20 @@
      while ((line = bufferedReader.readLine()) != null) {
        str += line;
      }
      // 将str字符串格式转为json
      JSONObject jsonObject = new JSONObject(str);
      // 获取json中的值
      JSONArray address = jsonObject.getJSONArray("address");
      for (int i = 0; i < address.size(); i++) {
        JSONObject ress = (JSONObject) address.get(i);
        this.name = ress.getStr("name");
        this.count = ress.getInt("count");
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
@@ -63,7 +63,7 @@
      e.printStackTrace();
    }
  }
  @Override
  public void run() {
    while (this != null) {
@@ -74,27 +74,33 @@
      }
       List<String> addressList21 = Arrays.asList(config.getProperty("PlcIO.State").split(","));
       List<Boolean> plclist = S7control.getinstance().readBits(addressList21);
       List<String> addressListName = Arrays.asList(config.getProperty("PlcIO.Name").split(","));
      //  System.out.println("急停"+S7control.getinstance().ReadBits("DB10.0.5", 1));
      //  int index = 0;
      // for (String item : addressList21) {
      //   System.out.println("地址:"+item+"值"+plclist.get(index)+"下标"+index);
      //   index++;
      // }
      
      if (plclist != null) {
        // 将获取的布尔类型转换为整数类型
        List<Integer> Intlist = new ArrayList<>();
        // System.out.println("长度"+plclist.size());
        for (Boolean value : plclist) {
          if (value != null) {
            Intlist.add(value == true ? 0 : 1);
          }else {
            Intlist.add(1);
            System.out.println("null");
          }
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.append("sig", Intlist);
        jsonObject.append("addressListName", addressListName);
//        WebSocketServer sendwServer3 = WebSocketServer.sessionMap.get("Sign");
//        if (sendwServer3 != null) {
//          sendwServer3.sendMessage(jsonObject.toString());
//        }
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("Sign");
        if (sendwServer != null) {
          for (WebSocketServer webserver : sendwServer) {
@@ -104,4 +110,4 @@
      }
    }
  }
}
}