From 9fd40b787bdd4e0caaed213d1931d9c7fb8f846c Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期三, 30 十二月 2020 09:46:33 +0800 Subject: [PATCH] ## --- src/main/java/com/zy/core/thread/MelsecCrnThread.java | 78 ++++++++++++++++++++++++++++++++++---- 1 files changed, 69 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/zy/core/thread/MelsecCrnThread.java b/src/main/java/com/zy/core/thread/MelsecCrnThread.java index f7544ad..ff55e83 100644 --- a/src/main/java/com/zy/core/thread/MelsecCrnThread.java +++ b/src/main/java/com/zy/core/thread/MelsecCrnThread.java @@ -7,7 +7,9 @@ import com.core.common.Arith; import com.core.common.DateUtils; import com.core.common.SpringUtils; +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.CrnThread; import com.zy.core.cache.MessageQueue; @@ -23,6 +25,7 @@ import lombok.extern.slf4j.Slf4j; import java.text.MessageFormat; +import java.util.Calendar; import java.util.Date; /** @@ -106,13 +109,45 @@ OperateResult connect = melsecMcNet.ConnectServer(); if(connect.IsSuccess){ result = true; - 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.info("鍫嗗灈鏈簆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.info("鍫嗗灈鏈簆lc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort()); } 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("鍫嗗灈鏈簆lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort()); } + // 鍛戒护涓嬪彂鍖� -------------------------------------------------------------------------- + /** + * array[1] = command.getSourcePosY(); // 鍒� + * array[2] = command.getSourcePosZ(); // 灞� + * array[3] = command.getSourcePosX(); // 鎺� + * array[4] = command.getDestinationPosY(); // 鍒� + * array[5] = command.getDestinationPosZ(); // 灞� + * array[6] = command.getDestinationPosX(); // 鎺� + * array[7] = command.getTaskNo(); + */ + Date date = new Date(); + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + CrnCommand crnCommand = new CrnCommand(); + crnCommand.setCrnNo(slave.getId()); // 鍫嗗灈鏈虹紪鍙� + crnCommand.setTaskMode(CrnTaskModeType.TIMING); // 浠诲姟妯″紡: 璁剧疆鏃堕棿 + crnCommand.setSourcePosY((short) cal.get(Calendar.YEAR)); // 骞达細1980锝�2079 + crnCommand.setSourcePosZ((short) (cal.get(Calendar.MONTH)+1)); // 鏈堬細1锝�12 + crnCommand.setSourcePosX((short) cal.get(Calendar.DATE)); // 鏃ワ細1锝�31 + crnCommand.setDestinationPosY((short) cal.get(Calendar.HOUR_OF_DAY)); // 鏃讹細0锝�23 + crnCommand.setDestinationPosZ((short) cal.get(Calendar.MINUTE)); // 鍒嗭細0锝�59 + crnCommand.setDestinationPosX((short) cal.get(Calendar.SECOND)); // 绉掞細0锝�59 + crnCommand.setTaskNo((short) (cal.get(Calendar.DAY_OF_WEEK) - 1)); // 鏄熸湡锛�0(鏃�)锝�6(鍏�) + crnCommand.setTaskSend((short) 1); + crnCommand.setAckFinish((short) 0); + if (write(crnCommand)) { + log.info("鍫嗗灈鏈簆lc鏍″鏃堕棿鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort()); + } + melsecMcNet.ConnectClose(); + try { + Thread.sleep(1000); + } catch (InterruptedException ignore) {} return result; } @@ -166,13 +201,14 @@ BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class); BasCrnp basCrnp = new BasCrnp(); basCrnp.setCrnNo(slave.getId()); + crnProtocol.setAlarm1((short) (crnProtocol.getAlarm1() + 1000)); if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){ - log.error("鍫嗗灈鏈簆lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); + log.error("鍫嗗灈鏈簆lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); } } 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("璇诲彇鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); } } @@ -206,10 +242,34 @@ 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))); + + 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) {} + 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("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); return false; } } -- Gitblit v1.9.1