From 66942458f7753fe4ddee7c5ed3386d61cff28b24 Mon Sep 17 00:00:00 2001 From: 野心家 <1051256694@qq.com> Date: 星期二, 01 四月 2025 13:55:21 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/jxjdzwcs' into jxjdzwcs --- src/main/java/com/zy/core/thread/SiemensCrnThread.java | 259 +++++++++++++++++++++++++-------------------------- 1 files changed, 125 insertions(+), 134 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java index 3bd2c0a..37ca98b 100644 --- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java +++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java @@ -83,7 +83,7 @@ break; // 鍐欏叆鏁版嵁 case 2: - write2((CrnCommand) task.getData()); + write5((CrnCommand) task.getData()); break; // 澶嶄綅 case 3: @@ -336,98 +336,150 @@ // crnCommand.setDestinationStaNo(command.getDestinationStaNo()); crnCommand.setCommand(command.getCommand()); if (command.getTaskNo() == 0 && command.getAckFinish() == 0 && command.getAuto() != 1) { - command.setTaskNo((short) 9999); + command.setTaskNo((short) 999); } command.setCrnNo(slave.getId()); short[] array = new short[10]; - if (Cools.isEmpty(command.getAckFinish())) { - array[0] = 5; - } else { - array[0] = command.getAckFinish(); - } + array[0] = command.getAckFinish(); array[1] = command.getTaskNo(); array[2] = command.getTaskMode(); - array[3] = command.getSourcePosZ(); - array[4] = command.getSourcePosX(); - array[5] = command.getSourcePosY(); - array[6] = command.getDestinationPosZ(); - array[7] = command.getDestinationPosX(); - array[8] = command.getDestinationPosY(); + array[3] = command.getSourcePosX(); + array[4] = command.getSourcePosY(); + array[5] = command.getSourcePosZ(); + array[6] = command.getDestinationPosX(); + array[7] = command.getDestinationPosY(); + array[8] = command.getDestinationPosZ(); array[9] = command.getCommand(); // 浣滀笟淇℃伅 OperateResult result = siemensNet.Write("DB100.0", array); - if (command.getAckFinish() != 1) { + + if (result.IsSuccess) { + log.warn("鍫嗗灈鏈哄懡浠や笅鍙慬id:{},鏃堕棿锛歿}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command)); + OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); + return true; + } else { + OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ爢鍨涙満plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); + log.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); + return false; + } + } + + /** + * 鍐欏叆鏁版嵁 + */ + private synchronized boolean write5(CrnCommand command) throws InterruptedException { + String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); + + if (null == command) { + log.error("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�"); + return false; + } +// convertRow(command); + command.setCrnNo(slave.getId()); + short[] array = new short[10]; + array[0] = command.getAckFinish(); + array[1] = command.getTaskNo(); + array[2] = command.getTaskMode(); + array[3] = command.getSourcePosX(); + array[4] = command.getSourcePosY(); + array[5] = command.getSourcePosZ(); + array[6] = command.getDestinationPosX(); + array[7] = command.getDestinationPosY(); + array[8] = command.getDestinationPosZ(); +// array[9] = command.getSourceStaNo(); +// array[10] = command.getDestinationStaNo(); + array[9] = command.getCommand(); + OperateResult result18 = siemensNet.Write("DB100.18", (short)0); + Thread.sleep(100L); + OperateResult result = siemensNet.Write("DB100.0", array); + + int i=0; + do{ + //鍫嗗灈鏈轰换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔� + Thread.sleep(100); + OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20); + if (resultRead.IsSuccess) { + CrnCommand one = new CrnCommand(); + one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); + one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); + one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); + one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); + one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); + one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); + one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); + one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); + if (!command.getTaskNo().equals(one.getTaskNo()) || !command.getTaskMode().equals(one.getTaskMode()) + || !command.getSourcePosX().equals(one.getSourcePosX()) || !command.getSourcePosY().equals(one.getSourcePosY()) + || !command.getSourcePosZ().equals(one.getSourcePosZ()) || !command.getDestinationPosX().equals(one.getDestinationPosX()) + || !command.getDestinationPosY().equals(one.getDestinationPosY()) || !command.getDestinationPosZ().equals(one.getDestinationPosZ()) + ){ + i++; + log.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲け璐id:{}]>>>>閲嶅啓[{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), i,JSON.toJSON(command),JSON.toJSON(one)); + result = siemensNet.Write("DB100.0", array); + }else{ + break; + } + } + }while(i<5); + + if (command.getAckFinish() == 0) { + short commandFinish = 1; + Thread.sleep(100L); + result = siemensNet.Write("DB100.18", commandFinish); + int signFinish = 1; + while (signFinish<5){ + OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.18", (short) 2); + short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0); + if (transInt16 != commandFinish){ + log.info("涓嬪彂DB100.18 鍥炶澶辫触" + "commandFinish:"+commandFinish); + log.info("涓嬪彂DB100.18 鍥炶澶辫触" + "array:"+ JSON.toJSONString(array)); + result = siemensNet.Write("DB100.18", commandFinish); + signFinish++; + }else { + log.info("涓嬪彂DB100.18" + "commandFinish:"+commandFinish); + log.info("涓嬪彂DB100.18" + "array:"+ JSON.toJSONString(array)); + break; + } + } + } + + try { + // 鏃ュ織璁板綍 BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class); BasCrnOpt basCrnOpt = new BasCrnOpt( command.getTaskNo().intValue(), // 浠诲姟鍙� command.getCrnNo(), // 鍫嗗灈鏈篬闈炵┖] new Date(), // 涓嬪彂鏃堕棿 - command.getTaskModeType() == null ? null : command.getTaskModeType().toString(), // 妯″紡 - command.getSourcePosZ().intValue(), // 婧愭帓 - command.getSourcePosX().intValue(), // 婧愬垪 - command.getSourcePosY().intValue(), // 婧愬眰 + command.getTaskModeType().toString(), // 妯″紡 + command.getSourcePosX().intValue(), // 婧愭帓 + command.getSourcePosY().intValue(), // 婧愬垪 + command.getSourcePosZ().intValue(), // 婧愬眰 null, // 婧愮珯 - command.getDestinationPosZ().intValue(), // 鐩爣鎺� - command.getDestinationPosX().intValue(), // 鐩爣鍒� - command.getDestinationPosY().intValue(), // 鐩爣灞� + command.getDestinationPosX().intValue(), // 鐩爣鎺� + command.getDestinationPosY().intValue(), // 鐩爣鍒� + command.getDestinationPosZ().intValue(), // 鐩爣灞� null, // 鐩爣绔� null, // 鍝嶅簲缁撴灉 null, // 淇敼鏃堕棿 null // 淇敼浜哄憳 ); bean.insert(basCrnOpt); - } + } catch (Exception ignore) {} - if (result.IsSuccess) { -// log.warn("鍫嗗灈鏈哄懡浠や笅鍙慬id:{},鏃堕棿锛歿}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command)); -// OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); -// return true; + if (result != null && result.IsSuccess) { + Thread.sleep(300); + this.readStatus(); + log.info(methodName + ":鍫嗗灈鏈哄懡浠や笅鍙慬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 true; } else { - OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ爢鍨涙満plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); - log.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); + 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(methodName + ":鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); return false; } - - - try{ - //鍫嗗灈鏈轰换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔� - Thread.sleep(500); - OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 24); - if (resultRead.IsSuccess) { - CrnCommand one = new CrnCommand(); - one.setAckFinish(siemensNet.getByteTransform().TransInt16(resultRead.Content, 0)); - one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); - //one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); - one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); - one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); - one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); - one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); - one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); - one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); -// one.setSourceStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 18)); -// one.setDestinationStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 20)); - if (!crnCommand.getTaskNo().equals(one.getTaskNo()) && !crnCommand.getAckFinish().equals(one.getAckFinish()) - && !crnCommand.getSourcePosZ().equals(one.getSourcePosZ()) && !crnCommand.getSourcePosX().equals(one.getSourcePosX()) && !crnCommand.getSourcePosY().equals(one.getSourcePosY()) - && !crnCommand.getDestinationPosZ().equals(one.getDestinationPosZ()) && !crnCommand.getDestinationPosX().equals(one.getDestinationPosX()) && !crnCommand.getDestinationPosY().equals(one.getDestinationPosY()) - ){ - log.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲け璐id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); - log.error("鍫嗗灈鏈哄懡浠ゅ洖璇诲け璐ュ悗锛岄噸鏂版坊鍔犱换鍔″埌闃熷垪 ===>> [id:{}],{}", slave.getId(), JSON.toJSON(crnCommand)); - MessageQueue.offer(SlaveType.Crn, slave.getId(), new Task(5, crnCommand)); - Thread.sleep(100); - readStatus(); - return false; - } else { - log.info("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇绘垚鍔焄id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); - OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); - } - } - }catch (Exception e){ - log.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲嚭閿�"); - } - return true; } /** @@ -454,7 +506,7 @@ // crnCommand.setDestinationStaNo(command.getDestinationStaNo()); crnCommand.setCommand(command.getCommand()); if (command.getTaskNo() == 0 && command.getAckFinish() == 0 && command.getAuto() != 1) { - command.setTaskNo((short) 9999); + command.setTaskNo((short) 999); } command.setCrnNo(slave.getId()); @@ -466,17 +518,16 @@ } array[1] = command.getTaskNo(); array[2] = command.getTaskMode(); - array[3] = command.getSourcePosZ(); - array[4] = command.getSourcePosX(); - array[5] = command.getSourcePosY(); - array[6] = command.getDestinationPosZ(); - array[7] = command.getDestinationPosX(); - array[8] = command.getDestinationPosY(); + array[3] = command.getSourcePosX(); + array[4] = command.getSourcePosY(); + array[5] = command.getSourcePosZ(); + array[6] = command.getDestinationPosX(); + array[7] = command.getDestinationPosY(); + array[8] = command.getDestinationPosZ(); array[9] = command.getCommand(); // 浣滀笟淇℃伅 OperateResult result = siemensNet.Write("DB100.0", array); // 鏃ュ織璁板綍 -// try { if (command.getAckFinish() != 1) { BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class); BasCrnOpt basCrnOpt = new BasCrnOpt( @@ -511,27 +562,7 @@ } CommandInfoLog commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class); commandInfoLog.setId(null); -// CommandInfoLog commandInfoLog = new CommandInfoLog(); -// if (commandInfo != null) { -// commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class); -// commandInfoLog.setId(null); -// }else { -// Date now = new Date(); -// commandInfoLog.setCommand(JSON.toJSONString(command)); -// commandInfoLog.setCommandStatus(3); -// commandInfoLog.setStartTime(now); -// commandInfoLog.setExecuteTime(now); -// commandInfoLog.setCompleteTime(now); -// commandInfoLog.setDevice(SlaveType.Devp.toString()); -// commandInfoLog.setWrkNo(9999); -// commandInfoLog.setTaskNo("9999"); -// commandInfoLog.setCommandDesc("鎵嬪姩鍛戒护"); -// } - - if (result.IsSuccess) { -// log.warn("鍫嗗灈鏈哄懡浠や笅鍙慬id:{},鏃堕棿锛歿}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command)); - Date now = new Date(); //鏇存柊鎸囦护鏃ュ織 commandInfoLog.setDeviceLog("鎸囦护涓嬪彂鎴愬姛"); @@ -557,46 +588,6 @@ } else { OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ爢鍨涙満plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); log.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); - - //鏇存柊鎸囦护鏃ュ織 - commandInfoLog.setDeviceLog("鎸囦护涓嬪彂澶辫触"); - commandInfoLogService.insert(commandInfoLog); - return false; - } - try{ - //鍫嗗灈鏈轰换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔� - Thread.sleep(500); - OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 24); - if (resultRead.IsSuccess) { - CrnCommand one = new CrnCommand(); - one.setAckFinish(siemensNet.getByteTransform().TransInt16(resultRead.Content, 0)); - one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); - //one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); - one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); - one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8)); - one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10)); - one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); - one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); - one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); -// one.setSourceStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 18)); -// one.setDestinationStaNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 20)); - if (!crnCommand.getTaskNo().equals(one.getTaskNo()) && !crnCommand.getAckFinish().equals(one.getAckFinish()) - && !crnCommand.getSourcePosZ().equals(one.getSourcePosZ()) && !crnCommand.getSourcePosX().equals(one.getSourcePosX()) && !crnCommand.getSourcePosY().equals(one.getSourcePosY()) - && !crnCommand.getDestinationPosZ().equals(one.getDestinationPosZ()) && !crnCommand.getDestinationPosX().equals(one.getDestinationPosX()) && !crnCommand.getDestinationPosY().equals(one.getDestinationPosY()) - ){ - log.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲け璐id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); - log.error("鍫嗗灈鏈哄懡浠ゅ洖璇诲け璐ュ悗锛岄噸鏂版坊鍔犱换鍔″埌闃熷垪 ===>> [id:{}],{}", slave.getId(), JSON.toJSON(crnCommand)); - MessageQueue.offer(SlaveType.Crn, slave.getId(), new Task(5, crnCommand)); - Thread.sleep(100); - readStatus(); - return false; - } else { - log.info("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇绘垚鍔焄id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); - OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); - } - } - }catch (Exception e){ - log.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲嚭閿�"); } return true; } -- Gitblit v1.9.1