From e08b0e5516fb552c99362e474bb6959dab92d90a Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期三, 02 九月 2020 09:53:26 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/CrnThread.java | 51 ++++++++++++++++++++++++++------------------------- 1 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/zy/core/thread/CrnThread.java b/src/main/java/com/zy/core/thread/CrnThread.java index d9ef282..e054bfd 100644 --- a/src/main/java/com/zy/core/thread/CrnThread.java +++ b/src/main/java/com/zy/core/thread/CrnThread.java @@ -113,13 +113,13 @@ */ private void readStatus(){ try { - if (null == crnProtocol) { - crnProtocol = new CrnProtocol(); - } /* 鏂规硶1 */ OperateResultExOne<byte[]> result = melsecMcNet.Read("D2231", (short) 62); if (result.IsSuccess) { + if (null == crnProtocol) { + crnProtocol = new CrnProtocol(); + } crnProtocol.setMode(melsecMcNet.getByteTransform().TransInt16(result.Content, 0)); crnProtocol.setTaskNo(melsecMcNet.getByteTransform().TransInt16(result.Content, 4)); crnProtocol.setStatus(melsecMcNet.getByteTransform().TransInt16(result.Content, 6)); @@ -144,8 +144,28 @@ crnProtocol.setXDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 54)); crnProtocol.setYDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 58)); + OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId())); + + // 澶嶄綅淇″彿 + if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) { + if (resetFlag) { + if (melsecMcNet.Write("D2218", (short) 1).IsSuccess) { + resetFlag = false; + } + } + } + + // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴� + BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class); + BasCrnp basCrnp = new BasCrnp(); + basCrnp.setCrnNo(slave.getId()); + if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){ + log.error("鍫嗗灈鏈簆lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + } + } else { - throw new CoolException("鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐�"); + OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆憑1}鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐�",DateUtils.convert(new Date()), slave.getId())); + throw new CoolException(MessageFormat.format( "鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐� ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort())); } /* 鏂规硶2 */ // crnProtocol.setMode(melsecMcNet.ReadInt16("D2231").Content); @@ -175,26 +195,7 @@ e.printStackTrace(); OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戣鍙栧爢鍨涙満plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); log.error("璇诲彇鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); - return; } - - OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId())); - -// if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) { -// if (resetFlag) { -// if (melsecMcNet.Write("D2218", 1).IsSuccess) { -// resetFlag = false; -// } -// } -// } - - // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴� -// BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class); -// BasCrnp basCrnp = new BasCrnp(); -// basCrnp.setCrnNo(slave.getId()); -// if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){ -// log.error("鍫嗗灈鏈簆lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); -// } } @@ -237,7 +238,7 @@ if (!melsecMcNet.Write("D2218", command.getAckFinish()).IsSuccess) { break; } } - System.out.println(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); + 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))); return; @@ -270,7 +271,7 @@ public CrnProtocol getCrnProtocol(){ if (crnProtocol == null) { - readStatus(); + throw new CoolException(slave.getId() + "鍙峰爢鍨涙満杩炴帴澶辫触"); } return this.crnProtocol; } -- Gitblit v1.9.1