From e2a14112a81740481623dc16bbd1301432ce34b0 Mon Sep 17 00:00:00 2001 From: L <L@132> Date: 星期三, 27 八月 2025 13:15:22 +0800 Subject: [PATCH] * --- src/main/java/com/zy/core/thread/SiemensCrnThread.java | 121 ++++++++++++++++++++++++++++++++-------- 1 files changed, 97 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java index 3b40137..603aa3b 100644 --- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java +++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java @@ -105,7 +105,7 @@ default: break; } - Thread.sleep(500); + Thread.sleep(200); } catch (Exception e) { // e.printStackTrace(); } @@ -138,6 +138,12 @@ crnProtocol.setyDistance((short) 0); crnProtocol.setxDuration((short) 0); crnProtocol.setyDuration((short) 0); + try{ + CrnErrCache.updateCrnErr(crnProtocol.getCrnNo(), "绂荤嚎"); + } catch (Exception e1){ + + } + } @Override @@ -204,10 +210,18 @@ if(crnProtocol.getTaskNo()==9999){ backHpFlag = false; } - CrnCommand crnCommand = new CrnCommand(); - crnCommand.setAckFinish((short)1); - if (write(crnCommand)) { - resetFlag = false; + + if (!Cools.isEmpty(crnProtocol.getLaneNo()) && crnProtocol.getLaneNo()!=0){ + CrnCommand crnCommand = new CrnCommand(); + crnCommand.setAckFinish((short)1); +// crnCommand.setTaskNo(crnProtocol.getTaskNo()); + crnCommand.setLaneNo(crnProtocol.getLaneNo()); + crnCommand.setTaskMode(CrnTaskModeType.NONE); // 浠诲姟妯″紡 + if (write(crnCommand)) { + resetFlag = false; + } + } else { + CrnErrCache.updateCrnErr(crnProtocol.getCrnNo(), "宸烽亾鍙蜂负0"); } } } @@ -268,21 +282,20 @@ log.error("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�"); return false; } - CrnErrCache.updateCrnErr(slave.getId(), "-"); try{ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); - deviceErrorService.addDeviceError("crnWrite", slave.getId(), "宸烽亾鍙�"+command.getLaneNo()+";鍫嗗灈鏈烘寚浠や笅鍙�:"+JSON.toJSONString(command.getNowTask())); - } catch (Exception e2){ + deviceErrorService.addDeviceError("crnWriteIng", slave.getId(), "宸烽亾鍙�"+command.getLaneNo()+";鍫嗗灈鏈哄緟涓嬪彂鎸囦护:"+JSON.toJSONString(command.getNowTask())); + } catch (Exception e){ + log.error("crnWriteIng鏂板寮傚父"); } + try{ - BasErrLogService basErrLogService = SpringUtils.getBean(BasErrLogService.class); - BasErrLog basErrLog = new BasErrLog(command,"","闈炲紓甯革紝浠诲姟涓嬪彂璁板綍"); - if (!basErrLogService.insert(basErrLog)) { - log.error("鍫嗗灈鏈簆lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", slave.getId(), "浠诲姟涓嬪彂璁板綍澶辫触"); - } - } catch (Exception e3){ + CrnErrCache.updateCrnErr(slave.getId(), "-"); + } catch (Exception e){ + log.error(JSON.toJSONString(e)); + log.error("鍫嗗灈鏈轰换鍔″啓寮傚父锛氬紓甯稿畾浣嶅�硷細crnWrite-294琛�"); } -// convertRow(command); + command.setCrnNo(slave.getId()); short[] array = new short[10]; array[0] = command.getAckFinish(); @@ -294,34 +307,61 @@ array[6] = command.getDestinationPosX(); array[7] = command.getDestinationPosY(); array[8] = command.getDestinationPosZ(); - array[9] = command.getCommand(); +// array[9] = command.getCommand(); + array[9] = (short)0; + + + log.info("鍫嗗灈鏈轰换鍔″啓100.18锛氬�硷細0 crnWrite-313琛�"); OperateResult result18 = siemensNet.Write("DB100.18", (short)0); + + if (command.getAckFinish() == 0) { + log.info("鍫嗗灈鏈轰换鍔″啓100.0锛氬�硷細0 crnWrite-317琛�"); + OperateResult result100 = siemensNet.Write("DB100.0", (short)0); + } + try{ Thread.sleep(50L); - } catch (Exception e){} + } catch (Exception e){log.error("寤舵椂寮傚父324琛�");} + log.info("鍫嗗灈鏈轰换鍔″啓100.0锛氬�硷細array crnWrite-317琛�;array:"+JSON.toJSONString(array)); OperateResult result = siemensNet.Write("DB100.0", array); int i=0; do{ + i++; //鍫嗗灈鏈轰换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔� try{ - Thread.sleep(100L); - } catch (Exception e){} - OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB101.0", (short) 4); + Thread.sleep(50L); + } catch (Exception e){log.error("寤舵椂寮傚父335琛�");} + + log.info("鍫嗗灈鏈轰换鍔¤100.0锛氬�硷細20 crnWrite-317琛�;"); + 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++; CrnErrCache.updateCrnErr(slave.getId(), "鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲け璐�"); log.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲け璐id:{}]>>>>閲嶅啓[{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), i,JSON.toJSON(command),JSON.toJSON(one)); try{ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); - deviceErrorService.addDeviceError("crnErr", slave.getId(), "宸烽亾鍙�"+command.getLaneNo()+";鍐欏叆娆℃暟"+i+";鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲け璐�:"+JSON.toJSONString(command.getNowTask())); + deviceErrorService.addDeviceError("CrnErr", slave.getId(), "宸烽亾鍙�"+command.getLaneNo()+";鍐欏叆娆℃暟"+i+";鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲け璐�:"+JSON.toJSONString(command.getNowTask())); } catch (Exception e2){ } try{ @@ -334,7 +374,22 @@ } result = siemensNet.Write("DB100.0", array); }else{ + try{ + DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); + deviceErrorService.addDeviceError("crnWrite", slave.getId(), "宸烽亾鍙�"+command.getLaneNo()+";鍫嗗灈鏈烘寚浠や笅鍙�:"+JSON.toJSONString(command.getNowTask())); + } catch (Exception e2){ + } break; + } + } else { + CrnErrCache.updateCrnErr(slave.getId(), "鍫嗗灈鏈哄懡浠よ鍙栧け璐�"); + + log.error("鍫嗗灈鏈哄懡浠よ鍙栧け璐id:{}]>>>>閲嶅啓[{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), i,JSON.toJSON(command),""); + + try{ + DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); + deviceErrorService.addDeviceError("CrnErr", slave.getId(), "宸烽亾鍙�"+command.getLaneNo()+";鍐欏叆娆℃暟"+i+";鍫嗗灈鏈哄懡浠よ鍙栧け璐�:"+JSON.toJSONString(command.getNowTask())); + } catch (Exception e2){ } } }while(i<5); @@ -347,6 +402,7 @@ result = siemensNet.Write("DB100.18", commandFinish); int signFinish = 1; while (signFinish<5){ + signFinish++; OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.18", (short) 2); short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0); if (transInt16 != commandFinish){ @@ -355,7 +411,7 @@ CrnErrCache.updateCrnErr(slave.getId(), "涓嬪彂DB100.18 鍥炶澶辫触"); try{ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); - deviceErrorService.addDeviceError("crnErr", slave.getId(), "宸烽亾鍙�"+command.getLaneNo()+";鍐欏叆娆℃暟"+signFinish+";涓嬪彂DB100.18 鍥炶澶辫触:"+JSON.toJSONString(command.getNowTask())); + deviceErrorService.addDeviceError("CrnErr", slave.getId(), "宸烽亾鍙�"+command.getLaneNo()+";鍐欏叆娆℃暟"+signFinish+";涓嬪彂DB100.18 鍥炶澶辫触:"+JSON.toJSONString(command.getNowTask())); } catch (Exception e2){ } try{ @@ -367,7 +423,6 @@ } catch (Exception e3){ } result = siemensNet.Write("DB100.18", commandFinish); - signFinish++; }else { log.info("涓嬪彂DB100.18" + "commandFinish:"+commandFinish); log.info("涓嬪彂DB100.18" + "array:"+ JSON.toJSONString(array)); @@ -548,4 +603,22 @@ public void setWrkSign() { } + + /** + * 娓呴櫎浣滀笟鍚姩涓� + */ + @Override + public void setResetFlag(boolean flag) { + this.resetFlag = flag; + } + + + /** + * 娓呴櫎浣滀笟鍚姩涓� + */ + @Override + public boolean getResetFlag() { + return resetFlag; + } + } -- Gitblit v1.9.1