| | |
| | | import com.alibaba.fastjson.JSON; |
| | | 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.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.CrnTaskModeType; |
| | | import com.zy.core.enums.DualCrnTaskModeType; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.model.CommandResponse; |
| | |
| | | crnStatus.setXDuration((double) siemensNet.getByteTransform().TransSingle(result.Content, 62)); |
| | | crnStatus.setYDuration((double) siemensNet.getByteTransform().TransSingle(result.Content, 66)); |
| | | |
| | | OperateResultExOne<byte[]> taskResult = siemensNet.Read("DB100.0", (short) 18); |
| | | OperateResultExOne<byte[]> taskResult = siemensNet.Read("DB100.0", (short) 36); |
| | | if (taskResult.IsSuccess) { |
| | | short taskNo = siemensNet.getByteTransform().TransInt16(taskResult.Content, 0); |
| | | short taskMode = siemensNet.getByteTransform().TransInt16(taskResult.Content, 2); |
| | | short sourcePosX = siemensNet.getByteTransform().TransInt16(taskResult.Content, 4); |
| | | short sourcePosY = siemensNet.getByteTransform().TransInt16(taskResult.Content, 6); |
| | | short sourcePosZ = siemensNet.getByteTransform().TransInt16(taskResult.Content, 8); |
| | | short destinationPosX = siemensNet.getByteTransform().TransInt16(taskResult.Content, 10); |
| | | short destinationPosY = siemensNet.getByteTransform().TransInt16(taskResult.Content, 12); |
| | | short destinationPosZ = siemensNet.getByteTransform().TransInt16(taskResult.Content, 14); |
| | | short confirm = siemensNet.getByteTransform().TransInt16(taskResult.Content, 16); |
| | | byte[] taskContent = taskResult.Content; |
| | | |
| | | // 工位1命令区:DB100.0 ~ DB100.17 |
| | | short taskNo = siemensNet.getByteTransform().TransInt16(taskContent, 0); |
| | | short taskMode = siemensNet.getByteTransform().TransInt16(taskContent, 2); |
| | | short sourcePosX = siemensNet.getByteTransform().TransInt16(taskContent, 4); |
| | | short sourcePosY = siemensNet.getByteTransform().TransInt16(taskContent, 6); |
| | | short sourcePosZ = siemensNet.getByteTransform().TransInt16(taskContent, 8); |
| | | short destinationPosX = siemensNet.getByteTransform().TransInt16(taskContent, 10); |
| | | short destinationPosY = siemensNet.getByteTransform().TransInt16(taskContent, 12); |
| | | short destinationPosZ = siemensNet.getByteTransform().TransInt16(taskContent, 14); |
| | | short confirm = siemensNet.getByteTransform().TransInt16(taskContent, 16); |
| | | |
| | | int hasData = 0; |
| | | if(taskNo != 0 || taskMode != 0 || sourcePosX != 0 || sourcePosY != 0 || sourcePosZ != 0 || destinationPosX != 0 || destinationPosY != 0 || destinationPosZ != 0 || confirm != 0) { |
| | |
| | | |
| | | if (clear) { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | Object lock = redisUtil.get(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo()); |
| | | Object lock = redisUtil.get(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + 1); |
| | | if (lock == null) { |
| | | OperateResult taskClearResult = siemensNet.Write("DB100.0", array); |
| | | redisUtil.set(RedisKeyType.CLEAR_DUAL_CRN_TASK_LIMIT.key + deviceConfig.getDeviceNo(), "lock", 3); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + 1, "lock", 1); |
| | | News.info("双工位堆垛机:{}号{}工位命令区域清空,原始数据:{}", deviceConfig.getDeviceNo(), 1, JSON.toJSONString(map)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | crnStatus.setTaskSend(hasData); |
| | | } |
| | | |
| | | OperateResultExOne<byte[]> taskResult2 = siemensNet.Read("DB100.18", (short) 18); |
| | | if (taskResult2.IsSuccess) { |
| | | short taskNo = siemensNet.getByteTransform().TransInt16(taskResult2.Content, 0); |
| | | short taskMode = siemensNet.getByteTransform().TransInt16(taskResult2.Content, 2); |
| | | short sourcePosX = siemensNet.getByteTransform().TransInt16(taskResult2.Content, 4); |
| | | short sourcePosY = siemensNet.getByteTransform().TransInt16(taskResult2.Content, 6); |
| | | short sourcePosZ = siemensNet.getByteTransform().TransInt16(taskResult2.Content, 8); |
| | | short destinationPosX = siemensNet.getByteTransform().TransInt16(taskResult2.Content, 10); |
| | | short destinationPosY = siemensNet.getByteTransform().TransInt16(taskResult2.Content, 12); |
| | | short destinationPosZ = siemensNet.getByteTransform().TransInt16(taskResult2.Content, 14); |
| | | short confirm = siemensNet.getByteTransform().TransInt16(taskResult2.Content, 16); |
| | | // 工位2命令区:DB100.18 ~ DB100.35 |
| | | short taskNoTwo = siemensNet.getByteTransform().TransInt16(taskContent, 18); |
| | | short taskModeTwo = siemensNet.getByteTransform().TransInt16(taskContent, 20); |
| | | short sourcePosXTwo = siemensNet.getByteTransform().TransInt16(taskContent, 22); |
| | | short sourcePosYTwo = siemensNet.getByteTransform().TransInt16(taskContent, 24); |
| | | short sourcePosZTwo = siemensNet.getByteTransform().TransInt16(taskContent, 26); |
| | | short destinationPosXTwo = siemensNet.getByteTransform().TransInt16(taskContent, 28); |
| | | short destinationPosYTwo = siemensNet.getByteTransform().TransInt16(taskContent, 30); |
| | | short destinationPosZTwo = siemensNet.getByteTransform().TransInt16(taskContent, 32); |
| | | short confirmTwo = siemensNet.getByteTransform().TransInt16(taskContent, 34); |
| | | |
| | | int hasData = 0; |
| | | if(taskNo != 0 || taskMode != 0 || sourcePosX != 0 || sourcePosY != 0 || sourcePosZ != 0 || destinationPosX != 0 || destinationPosY != 0 || destinationPosZ != 0 || confirm != 0) { |
| | | hasData = 1; |
| | | int hasDataTwo = 0; |
| | | if(taskNoTwo != 0 || taskModeTwo != 0 || sourcePosXTwo != 0 || sourcePosYTwo != 0 || sourcePosZTwo != 0 || destinationPosXTwo != 0 || destinationPosYTwo != 0 || destinationPosZTwo != 0 || confirmTwo != 0) { |
| | | hasDataTwo = 1; |
| | | if (crnStatus.getTaskReceiveTwo() == 1) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("taskNo", taskNo); |
| | | map.put("taskMode", taskMode); |
| | | map.put("sourcePosX", sourcePosX); |
| | | map.put("sourcePosY", sourcePosY); |
| | | map.put("sourcePosZ", sourcePosZ); |
| | | map.put("destinationPosX", destinationPosX); |
| | | map.put("destinationPosY", destinationPosY); |
| | | map.put("destinationPosZ", destinationPosZ); |
| | | map.put("confirm", confirm); |
| | | map.put("taskNo", taskNoTwo); |
| | | map.put("taskMode", taskModeTwo); |
| | | map.put("sourcePosX", sourcePosXTwo); |
| | | map.put("sourcePosY", sourcePosYTwo); |
| | | map.put("sourcePosZ", sourcePosZTwo); |
| | | map.put("destinationPosX", destinationPosXTwo); |
| | | map.put("destinationPosY", destinationPosYTwo); |
| | | map.put("destinationPosZ", destinationPosZTwo); |
| | | map.put("confirm", confirmTwo); |
| | | |
| | | short[] array = new short[9]; |
| | | array[0] = (short) 0; |
| | |
| | | array[8] = (short) 0; |
| | | |
| | | boolean clear = false; |
| | | if (taskMode == DualCrnTaskModeType.CONFIRM.id) { |
| | | if (taskModeTwo == DualCrnTaskModeType.CONFIRM.id) { |
| | | // if (crnStatus.getStatusTwo() == 0) { |
| | | // clear = true; |
| | | // } |
| | |
| | | |
| | | if (clear) { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | Object lock = redisUtil.get(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo()); |
| | | Object lock = redisUtil.get(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + 2); |
| | | if (lock == null) { |
| | | OperateResult taskClearResult = siemensNet.Write("DB100.18", array); |
| | | redisUtil.set(RedisKeyType.CLEAR_DUAL_CRN_TASK_LIMIT.key + deviceConfig.getDeviceNo(), "lock", 3); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + 2, "lock", 1); |
| | | News.info("双工位堆垛机:{}号{}工位命令区域清空,原始数据:{}", deviceConfig.getDeviceNo(), 2, JSON.toJSONString(map)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | crnStatus.setTaskSendTwo(hasData); |
| | | crnStatus.setTaskSendTwo(hasDataTwo); |
| | | } |
| | | |
| | | return crnStatus; |
| | |
| | | @Override |
| | | public CommandResponse sendCommand(DualCrnCommand command) { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo(), "lock", 3); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + command.getStation(), "lock", 1); |
| | | CommandResponse response = new CommandResponse(false); |
| | | try { |
| | | if (null == command) { |
| | |
| | | } |
| | | } |
| | | idx++; |
| | | Thread.sleep(500); |
| | | Thread.sleep(200); |
| | | } while (idx < 5); |
| | | |
| | | OperateResult confirmResult = siemensNet.Write(confirmAddress, (short) 1); |
| | |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command))); |
| | | response.setResult(true); |
| | | response.setMessage("命令下发成功"); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo(), "lock", 3); |
| | | redisUtil.set(RedisKeyType.DUAL_CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo() + "_" + command.getStation(), "lock", 1); |
| | | } else { |
| | | News.error("双工位堆垛机写入堆垛机plc数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}]", DateUtils.convert(new Date()), command.getCrnNo())); |