From db1edf54ea55cf01f8794627b9e38a549afb951f Mon Sep 17 00:00:00 2001 From: wu <731351411@qq.com> Date: 星期一, 27 十一月 2023 09:15:22 +0800 Subject: [PATCH] 更新理片笼逻辑 --- springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java | 49 +++++++++++++++++++++++++++++-------------------- 1 files changed, 29 insertions(+), 20 deletions(-) diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java b/springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java index 1597562..ca035a8 100644 --- a/springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java +++ b/springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java @@ -3,6 +3,7 @@ import cn.hutool.json.JSONObject; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import com.example.springboot.mapper.AlarmMapper; @@ -14,31 +15,39 @@ public void run() { while (this != null) { try { - Thread.sleep(10000); + Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } - - List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.DBx0.0", 40); - if (plclist == null) { - - } else { + // 鏍规嵁鍦板潃璇诲彇PCL鏁版嵁 + List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.0.0", 40); + // 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(); - jsonObject.append("params", plclist); WebSocketServer sendwServer = WebSocketServer.sessionMap.get("alarm"); if (sendwServer != null) { sendwServer.sendMessage(jsonObject.toString()); } - // 将读取到的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); + + } + + // 灏咺ntlist杞崲涓烘暟缁� + Integer[] shuzu1 = Intlist.toArray(new Integer[0]); + + // 瀹氫箟鐨勬姤璀﹀唴瀹规暟缁� String[] shuzu = { "D01 VFD error", "D02 VFD error", @@ -82,15 +91,15 @@ "B02 OUT pos error", }; alarmMapper = WebSocketServer.applicationContext.getBean(AlarmMapper.class); - for (short i = 0; i < shuzu1.length; i++) { - // 查询结束时间为null的个数 + for (short i = 0; i < shuzu.length; i++) { + // 鏌ヨ瀵瑰簲鎶ヨ淇℃伅缁撴潫鏃堕棿涓簄ull鐨勬潯鏁� short result = alarmMapper.selectnullti(shuzu[i]); - // 读取PLC对应地址的值为1并且该地址没有结束时间为null的数据,添加一条新的报警信息 + // 璇诲彇鍒癙LC鐨勫�间负1骞朵笖瀵瑰簲鎶ヨ淇℃伅缁撴潫鏃堕棿涓簄ull鐨勬潯鏁扮殑鏉℃暟涓�0 if (shuzu1[i] == 1 && result == 0) { + // 濉姞涓�鏉℃姤璀︿俊鎭�,鏈夊紑濮嬫椂闂� alarmMapper.Insertalarm(shuzu[i]); - } - // 读取PLC对应地址的值为0并且该地址有结束时间为null的数据,修改该条数据的结束时间 - else if (shuzu1[i] == 0 && result > 0) { + } else if (shuzu1[i] == 0 && result > 0) { + // 淇敼璇ユ潯鎶ヨ淇℃伅鐨勭粨鏉熸椂闂� alarmMapper.updatealarm(shuzu[i]); } } -- Gitblit v1.8.0