From f35b7028fc2c980f1ad1afefa17e9adf55b7a1d0 Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期四, 30 十一月 2023 08:54:33 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/CanadaMes
---
springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java | 168 +++++++++++++++++++++++++++++++++++---------------------
1 files changed, 105 insertions(+), 63 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..54d6a6d 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
@@ -1,8 +1,16 @@
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;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import com.example.springboot.mapper.AlarmMapper;
@@ -10,88 +18,122 @@
public class Plcalarm extends Thread {
private AlarmMapper alarmMapper;
+ String content = "";
+ String name = "";
+ Integer count = 0;
+
+ public List<String> readValue() {
+ String str = "";
+ BufferedReader bufferedReader = null;
+ FileInputStream fileInputStream;
+ try {
+ // 浠庢枃浠朵腑璇诲彇瀛楄妭鏁版嵁瀛樺叆 fileInputStream
+ fileInputStream = new FileInputStream("CanadaMes-ui/src/configuration/Alarm.json");
+ // 璇诲彇 fileInputStream 涓瓧鑺傚苟灏嗗叾瑙g爜涓哄瓧绗�
+ InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "utf-8");
+ // 鎻愰珮璇诲彇鏁堢巼锛屽湪 BufferedReader 鍐呭寘瑁� InputStreamReader
+ bufferedReader = new BufferedReader(inputStreamReader);
+ String line = null;
+ // 灏� bufferedReader 鍐呭涓�琛屼竴琛岃祴鍊肩粰str
+ while ((line = bufferedReader.readLine()) != null) {
+ str += line;
+ }
+
+ // 灏唖tr瀛楃涓叉牸寮忚浆涓簀son
+ JSONObject jsonObject = new JSONObject(str);
+
+ List<String> arraylistss = new ArrayList<>();
+
+ // 鑾峰彇json涓姤璀︿俊鎭殑鍊�
+ JSONArray AlarmContent = jsonObject.getJSONArray("content");
+ for (int i = 0; i < AlarmContent.size(); i++) {
+ JSONObject ress = (JSONObject) AlarmContent.get(i);
+
+ this.content = ress.getStr("name");
+ arraylistss.add(content);
+ }
+ // 鑾峰彇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");
+
+ }
+
+ return arraylistss;
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
@Override
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) {
+// this.readValue();
+// String PlcAddress = this.name;
+// Integer Plccount = this.count;
- } else {
+ // 鏍规嵁鍦板潃璇诲彇PCL鏁版嵁
+ List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.0.0", 71);
+// List<Boolean> plclist = S7control.getinstance().ReadBits(PlcAddress, Plccount);
+ // System.out.println(plclist);
+ // Boolean[] values = { false, 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,
- // };
- String[] shuzu = {
- "D01 VFD error",
- "D02 VFD error",
- "D03 VFD error",
- "D04 VFD error",
- "D05 VFD error",
- "D06 VFD error",
- "B01 VFD error",
- "B02 VFD error",
- "A01 VFD error",
- "A02 VFD error",
- "A01 servo turn error",
- "A02 servo turn error",
- "A01 servo travel error",
- "A02 servo travel error",
- "B01 servo travel error",
- "B02 servo travel error",
- "D01 DEC error",
- "D01 pos error",
- "D02 DEC error",
- "D02 pos error",
- "D03 DEC error",
- "D03 pos error",
- "D04 DEC error",
- "D04 pos error",
- "D05 DEC error",
- "D05 pos error",
- "D06 DEC error",
- "D06 pos error",
- "A01 DEC error",
- "A01 pos error",
- "A02 DEC error",
- "A02 pos error",
- "B01 IN DEC error",
- "B01 IN pos error",
- "B01 OUT DEC error",
- "B01 OUT pos error",
- "B02 IN DEC error",
- "B02 IN pos error",
- "B02 OUT DEC error",
- "B02 OUT pos error",
- };
+ // 灏嗚幏鍙栫殑甯冨皵绫诲瀷杞崲涓烘暣鏁扮被鍨�
+ List<Integer> Intlist = new ArrayList<>();
+ for (Boolean value : plclist) {
+ Intlist.add(value == true ? 1 : 0);
+
+ }
+
+ // 灏咺ntlist杞崲涓烘暟缁�
+ // System.out.println(Intlist);
+ Integer[] shuzu1 = Intlist.toArray(new Integer[0]);
+
+ // 瀹氫箟鐨勬姤璀﹀唴瀹规暟缁�,鑾峰彇json杩斿洖鐨勯泦鍚�
+ List<String> myCollection;
+ myCollection = readValue();
+ String[] array1 = myCollection.toArray(new String[myCollection.size()]);
+
alarmMapper = WebSocketServer.applicationContext.getBean(AlarmMapper.class);
- for (short i = 0; i < shuzu1.length; i++) {
- // 查询结束时间为null的个数
- short result = alarmMapper.selectnullti(shuzu[i]);
- // 读取PLC对应地址的值为1并且该地址没有结束时间为null的数据,添加一条新的报警信息
+ for (short i = 0; i < array1.length; i++) {
+ // 鏌ヨ瀵瑰簲鎶ヨ淇℃伅缁撴潫鏃堕棿涓簄ull鐨勬潯鏁�
+ short result = alarmMapper.selectnullti(array1[i]);
+ // 璇诲彇鍒癙LC鐨勫�间负1骞朵笖瀵瑰簲鎶ヨ淇℃伅缁撴潫鏃堕棿涓簄ull鐨勬潯鏁扮殑鏉℃暟涓�0
+ // System.out.println(result);
if (shuzu1[i] == 1 && result == 0) {
- alarmMapper.Insertalarm(shuzu[i]);
- }
- // 读取PLC对应地址的值为0并且该地址有结束时间为null的数据,修改该条数据的结束时间
- else if (shuzu1[i] == 0 && result > 0) {
- alarmMapper.updatealarm(shuzu[i]);
+ // 濉姞涓�鏉℃姤璀︿俊鎭�,鏈夊紑濮嬫椂闂�
+ // alarmMapper.Insertalarm(array1[i]);
+ } else if (shuzu1[i] == 0 && result > 0) {
+ // 淇敼璇ユ潯鎶ヨ淇℃伅鐨勭粨鏉熸椂闂�
+ alarmMapper.updatealarm(array1[i]);
}
}
}
--
Gitblit v1.8.0