From a0adee2f689c85399ca311ef7691cd911a00fd3b Mon Sep 17 00:00:00 2001 From: 18516761980 <4761516tqsxp> Date: 星期四, 17 三月 2022 16:02:30 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/MelsecCrnThread.java | 84 ++++++++++++++++++++++++++++++++---------- 1 files changed, 64 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/zy/core/thread/MelsecCrnThread.java b/src/main/java/com/zy/core/thread/MelsecCrnThread.java index 1680a88..73e1d1b 100644 --- a/src/main/java/com/zy/core/thread/MelsecCrnThread.java +++ b/src/main/java/com/zy/core/thread/MelsecCrnThread.java @@ -229,29 +229,73 @@ log.error("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�"); return false; } - 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.getCommand(); - OperateResult result = melsecMcNet.Write("D0", array); - try { - Thread.sleep(200); + OperateResult result = null; + try{ + Integer exeCount=0; + do{ + 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.getCommand(); + result = melsecMcNet.Write("D0", array); + if(result.IsSuccess) { + if (command.getAckFinish() == 0) { + short commandFinish = 1; + result = melsecMcNet.Write("D9", commandFinish); + if(result.IsSuccess){ + //鍐欎换鍔$‘璁よ繑鍥炴垚鍔熷悗锛屾煡璇㈢‘璁や竴娆� + Thread.sleep(200); + OperateResultExOne<byte[]> result1 = melsecMcNet.Read("D9", (short)2); + if(result1.IsSuccess){ + short commandVal = melsecMcNet.getByteTransform().TransInt16(result1.Content,2); + if(commandVal==1){ + break; + } else { + exeCount++; + } + } else{ + exeCount++; + } + }else{ + exeCount++; + } + } + }else{ + exeCount++; + } + Thread.sleep(200); + }while(exeCount>3); }catch (Exception e){ + } - if (command.getAckFinish() == 0) { - short commandFinish = 1; - result = melsecMcNet.Write("D9", commandFinish); - } +// 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.getCommand(); +// OperateResult result = melsecMcNet.Write("D0", array); +// +// if (command.getAckFinish() == 0) { +// short commandFinish = 1; +// result = melsecMcNet.Write("D9", commandFinish); +// } try { // 鏃ュ織璁板綍 @@ -276,7 +320,7 @@ bean.insert(basCrnOpt); } catch (Exception ignore) {} - if (result.IsSuccess) { + if (result != null && result.IsSuccess) { 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 true; -- Gitblit v1.9.1