wuyouming666
2024-05-09 c0b596275d583b0874e501f49a90e7a1dfd879e3
springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java
@@ -2,6 +2,7 @@
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
import java.io.FileInputStream;
@@ -15,6 +16,7 @@
import com.example.springboot.mapper.AlarmMapper;
@Slf4j
public class Plcalarm extends Thread {
  private AlarmMapper alarmMapper;
@@ -78,16 +80,12 @@
    while (this != null) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
//      this.readValue();
//      String PlcAddress = this.name;
//      Integer Plccount = this.count;
        this.readValue();
      String PlcAddress = this.name;
      Integer Plccount = this.count;
      // 根据地址读取PCL数据
      List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.0.0", 71);
      List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.0.0", Plccount);
//      List<Boolean> plclist = S7control.getinstance().ReadBits(PlcAddress, Plccount);
      // System.out.println(plclist);
      // Boolean[] values = { false, false, true, false, true, false, true, false,
@@ -106,7 +104,9 @@
          for (WebSocketServer webserver : sendwServer) {
            webserver.sendMessage(jsonObject.toString());
          }
        }
            // 将获取的布尔类型转换为整数类型
            List<Integer> Intlist = new ArrayList<>();
            for (Boolean value : plclist) {
@@ -115,7 +115,8 @@
            }
            // 将Intlist转换为数组
            // System.out.println(Intlist);
//             System.out.println(Intlist);
//     System.out.println(Intlist.toArray().length);
            Integer[] shuzu1 = Intlist.toArray(new Integer[0]);
            // 定义的报警内容数组,获取json返回的集合
@@ -128,7 +129,7 @@
              // 查询对应报警信息结束时间为null的条数
              short result = alarmMapper.selectnullti(array1[i]);
              // 读取到PLC的值为1并且对应报警信息结束时间为null的条数的条数为0
              // System.out.println(result);
    //System.out.println(result);
              if (shuzu1[i] == 1 && result == 0) {
                // 填加一条报警信息,有开始时间
                alarmMapper.Insertalarm(array1[i]);
@@ -138,8 +139,10 @@
              }
            }
          }
        }
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
}
}