From 58d7b0e12ccd92cf3934f6582b51b5fbcecaa39a Mon Sep 17 00:00:00 2001
From: ZengTao <2773468879@qq.com>
Date: 星期四, 09 五月 2024 09:42:41 +0800
Subject: [PATCH] 修改注入方式
---
springboot-vue3/src/main/java/com/example/springboot/component/S7control.java | 47 +++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/S7control.java b/springboot-vue3/src/main/java/com/example/springboot/component/S7control.java
index 0eb3b69..ce4f674 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/S7control.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/S7control.java
@@ -223,7 +223,15 @@
if (s7PLC==null)
return null;
// List<String> addresslist = GetAddressList(address, count, 16);
- return s7PLC.readByte(address,count);
+
+ try {
+ return s7PLC.readByte(address, count);
+ }catch (Exception e) {
+ // 澶勭悊寮傚父
+ System.out.println("璇诲彇 " + address + " 澶辫触锛�" + e.getMessage());
+ return null;
+ }
+
}
/**
@@ -279,6 +287,41 @@
return result;
}
+
+
+
+
+
+ public List<String> readStringsandword(List<String> addressList) {
+ if (s7PLC == null) {
+ return null;
+ }
+ List<String> result = new ArrayList<>();
+ for (String address : addressList) {
+ try {
+ if (address.contains("-")) {
+ address = address.substring(0, address.indexOf("-"));
+
+ byte[] bytes = s7PLC.readByte(address, 14);
+ if (bytes != null) {
+ String str = new String(bytes, StandardCharsets.UTF_8);
+ result.add(str);
+ }
+
+ } else {
+ Short value = s7PLC.readInt16(address);
+ result.add(value.toString());
+
+ }
+ } catch (Exception e) {
+ System.out.println("璇诲彇 " + address + " 澶辫触锛�" + e.getMessage());
+ result.add(null);
+ }
+ }
+
+ return result;
+ }
+
//涓嶈繛缁湴鍧�鍐欏叆Word
@@ -345,7 +388,7 @@
try {
return s7PLC.readTime(address);
} catch (Exception e) {
- e.printStackTrace();
+ System.out.println("璇诲彇 " + address + " 澶辫触锛�" + e.getMessage());
return null;
}
}
--
Gitblit v1.8.0