From 733aaaac3ed6a41b78f74c0bcb4d5de7725d788c Mon Sep 17 00:00:00 2001 From: wu <731351411@qq.com> Date: 星期一, 15 一月 2024 16:32:02 +0800 Subject: [PATCH] 更新已有未完成任务提示 --- springboot-vue3/src/main/java/com/example/springboot/component/S7control.java | 32 +++++++++++++++++++++++++++----- 1 files changed, 27 insertions(+), 5 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 a73f176..e0a5353 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 @@ -37,13 +37,21 @@ } return instance; } - + /** * 鍏抽棴瑗块棬瀛恠7閫氳杩炴帴 */ public void CloseS7client() { if (s7PLC == null) s7PLC.close(); + s7PLC.checkConnected(); + } + + /** + * s7閫氳杩炴帴鐘舵�� + */ + public boolean CheckConnected() { + return s7PLC.checkConnected(); } /** @@ -215,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; + } + } /** @@ -331,11 +347,17 @@ } //璇诲彇鏃堕棿 - public Long readtime(String address) { - if (s7PLC==null) - return null; +public Long readtime(String address) { + if (s7PLC == null) + return null; + try { return s7PLC.readTime(address); + } catch (Exception e) { + System.out.println("璇诲彇 " + address + " 澶辫触锛�" + e.getMessage()); + return null; } +} + public void writetime(String address, long datas) { if (s7PLC == null) -- Gitblit v1.8.0