| | |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.BasCrnpOpt; |
| | | import com.zy.asrs.entity.BasDualCrnp; |
| | | import com.zy.asrs.entity.BasDualCrnpOpt; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.service.BasCrnpOptService; |
| | | import com.zy.asrs.service.BasDualCrnpOptService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.OutputQueue; |
| | |
| | | //工位1 |
| | | crnStatus.setTaskNo((int) siemensNet.getByteTransform().TransInt16(result.Content, 2)); |
| | | crnStatus.setStatus((int) siemensNet.getByteTransform().TransInt16(result.Content, 4)); |
| | | crnStatus.setBay((int) siemensNet.getByteTransform().TransInt16(result.Content, 6)); |
| | | crnStatus.setLevel((int) siemensNet.getByteTransform().TransInt16(result.Content, 8)); |
| | | crnStatus.setForkPos((int) siemensNet.getByteTransform().TransInt16(result.Content, 10)); |
| | | crnStatus.setLoaded((int) siemensNet.getByteTransform().TransInt16(result.Content, 12)); |
| | | crnStatus.setWalkPos((int) siemensNet.getByteTransform().TransInt16(result.Content, 26)); |
| | | crnStatus.setForkPos((int) siemensNet.getByteTransform().TransInt16(result.Content, 6)); |
| | | crnStatus.setLoaded((int) siemensNet.getByteTransform().TransInt16(result.Content, 8)); |
| | | crnStatus.setTaskReceive((int) siemensNet.getByteTransform().TransInt16(result.Content, 10)); |
| | | |
| | | //工位2 |
| | | crnStatus.setTaskNoTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 14)); |
| | | crnStatus.setStatusTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 16)); |
| | | crnStatus.setBayTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 18)); |
| | | crnStatus.setLevelTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 20)); |
| | | crnStatus.setForkPosTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 22)); |
| | | crnStatus.setLoadedTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 24)); |
| | | crnStatus.setWalkPosTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 28)); |
| | | crnStatus.setTaskNoTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 12)); |
| | | crnStatus.setStatusTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 14)); |
| | | crnStatus.setForkPosTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 16)); |
| | | crnStatus.setLoadedTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 18)); |
| | | crnStatus.setTaskReceiveTwo((int) siemensNet.getByteTransform().TransInt16(result.Content, 20)); |
| | | |
| | | crnStatus.setAlarm((int) siemensNet.getByteTransform().TransInt16(result.Content, 18)); |
| | | crnStatus.setTemp1((int) siemensNet.getByteTransform().TransInt16(result.Content, 20)); |
| | | crnStatus.setTemp2((int) siemensNet.getByteTransform().TransInt16(result.Content, 22)); |
| | | crnStatus.setTemp3((int) siemensNet.getByteTransform().TransInt16(result.Content, 24)); |
| | | crnStatus.setTemp4((int) siemensNet.getByteTransform().TransInt16(result.Content, 26)); |
| | | crnStatus.setXSpeed((int) siemensNet.getByteTransform().TransInt16(result.Content, 28)); |
| | | crnStatus.setYSpeed((int) siemensNet.getByteTransform().TransInt16(result.Content, 32)); |
| | | crnStatus.setZSpeed((int) siemensNet.getByteTransform().TransInt16(result.Content, 36)); |
| | | crnStatus.setXDistance((int) siemensNet.getByteTransform().TransInt16(result.Content, 40)); |
| | | crnStatus.setYDistance((int) siemensNet.getByteTransform().TransInt16(result.Content, 44)); |
| | | crnStatus.setXDuration((int) siemensNet.getByteTransform().TransInt16(result.Content, 48)); |
| | | crnStatus.setYDuration((int) siemensNet.getByteTransform().TransInt16(result.Content, 52)); |
| | | crnStatus.setBay((int) siemensNet.getByteTransform().TransInt16(result.Content, 22)); |
| | | crnStatus.setLevel((int) siemensNet.getByteTransform().TransInt16(result.Content, 24)); |
| | | crnStatus.setLiftPos((int) siemensNet.getByteTransform().TransInt16(result.Content, 26)); |
| | | crnStatus.setWalkPos((int) siemensNet.getByteTransform().TransInt16(result.Content, 28)); |
| | | crnStatus.setAlarm((int) siemensNet.getByteTransform().TransInt16(result.Content, 30)); |
| | | crnStatus.setTemp1((int) siemensNet.getByteTransform().TransInt16(result.Content, 34)); |
| | | crnStatus.setTemp2((int) siemensNet.getByteTransform().TransInt16(result.Content, 36)); |
| | | crnStatus.setTemp3((int) siemensNet.getByteTransform().TransInt16(result.Content, 38)); |
| | | crnStatus.setTemp4((int) siemensNet.getByteTransform().TransInt16(result.Content, 40)); |
| | | crnStatus.setXSpeed((int) siemensNet.getByteTransform().TransInt16(result.Content, 42)); |
| | | crnStatus.setYSpeed((int) siemensNet.getByteTransform().TransInt16(result.Content, 44)); |
| | | crnStatus.setZSpeed((int) siemensNet.getByteTransform().TransInt16(result.Content, 46)); |
| | | crnStatus.setXDistance((int) siemensNet.getByteTransform().TransInt16(result.Content, 48)); |
| | | crnStatus.setYDistance((int) siemensNet.getByteTransform().TransInt16(result.Content, 50)); |
| | | crnStatus.setXDuration((int) siemensNet.getByteTransform().TransInt16(result.Content, 52)); |
| | | crnStatus.setYDuration((int) siemensNet.getByteTransform().TransInt16(result.Content, 54)); |
| | | crnStatus.setGoodsType((int) siemensNet.getByteTransform().TransInt16(result.Content, 56)); |
| | | |
| | | String barcode = siemensNet.getByteTransform().TransString(result.Content, 58, 8, "UTF-8"); |
| | | crnStatus.setBarcode(barcode); |
| | | return crnStatus; |
| | | } else { |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】读取双工位堆垛机plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | |
| | | @Override |
| | | public CommandResponse sendCommand(DualCrnCommand command) { |
| | | CommandResponse response = new CommandResponse(false); |
| | | try { |
| | | if (null == command) { |
| | | News.error("双工位堆垛机写入命令为空"); |
| | | response.setMessage("双工位堆垛机写入命令为空"); |
| | | return response; |
| | | } |
| | | try { |
| | | if (null == command) { |
| | | News.error("双工位堆垛机写入命令为空"); |
| | | response.setMessage("双工位堆垛机写入命令为空"); |
| | | return response; |
| | | } |
| | | |
| | | String address = "DB100.0"; |
| | | if (command.getStation() == 1) { |
| | | //工位1 |
| | | address = "DB100.0"; |
| | | }else { |
| | | //工位2 |
| | | address = "DB100.20"; |
| | | } |
| | | String address = "DB100.0"; |
| | | if (command.getStation() == 1) { |
| | | //工位1 |
| | | address = "DB100.0"; |
| | | }else { |
| | | //工位2 |
| | | address = "DB100.18"; |
| | | } |
| | | |
| | | int writeAck = 0; |
| | | boolean ackResult = false; |
| | | do { |
| | | OperateResult resultAck = siemensNet.Write(address, (short) 0); |
| | | if (resultAck.IsSuccess) { |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read(address, (short) 2); |
| | | short ack = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0); |
| | | if (ack != 0) { |
| | | writeAck++; |
| | | String confirmAddress = "DB100.16"; |
| | | if (command.getStation() == 1) { |
| | | //工位1 |
| | | confirmAddress = "DB100.16"; |
| | | }else { |
| | | //工位2 |
| | | confirmAddress = "DB100.34"; |
| | | } |
| | | |
| | | short[] array = new short[9]; |
| | | array[0] = command.getTaskNo().shortValue(); |
| | | array[1] = command.getTaskMode().shortValue(); |
| | | array[2] = command.getSourcePosX().shortValue(); |
| | | array[3] = command.getSourcePosY().shortValue(); |
| | | array[4] = command.getSourcePosZ().shortValue(); |
| | | array[5] = command.getDestinationPosX().shortValue(); |
| | | array[6] = command.getDestinationPosY().shortValue(); |
| | | array[7] = command.getDestinationPosZ().shortValue(); |
| | | array[8] = (short) 0; |
| | | |
| | | OperateResult result = siemensNet.Write(address, array); |
| | | if (!result.IsSuccess) { |
| | | News.error("双工位堆垛机写入堆垛机plc数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | response.setMessage("双工位堆垛机写入堆垛机plc数据失败"); |
| | | return response; |
| | | } |
| | | |
| | | int idx = 0; |
| | | do { |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read(address, (short) 18); |
| | | if (resultRead.IsSuccess) { |
| | | short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2); |
| | | short taskMode = siemensNet.getByteTransform().TransInt16(resultRead.Content, 4); |
| | | short sourcePosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 6); |
| | | short sourcePosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 8); |
| | | short sourcePosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10); |
| | | short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12); |
| | | short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14); |
| | | short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 16); |
| | | if (taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) { |
| | | result = siemensNet.Write(address, array); |
| | | } else { |
| | | News.info("双工位堆垛机命令下发[id:{}] >>>>> {}", command.getCrnNo(), "ack复位完成"); |
| | | ackResult = true; |
| | | break; |
| | | } |
| | | } |
| | | } while (writeAck < 5); |
| | | } |
| | | idx++; |
| | | Thread.sleep(500); |
| | | } while (idx < 5); |
| | | |
| | | if (!ackResult) { |
| | | response.setMessage("双工位堆垛机命令下发[id:{}] >>>>> {}" + command.getCrnNo() + "ack复位失败"); |
| | | return response; |
| | | } |
| | | OperateResult confirmResult = siemensNet.Write(confirmAddress, (short) 1); |
| | | if (!confirmResult.IsSuccess) { |
| | | News.error("双工位堆垛机写入确认数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | response.setMessage("双工位堆垛机写入确认数据失败"); |
| | | return response; |
| | | } |
| | | |
| | | 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(); |
| | | if (result != null && result.IsSuccess) { |
| | | News.info("双工位堆垛机命令下发[id:{}] >>>>> {}", command.getCrnNo(), JSON.toJSON(command)); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command))); |
| | | response.setResult(true); |
| | | response.setMessage("命令下发成功"); |
| | | } else { |
| | | News.error("双工位堆垛机写入堆垛机plc数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}]", DateUtils.convert(new Date()), command.getCrnNo())); |
| | | response.setResult(false); |
| | | response.setMessage("命令下发失败"); |
| | | } |
| | | |
| | | OperateResult result = null; |
| | | int idx = 0; |
| | | do { |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read(address, (short) 20); |
| | | if (resultRead.IsSuccess) { |
| | | if (command.getAckFinish() == 0) { |
| | | short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2); |
| | | short taskMode = siemensNet.getByteTransform().TransInt16(resultRead.Content, 4); |
| | | short sourcePosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 6); |
| | | short sourcePosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 8); |
| | | short sourcePosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10); |
| | | short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12); |
| | | short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14); |
| | | short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 16); |
| | | if (taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) { |
| | | result = siemensNet.Write(address, array); |
| | | } else { |
| | | break; |
| | | } |
| | | } else { |
| | | short ackFinish = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0); |
| | | if (ackFinish != command.getAckFinish()) { |
| | | result = siemensNet.Write(address, array); |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | idx++; |
| | | Thread.sleep(500); |
| | | } while (idx < 5); |
| | | return response; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ()); |
| | | String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ()); |
| | | |
| | | if (command.getAckFinish() == 0) { |
| | | short commandFinish = 1; |
| | | int i = 0; |
| | | do { |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read(address, (short) 4); |
| | | OperateResultExOne<byte[]> resultReadConfirm = siemensNet.Read(address + 18, (short) 2); |
| | | if (resultRead.IsSuccess && resultReadConfirm.IsSuccess) { |
| | | short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2); |
| | | short confirm = siemensNet.getByteTransform().TransInt16(resultReadConfirm.Content, 0); |
| | | if (taskNo != 0 && confirm == 0) { |
| | | result = siemensNet.Write(address + 18, commandFinish); |
| | | } |
| | | } |
| | | i++; |
| | | Thread.sleep(500); |
| | | } while (i < 5); |
| | | } |
| | | |
| | | if (result != null && result.IsSuccess) { |
| | | News.info("SiemensDualCrn 双工位堆垛机命令下发[id:{}] >>>>> {}", command.getCrnNo(), JSON.toJSON(command)); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command))); |
| | | response.setResult(true); |
| | | response.setMessage("命令下发成功"); |
| | | } else { |
| | | News.error("SiemensDualCrn 双工位堆垛机写入堆垛机plc数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}]", DateUtils.convert(new Date()), command.getCrnNo())); |
| | | response.setResult(false); |
| | | response.setMessage("命令下发失败"); |
| | | } |
| | | |
| | | return response; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ()); |
| | | String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ()); |
| | | |
| | | // 日志记录 |
| | | BasCrnpOptService bean = SpringUtils.getBean(BasCrnpOptService.class); |
| | | BasCrnpOpt basCrnpOpt = new BasCrnpOpt( |
| | | command.getTaskNo().intValue(), // 任务号 |
| | | command.getCrnNo(), // 堆垛机[非空] |
| | | new Date(), // 下发时间 |
| | | String.valueOf(command.getTaskMode()), // 模式 |
| | | sourceLocNo, //源库位 |
| | | targetLocNo, //目标库位 |
| | | null, // 修改时间 |
| | | null, // 修改人员 |
| | | null, // 备注 |
| | | JSON.toJSONString(command), // 指令 |
| | | JSON.toJSONString(getStatus()), // 系统状态 |
| | | 1, // 下发状态{0:未下发,1:已下发} |
| | | JSON.toJSONString(response) // 响应 |
| | | ); |
| | | bean.insert(basCrnpOpt); |
| | | } |
| | | // 日志记录 |
| | | BasDualCrnpOptService bean = SpringUtils.getBean(BasDualCrnpOptService.class); |
| | | BasDualCrnpOpt basDualCrnp = new BasDualCrnpOpt( |
| | | command.getTaskNo(), // 任务号 |
| | | command.getCrnNo(), // 堆垛机[非空] |
| | | new Date(), // 下发时间 |
| | | String.valueOf(command.getTaskMode()), // 模式 |
| | | sourceLocNo, //源库位 |
| | | targetLocNo, //目标库位 |
| | | null, // 修改时间 |
| | | null, // 修改人员 |
| | | null, // 备注 |
| | | JSON.toJSONString(command), // 指令 |
| | | JSON.toJSONString(getStatus()), // 系统状态 |
| | | 1, // 下发状态{0:未下发,1:已下发} |
| | | JSON.toJSONString(response) // 响应 |
| | | ); |
| | | bean.insert(basDualCrnp); |
| | | } |
| | | return response; |
| | | } |
| | | } |