From a87d3006efd604c576a39bfaff2d21379143ada5 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@63.com> Date: 星期一, 14 三月 2022 16:02:22 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/SteThread.java | 38 +++++++++++++++++++++++++++----------- 1 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java index 7111554..9880419 100644 --- a/src/main/java/com/zy/core/thread/SteThread.java +++ b/src/main/java/com/zy/core/thread/SteThread.java @@ -219,15 +219,15 @@ return false; } command.setSteNo(slave.getId()); - OperateResult result; + OperateResult result = null; // 寮�濮嬩换鍔� if (!command.getWaiting()) { OperateResult result0 = siemensS7Net.Write("D0", command.getTaskNo()); short[] array = new short[10]; array[0] = command.getTaskMode(); -// array[1] = command.getTaskNo(); -// array[2] = command.getTaskMode(); -// array[3] = command.getSourcePosX(); +// array[1] = command.getTaskNo(); +// array[2] = command.getTaskMode(); +// array[3] = command.getSourcePosX(); // array[4] = command.getSourcePosY(); // array[5] = command.getSourcePosZ(); // array[6] = command.getDestinationPosX(); @@ -236,7 +236,9 @@ // array[9] = command.getCommand(); OperateResult result1 = siemensS7Net.Write("D0", array); // 纭寮�濮嬩换鍔� - result = siemensS7Net.Write("D0", true); + if (result0.IsSuccess) { + result = siemensS7Net.Write("D0", true); + } // 浠诲姟瀹屾垚 } else { result = siemensS7Net.Write("D0", true); @@ -265,9 +267,14 @@ // bean.insert(basSteOpt); } catch (Exception ignore) {} - if (result.IsSuccess) { + if (result != null && result.IsSuccess) { // 缁存姢鏁版嵁搴撴帓鍒楀眰 -// this.modifyPos(); + if (!steProtocol.getWaiting()) { + this.lastRow = command.getRow().intValue(); + this.lastBay = command.getBay().intValue(); + this.lastLev = command.getLev().intValue(); + } + log.info("绌挎杞﹀懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); @@ -292,10 +299,19 @@ BasSteService service = SpringUtils.getBean(BasSteService.class); BasSte basSte = service.selectById(slave.getId()); if (basSte != null) { - if (service.updatePos(this.lastRow, this.lastBay, this.lastLev) > 0) { - return true; - } else { - log.error("{}鍙风┛姊溅淇敼鏁版嵁搴撳畾浣嶅け璐ワ紒锛侊紒", slave.getId()); + // 鏇存柊plc鏁版嵁鍧� + short[] arr = new short[] {this.lastRow.shortValue(), this.lastBay.shortValue(), this.lastLev.shortValue()}; + OperateResult result = siemensS7Net.Write("D0", arr); + if (result.IsSuccess) { + // 鏇存柊鏁版嵁搴� + if (service.updatePos(this.lastRow, this.lastBay, this.lastLev) > 0) { + this.lastRow = null; + this.lastBay = null; + this.lastLev = null; + return true; + } else { + log.error("{}鍙风┛姊溅淇敼鏁版嵁搴撳畾浣嶅け璐ワ紒锛侊紒", slave.getId()); + } } } -- Gitblit v1.9.1