From 462e0f4475665ec5596965bfb2a91b19badba446 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@63.com> Date: 星期三, 09 三月 2022 14:40:45 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/SteThread.java | 137 ++++++++++++++++++++++----------------------- 1 files changed, 67 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java index b186098..6cca57c 100644 --- a/src/main/java/com/zy/core/thread/SteThread.java +++ b/src/main/java/com/zy/core/thread/SteThread.java @@ -4,19 +4,15 @@ import HslCommunication.Core.Types.OperateResultExOne; import HslCommunication.Profinet.Siemens.SiemensPLCS; import HslCommunication.Profinet.Siemens.SiemensS7Net; -import com.alibaba.fastjson.JSON; import com.core.common.DateUtils; import com.core.common.SpringUtils; import com.core.exception.CoolException; -import com.zy.asrs.entity.BasCrnOpt; import com.zy.asrs.entity.BasCrnp; -import com.zy.asrs.service.BasCrnOptService; import com.zy.asrs.service.BasCrnpService; import com.zy.core.ThreadHandler; import com.zy.core.cache.MessageQueue; import com.zy.core.cache.OutputQueue; import com.zy.core.enums.CrnStatusType; -import com.zy.core.enums.CrnTaskModeType; import com.zy.core.enums.SlaveType; import com.zy.core.model.SteSlave; import com.zy.core.model.Task; @@ -158,16 +154,16 @@ if (null == steProtocol) { steProtocol = new SteProtocol(); } - steProtocol.setMode(siemensS7Net.getByteTransform().TransInt16(result.Content, 0)); - steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 2)); - steProtocol.setStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 4)); - steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 6)); - steProtocol.setLevel(siemensS7Net.getByteTransform().TransInt16(result.Content, 8)); - steProtocol.setForkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 10)); - steProtocol.setLiftPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 12)); - steProtocol.setWalkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 14)); - steProtocol.setLoaded(siemensS7Net.getByteTransform().TransInt16(result.Content, 16)); - steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt16(result.Content, 18)); +// steProtocol.setMode(siemensS7Net.getByteTransform().TransInt16(result.Content, 0)); +// steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 2)); +// steProtocol.setStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 4)); +// steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 6)); +// steProtocol.setLevel(siemensS7Net.getByteTransform().TransInt16(result.Content, 8)); +// steProtocol.setForkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 10)); +// steProtocol.setLiftPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 12)); +// steProtocol.setWalkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 14)); +// steProtocol.setLoaded(siemensS7Net.getByteTransform().TransInt16(result.Content, 16)); +// steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt16(result.Content, 18)); OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId())); @@ -175,7 +171,7 @@ if (steProtocol.getStatusType().equals(CrnStatusType.WAITING)) { if (resetFlag) { SteCommand steCommand = new SteCommand(); - steCommand.setAckFinish((short)1); +// steCommand.setAckFinish((short)1); if (write(steCommand)) { resetFlag = false; } @@ -209,61 +205,62 @@ * 鍐欏叆鏁版嵁 */ private boolean write(SteCommand command){ - if (null == command) { - 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 = siemensS7Net.Write("D0", array); - - if (command.getAckFinish() == 0) { - short commandFinish = 1; - result = siemensS7Net.Write("D9", commandFinish); - } - - try { - // 鏃ュ織璁板綍 - BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class); - BasCrnOpt basCrnOpt = new BasCrnOpt( - command.getTaskNo().intValue(), // 浠诲姟鍙� - command.getCrnNo(), // 绌挎杞闈炵┖] - new Date(), // 涓嬪彂鏃堕棿 - command.getTaskModeType().toString(), // 妯″紡 - command.getSourcePosX().intValue(), // 婧愭帓 - command.getSourcePosY().intValue(), // 婧愬垪 - command.getSourcePosZ().intValue(), // 婧愬眰 - null, // 婧愮珯 - command.getDestinationPosX().intValue(), // 鐩爣鎺� - command.getDestinationPosY().intValue(), // 鐩爣鍒� - command.getDestinationPosZ().intValue(), // 鐩爣灞� - null, // 鐩爣绔� - null, // 鍝嶅簲缁撴灉 - null, // 淇敼鏃堕棿 - null // 淇敼浜哄憳 - ); - bean.insert(basCrnOpt); - } catch (Exception ignore) {} - - if (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; - } else { - 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 false; - } + return true; +// if (null == command) { +// 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 = siemensS7Net.Write("D0", array); +// +// if (command.getAckFinish() == 0) { +// short commandFinish = 1; +// result = siemensS7Net.Write("D9", commandFinish); +// } +// +// try { +// // 鏃ュ織璁板綍 +// BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class); +// BasCrnOpt basCrnOpt = new BasCrnOpt( +// command.getTaskNo().intValue(), // 浠诲姟鍙� +// command.getCrnNo(), // 绌挎杞闈炵┖] +// new Date(), // 涓嬪彂鏃堕棿 +// command.getTaskModeType().toString(), // 妯″紡 +// command.getSourcePosX().intValue(), // 婧愭帓 +// command.getSourcePosY().intValue(), // 婧愬垪 +// command.getSourcePosZ().intValue(), // 婧愬眰 +// null, // 婧愮珯 +// command.getDestinationPosX().intValue(), // 鐩爣鎺� +// command.getDestinationPosY().intValue(), // 鐩爣鍒� +// command.getDestinationPosZ().intValue(), // 鐩爣灞� +// null, // 鐩爣绔� +// null, // 鍝嶅簲缁撴灉 +// null, // 淇敼鏃堕棿 +// null // 淇敼浜哄憳 +// ); +// bean.insert(basCrnOpt); +// } catch (Exception ignore) {} +// +// if (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; +// } else { +// 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 false; +// } } @Override -- Gitblit v1.9.1