| | |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.BasCrnOpt; |
| | |
| | | private CrnSlave slave; |
| | | private CrnProtocol crnProtocol; |
| | | private boolean resetFlag = false; |
| | | private boolean resetFlagTwo = false; |
| | | |
| | | public Long sign = System.currentTimeMillis(); |
| | | |
| | | public boolean isRunning = true; |
| | | |
| | | /** |
| | | * 堆垛机是否在回原点运动中标记 |
| | |
| | | @SuppressWarnings("InfiniteLoopStatement") |
| | | public void run() { |
| | | this.connect(); |
| | | while (true) { |
| | | while (isRunning) { |
| | | try { |
| | | int step = 1; |
| | | Task task = MessageQueue.poll(SlaveType.Crn, slave.getId()); |
| | |
| | | command.setDestinationPosZ((short)0); // 目标库位层 |
| | | write(command); |
| | | break; |
| | | // 写入数据 |
| | | case 5: |
| | | write5((CrnCommand) task.getData()); |
| | | break; |
| | | // 复位 |
| | | case 6: |
| | | CrnCommand command2 = (CrnCommand) task.getData(); |
| | | if (null == command2) { |
| | | command2 = new CrnCommand(); |
| | | } |
| | | command2.setCrnNo(slave.getId()); // 堆垛机编号 |
| | | command2.setTaskNo((short) 0); // 工作号 |
| | | command2.setAckFinish((short) 1); // 任务完成确认位 |
| | | command2.setTaskMode(CrnTaskModeType.NONE); // 任务模式 |
| | | command2.setSourcePosX((short)0); // 源库位排 |
| | | command2.setSourcePosY((short)0); // 源库位列 |
| | | command2.setSourcePosZ((short)0); // 源库位层 |
| | | command2.setDestinationPosX((short)0); // 目标库位排 |
| | | command2.setDestinationPosY((short)0); // 目标库位列 |
| | | command2.setDestinationPosZ((short)0); // 目标库位层 |
| | | write5(command2); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | |
| | | } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | } |
| | | |
| | | // System.out.println("第"+slave.getId()+"个堆垛机线程运行一轮:"+(System.currentTimeMillis()-sign)); |
| | | sign = System.currentTimeMillis(); |
| | | } |
| | | } |
| | | |
| | |
| | | crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48)); |
| | | crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 52)); |
| | | |
| | | |
| | | //工位2数据 无则无需例会 |
| | | crnProtocol.setTaskNoTwo(siemensNet.getByteTransform().TransInt16(result.Content, 56)); |
| | | crnProtocol.setStatusTwo(siemensNet.getByteTransform().TransInt16(result.Content, 56)); |
| | | crnProtocol.setForkPosTwo(siemensNet.getByteTransform().TransInt16(result.Content, 58)); |
| | | crnProtocol.setLiftPosTwo(siemensNet.getByteTransform().TransInt16(result.Content, 60)); |
| | | crnProtocol.setLoadedTwo(siemensNet.getByteTransform().TransInt16(result.Content, 64)); |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 复位信号 |
| | | if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) { |
| | | if (!Cools.isEmpty(crnProtocol.getStatusType()) && crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) { |
| | | log.error("-------------------------------------------第一步、[堆垛机号:{}, 工作号:{}, 载货台:{}]==>> 状态为10,等待确认!!", |
| | | slave.getId(),crnProtocol.getTaskNo(), crnProtocol.getLoaded()==1 ? "有物" : "无物"); |
| | | if (resetFlag) { |
| | | if(crnProtocol.getTaskNo()==9999){ |
| | | backHpFlag = false; |
| | |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setAckFinish((short)1); |
| | | if (write(crnCommand)) { |
| | | resetFlag = false; |
| | | } |
| | | } |
| | | if (resetFlagTwo) { |
| | | if(crnProtocol.getTaskNo()==9999){ |
| | | backHpFlag = false; |
| | | } |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setAckFinish((short)1); |
| | | if (write5(crnCommand)) { |
| | | resetFlag = false; |
| | | } |
| | | } |
| | |
| | | short commandFinish = 1; |
| | | Thread.sleep(100L); |
| | | result = siemensNet.Write("DB100.18", 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 != null && result.IsSuccess) { |
| | | Thread.sleep(200); |
| | | this.readStatus(); |
| | | 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("写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 写入数据 工位2 |
| | | */ |
| | | private boolean write5(CrnCommand command) throws InterruptedException { |
| | | if (null == command) { |
| | | log.error("堆垛机写入命令为空"); |
| | | return false; |
| | | } |
| | | // convertRow(command); |
| | | command.setCrnNo(slave.getId()); |
| | | short[] array = new short[9]; |
| | | // array[0] = command.getAckFinish(); |
| | | array[0] = command.getTaskNo(); |
| | | array[1] = command.getTaskMode(); |
| | | array[2] = command.getSourcePosX(); |
| | | array[3] = command.getSourcePosY(); |
| | | array[4] = command.getSourcePosZ(); |
| | | array[5] = command.getDestinationPosX(); |
| | | array[6] = command.getDestinationPosY(); |
| | | array[7] = command.getDestinationPosZ(); |
| | | // array[9] = command.getSourceStaNo(); |
| | | // array[10] = command.getDestinationStaNo(); |
| | | array[9] = command.getCommand(); |
| | | OperateResult result = siemensNet.Write("DB100.0", command.getAckFinish()); |
| | | OperateResult result2 = siemensNet.Write("DB100.20", array); |
| | | |
| | | if (command.getAckFinish() == 0) { |
| | | short commandFinish = 1; |
| | | Thread.sleep(100L); |
| | | result = siemensNet.Write("DB100.38", commandFinish); |
| | | } |
| | | |
| | | try { |
| | |
| | | |
| | | } |
| | | |
| | | // 提供一个方法来停止线程 |
| | | public void requestStop() { |
| | | isRunning = false; |
| | | } |
| | | |
| | | } |