| | |
| | | crnProtocol = new CrnProtocol(); |
| | | crnProtocol.setCrnNo(this.getSlave().getId()); |
| | | } |
| | | crnProtocol.setCrnNo(this.getSlave().getId()); |
| | | crnProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0)); |
| | | crnProtocol.setTaskNo(siemensNet.getByteTransform().TransInt16(result.Content, 2)); |
| | | crnProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 4)); |
| | |
| | | crnProtocol.setYDistance(siemensNet.getByteTransform().TransSingle(result.Content, 44)); |
| | | crnProtocol.setXDuration(siemensNet.getByteTransform().TransSingle(result.Content, 48)); |
| | | crnProtocol.setYDuration(siemensNet.getByteTransform().TransSingle(result.Content, 52)); |
| | | crnProtocol.setStatusEnd(false); |
| | | |
| | | try{ |
| | | 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 (this.slave.getId() == 1){ |
| | | if (one.getDestinationPosX() == 3 && one.getDestinationPosY() == 2 && one.getDestinationPosZ() == 1){ |
| | | crnProtocol.setStatusEnd(true); |
| | | } |
| | | } else if (this.slave.getId() == 3){ |
| | | if (one.getDestinationPosX() == 19 && one.getDestinationPosY() == 6 && one.getDestinationPosZ() == 1){ |
| | | crnProtocol.setStatusEnd(true); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e){ } |
| | | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 复位信号 |
| | | if (!Cools.isEmpty(crnProtocol.getStatusType()) && crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) { |
| | | News.error("---第一步、[堆垛机号:{}, 工作号:{}, 载货台信号:{}]==>> 状态为10,等待确认!!", |
| | | slave.getId(),crnProtocol.getTaskNo(), crnProtocol.getLoaded()==1 ? "有物" : "无物"); |
| | | if (resetFlag) { |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setAckFinish((short)1); |
| | |
| | | return false; |
| | | } |
| | | |
| | | //下发前克隆一份 |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setCrnNo(command.getCrnNo()); |
| | | crnCommand.setAckFinish(command.getAckFinish()); |
| | | crnCommand.setTaskNo(command.getTaskNo()); |
| | | crnCommand.setTaskMode(command.getTaskMode()); |
| | | crnCommand.setSourcePosX(command.getSourcePosX()); |
| | | crnCommand.setSourcePosY(command.getSourcePosY()); |
| | | crnCommand.setSourcePosZ(command.getSourcePosZ()); |
| | | crnCommand.setDestinationPosX(command.getDestinationPosX()); |
| | | crnCommand.setDestinationPosY(command.getDestinationPosY()); |
| | | crnCommand.setDestinationPosZ(command.getDestinationPosZ()); |
| | | crnCommand.setSourceStaNo(command.getSourceStaNo()); |
| | | crnCommand.setDestinationStaNo(command.getDestinationStaNo()); |
| | | crnCommand.setCommand(command.getCommand()); |
| | | |
| | | // convertRow(command); |
| | | command.setCrnNo(slave.getId()); |
| | | short[] array = new short[10]; |
| | |
| | | array[9] = command.getCommand(); |
| | | OperateResult result = siemensNet.Write("DB100.0", array); |
| | | |
| | | if(!result.IsSuccess){ |
| | | log.error("写入堆垛机plc数据失败,重新添加任务到队列 ===>> [id:{}],{}", slave.getId(), JSON.toJSON(crnCommand)); |
| | | MessageQueue.offer(SlaveType.Crn, slave.getId(), new Task(2, crnCommand)); |
| | | Thread.sleep(100); |
| | | readStatus(); |
| | | return false; |
| | | } |
| | | |
| | | //堆垛机任务写入后,回读一次,看是否成功 |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20); |
| | |
| | | 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()!=one.getTaskNo() || command.getTaskMode()!=one.getTaskMode() |
| | | if (!command.getTaskNo().equals(one.getTaskNo()) || command.getTaskMode()!=one.getTaskMode() |
| | | || command.getSourcePosX()!=one.getSourcePosX() || command.getSourcePosY()!=one.getSourcePosY() |
| | | || command.getSourcePosZ()!=one.getSourcePosZ() || command.getDestinationPosX()!=one.getDestinationPosX() |
| | | || command.getDestinationPosY()!=one.getDestinationPosY() || command.getDestinationPosZ()!=one.getDestinationPosZ() |
| | | ){ |
| | | News.error("堆垛机命令地址写入后回读失败[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); |
| | | News.error("堆垛机命令回读失败后,重新添加任务到队列 ===>> [id:{}],{}", slave.getId(), JSON.toJSON(crnCommand)); |
| | | // MessageQueue.offer(SlaveType.Crn, slave.getId(), new Task(2, crnCommand)); |
| | | Thread.sleep(100); |
| | | readStatus(); |
| | | return false; |
| | | }else{ |
| | | News.info("堆垛机命令地址写入后回读成功[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); |
| | | } |
| | | } |
| | | |
| | |
| | | short commandFinish = 1; |
| | | Thread.sleep(300); |
| | | News.info("堆垛机命令地址写入成功,开始写确认位[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | Integer counts = 0; |
| | | while(true) { |
| | | result = siemensNet.Write("DB100.18", commandFinish); |
| | | if(result.IsSuccess){ |
| | | break; |
| | | } else { |
| | | counts++; |
| | | if(counts>5){ |
| | | break; |
| | | } |
| | | } |
| | | Thread.sleep(300); |
| | | } |
| | | } |
| | | } |
| | | |