| | |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.command.CrnCommand; |
| | | import com.zy.core.network.api.ZyCrnConnectApi; |
| | |
| | | @Override |
| | | public ZyCrnStatusEntity getStatus() { |
| | | try { |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56); |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 62); |
| | | if (result.IsSuccess) { |
| | | ZyCrnStatusEntity crnStatus = new ZyCrnStatusEntity(); |
| | | crnStatus.setCrnNo(deviceConfig.getDeviceNo()); |
| | |
| | | crnStatus.setYDistance((double) siemensNet.getByteTransform().TransSingle(result.Content, 44)); |
| | | crnStatus.setXDuration((double) siemensNet.getByteTransform().TransSingle(result.Content, 48)); |
| | | crnStatus.setYDuration((double) siemensNet.getByteTransform().TransSingle(result.Content, 52)); |
| | | crnStatus.setTaskReceive((int) siemensNet.getByteTransform().TransInt16(result.Content, 60)); |
| | | |
| | | if (crnStatus.getStatus() == 0 && crnStatus.getTaskReceive() == 0) { |
| | | OperateResultExOne<byte[]> taskResult = siemensNet.Read("DB100.0", (short) 20); |
| | | if (taskResult.IsSuccess) { |
| | | short taskNo = siemensNet.getByteTransform().TransInt16(taskResult.Content, 2); |
| | | short taskMode = siemensNet.getByteTransform().TransInt16(taskResult.Content, 4); |
| | | short sourcePosX = siemensNet.getByteTransform().TransInt16(taskResult.Content, 6); |
| | | short sourcePosY = siemensNet.getByteTransform().TransInt16(taskResult.Content, 8); |
| | | short sourcePosZ = siemensNet.getByteTransform().TransInt16(taskResult.Content, 10); |
| | | short destinationPosX = siemensNet.getByteTransform().TransInt16(taskResult.Content, 12); |
| | | short destinationPosY = siemensNet.getByteTransform().TransInt16(taskResult.Content, 14); |
| | | short destinationPosZ = siemensNet.getByteTransform().TransInt16(taskResult.Content, 16); |
| | | short confirm = siemensNet.getByteTransform().TransInt16(taskResult.Content, 18); |
| | | |
| | | if(taskNo != 0 || taskMode != 0 || sourcePosX != 0 || sourcePosY != 0 || sourcePosZ != 0 || destinationPosX != 0 || destinationPosY != 0 || destinationPosZ != 0 || confirm != 0) { |
| | | short[] array = new short[10]; |
| | | array[0] = (short) 0; |
| | | array[1] = (short) 0; |
| | | array[2] = (short) 0; |
| | | array[3] = (short) 0; |
| | | array[4] = (short) 0; |
| | | array[5] = (short) 0; |
| | | array[6] = (short) 0; |
| | | array[7] = (short) 0; |
| | | array[8] = (short) 0; |
| | | array[9] = (short) 0; |
| | | |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | Object lock = redisUtil.get(RedisKeyType.CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo()); |
| | | if (lock == null) { |
| | | OperateResult taskClearResult = siemensNet.Write("DB100.0", array); |
| | | redisUtil.set(RedisKeyType.CLEAR_CRN_TASK_LIMIT.key + deviceConfig.getDeviceNo(), "lock", 3); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return crnStatus; |
| | | } else { |
| | |
| | | |
| | | @Override |
| | | public CommandResponse sendCommand(CrnCommand command) { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | redisUtil.set(RedisKeyType.CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo(), "lock", 10); |
| | | CommandResponse response = new CommandResponse(false); |
| | | try { |
| | | if (null == command) { |
| | |
| | | } |
| | | |
| | | int idx = 0; |
| | | boolean contentFlag = false; |
| | | do { |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20); |
| | | if (resultRead.IsSuccess) { |
| | |
| | | if (taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) { |
| | | result = siemensNet.Write("DB100.0", array); |
| | | } else { |
| | | contentFlag = true; |
| | | break; |
| | | } |
| | | } |
| | |
| | | Thread.sleep(500); |
| | | } while (idx < 5); |
| | | |
| | | OperateResult confirmResult = siemensNet.Write("DB100.18", (short) 1); |
| | | if (!confirmResult.IsSuccess) { |
| | | if(!contentFlag) { |
| | | News.error("堆垛机写入任务数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | response.setMessage("堆垛机写入任务数据失败"); |
| | | return response; |
| | | } |
| | | |
| | | int confirmIdx = 0; |
| | | boolean confirmFlag = false; |
| | | do { |
| | | OperateResult confirmResult = siemensNet.Write("DB100.18", (short) 1); |
| | | if (!confirmResult.IsSuccess) { |
| | | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.18", (short) 2); |
| | | if (resultRead.IsSuccess) { |
| | | short confirm = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0); |
| | | if(confirm == 0) { |
| | | confirmResult = siemensNet.Write("DB100.18", (short) 1); |
| | | }else { |
| | | confirmFlag = true; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | confirmIdx++; |
| | | Thread.sleep(500); |
| | | } while (confirmIdx < 5); |
| | | |
| | | if(!confirmFlag) { |
| | | News.error("堆垛机写入确认数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | response.setMessage("堆垛机写入确认数据失败"); |
| | | return response; |
| | |
| | | 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.CRN_SEND_COMMAND_LOCK.key + deviceConfig.getDeviceNo(), "lock", 5); |
| | | } else { |
| | | News.error("写入堆垛机plc数据失败 ===>> [id:{}]", command.getCrnNo()); |
| | | OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}]", DateUtils.convert(new Date()), command.getCrnNo())); |