| | |
| | | |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.FileInputStream; |
| | |
| | | |
| | | import com.example.springboot.mapper.AlarmMapper; |
| | | |
| | | @Slf4j |
| | | public class Plcalarm extends Thread { |
| | | private AlarmMapper alarmMapper; |
| | | |
| | |
| | | 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, |
| | |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | |
| | | } |
| | | |
| | | } |
| | | // 将获取的布尔类型转换为整数类型 |
| | | List<Integer> Intlist = new ArrayList<>(); |
| | | for (Boolean value : plclist) { |
| | |
| | | } |
| | | |
| | | // 将Intlist转换为数组 |
| | | // System.out.println(Intlist); |
| | | // System.out.println(Intlist); |
| | | // System.out.println(Intlist.toArray().length); |
| | | Integer[] shuzu1 = Intlist.toArray(new Integer[0]); |
| | | |
| | | // 定义的报警内容数组,获取json返回的集合 |
| | |
| | | // 查询对应报警信息结束时间为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]); |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |