From 3acd15a13d9edfde79ee125af135d2a089b23872 Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期四, 09 十一月 2023 15:08:26 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/CanadaMes
---
springboot-vue3/src/main/java/com/example/springboot/component/Plcaction.java | 126 +++++++++++++++++++++++++++++------------
1 files changed, 89 insertions(+), 37 deletions(-)
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/Plcaction.java b/springboot-vue3/src/main/java/com/example/springboot/component/Plcaction.java
index cc0f805..f601cbb 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/Plcaction.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/Plcaction.java
@@ -1,12 +1,61 @@
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;
public class Plcaction extends Thread {
+ String name = "";
+ Integer count = 0;
+
+ public void readValue() {
+ String str = "";
+ BufferedReader bufferedReader = null;
+ FileInputStream fileInputStream;
+ try {
+ // 浠庢枃浠朵腑璇诲彇瀛楄妭鏁版嵁瀛樺叆 fileInputStream
+ fileInputStream = new FileInputStream("CanadaMes-ui/src/configuration/Action.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);
+
+ // 鑾峰彇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");
+
+ }
+
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
@Override
public void run() {
while (this != null) {
@@ -16,23 +65,27 @@
e.printStackTrace();
}
-// List<Boolean> paramlist = S7control.getinstance().ReadBits("DB100.DBW", 12);
-////
-// JSONObject jsonObject = new JSONObject();
-// jsonObject.append("params", new short[]{1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0});
+ // 璋冪敤鏂规硶锛岃繘琛岃祴鍊�
+ this.readValue();
+ String PlcAddress = this.name;
+ Integer Plccount = this.count;
+ // System.out.println(PlcAddress);
- List<Boolean> paramlist = S7control.getinstance().ReadBits("DB2.DBX0.0 ", 26);
-// Boolean[] values = {true, true,true, true,true, true,true, true,true, true,true, true,true, true,true, true,true, true,true, true,true, true,true, true,false, true};
-// List<Boolean> paramlist = new ArrayList<>(Arrays.asList(values));
- if (paramlist == null) {
+ // List<Boolean> paramlist = S7control.getinstance().ReadBits("DB2.0.0", 26);
+ Boolean[] values = { false, true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true, true, true, true, true, true, true,
+ true, false, true };
+ List<Boolean> paramlist = new ArrayList<>(Arrays.asList(values));
- } else {
+ if (paramlist != null) {
+
short[] params = new short[paramlist.size()];
for (int i = 0; i < paramlist.size(); i++) {
boolean value = paramlist.get(i);
params[i] = value ? (short) 1 : (short) 0;
}
+
JSONObject jsonObject = new JSONObject();
jsonObject.append("params", params);
WebSocketServer sendwServer = WebSocketServer.sessionMap.get("action");
@@ -41,42 +94,41 @@
}
}
-
WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("action");
if (webSocketServer != null) {
- List<String> messages = webSocketServer.getMessages();
+ List<String> messages = webSocketServer.getMessages();
- String addressList = "DB100.DBW0";
+ String addressList = "DB2.0.0";
- if (!messages.isEmpty()) {
- // 灏嗘渶鍚庝竴涓秷鎭浆鎹负鏁存暟绫诲瀷鐨勫垪琛�
- String lastMessage = messages.get(messages.size() - 1);
- System.out.println("messages锛�" + messages);
- String[] parts = lastMessage.split(",");
- List<Integer> messageValues = new ArrayList<>();
- for (String part : parts) {
- try {
- // 浣跨敤姝e垯琛ㄨ揪寮忔竻闄ら潪鏁板瓧瀛楃
- String cleanedPart = part.replaceAll("[^0-9-]", "");
- Integer value = Integer.parseInt(cleanedPart.trim());
- messageValues.add(value);
- } catch (NumberFormatException e) {
- // 濡傛灉鏃犳硶瑙f瀽涓烘暣鏁扮被鍨嬶紝鍒欏拷鐣ヨ閮ㄥ垎
- e.printStackTrace();
- }
+ if (!messages.isEmpty()) {
+ // 灏嗘渶鍚庝竴涓秷鎭浆鎹负鏁存暟绫诲瀷鐨勫垪琛�
+ String lastMessage = messages.get(messages.size() - 1);
+ System.out.println("messages锛�" + messages);
+ String[] parts = lastMessage.split(",");
+ List<Integer> messageValues = new ArrayList<>();
+ for (String part : parts) {
+ try {
+ // 浣跨敤姝e垯琛ㄨ揪寮忔竻闄ら潪鏁板瓧瀛楃
+ String cleanedPart = part.replaceAll("[^0-9-]", "");
+ Integer value = Integer.parseInt(cleanedPart.trim());
+ messageValues.add(value);
+ } catch (NumberFormatException e) {
+ // 濡傛灉鏃犳硶瑙f瀽涓烘暣鏁扮被鍨嬶紝鍒欏拷鐣ヨ閮ㄥ垎
+ e.printStackTrace();
}
+ }
- // 灏嗘秷鎭�艰浆鎹负甯冨皵鍒楄〃
- List<Boolean> messageBooleans = new ArrayList<>();
- for (Integer value : messageValues) {
- messageBooleans.add(value == 1 ? true : false);
- }
+ // 灏嗘秷鎭�艰浆鎹负甯冨皵鍒楄〃
+ List<Boolean> messageBooleans = new ArrayList<>();
+ for (Integer value : messageValues) {
+ messageBooleans.add(value == 1 ? true : false);
+ }
- // 灏嗗竷灏斿垪琛ㄥ啓鍏� PLC
- S7control.getinstance().WriteBit(addressList, messageBooleans);
- System.out.println("messageValues锛�" + messageBooleans);
- System.out.println("addressList锛�" + addressList);
+ // 灏嗗竷灏斿垪琛ㄥ啓鍏� PLC
+ S7control.getinstance().WriteBit(addressList, messageBooleans);
+ System.out.println("messageValues锛�" + messageBooleans);
+ System.out.println("addressList锛�" + addressList);
// 娓呯┖娑堟伅鍒楄〃
webSocketServer.clearMessages();
}
--
Gitblit v1.8.0