| | |
| | | import cn.hutool.json.JSONObject; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | import com.example.springboot.mapper.AlarmMapper; |
| | |
| | | } |
| | | |
| | | List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.DBx0.0", 40); |
| | | if (plclist == null) { |
| | | |
| | | } else { |
| | | // Boolean[] values = { true, false, true, false, true, false, true, false, |
| | | // true, false, true, false, true, false, |
| | | // true, false, true, false, true, false, true, false, true, false, true, false, |
| | | // true, false, true, false, true, |
| | | // false, true, false, true, false, |
| | | // true, false, true, false }; |
| | | // List<Boolean> plclist = new ArrayList<>(Arrays.asList(values)); |
| | | if (plclist != null) { |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | |
| | |
| | | if (sendwServer != null) { |
| | | sendwServer.sendMessage(jsonObject.toString()); |
| | | } |
| | | // 将读取plc数据的plclist转换为数组 |
| | | Short[] shuzu1 = plclist.toArray(new Short[0]); |
| | | // Short[] shuzu1 = { |
| | | // 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, |
| | | // 1, 0, 1, 0, 0, |
| | | // 1, 0, 1, 0, 1, 0, 1, 0, 1, |
| | | // }; |
| | | |
| | | // 将获取的布尔类型转换为整数类型 |
| | | List<Integer> Intlist = new ArrayList<>(); |
| | | for (Boolean value : plclist) { |
| | | Intlist.add(value == true ? 1 : 0); |
| | | |
| | | } |
| | | // 将Intlist转换为数组 |
| | | Integer[] shuzu1 = Intlist.toArray(new Integer[0]); |
| | | |
| | | String[] shuzu = { |
| | | "D01 VFD error", |
| | |
| | | "B02 OUT pos error", |
| | | }; |
| | | alarmMapper = WebSocketServer.applicationContext.getBean(AlarmMapper.class); |
| | | for (short i = 0; i < shuzu1.length; i++) { |
| | | for (short i = 0; i < shuzu.length; i++) { |
| | | short result = alarmMapper.selectnullti(shuzu[i]); |
| | | if (shuzu1[i] == 1 && result == 0) { |
| | | alarmMapper.Insertalarm(shuzu[i]); |