| | |
| | | import com.zy.asrs.framework.common.SpringUtils; |
| | | import com.zy.asrs.wcs.core.entity.BasConveyor; |
| | | import com.zy.asrs.wcs.core.entity.BasConveyorSta; |
| | | import com.zy.asrs.wcs.core.entity.DeviceBarcode; |
| | | import com.zy.asrs.wcs.core.service.BasConveyorService; |
| | | import com.zy.asrs.wcs.core.service.BasConveyorStaService; |
| | | import com.zy.asrs.wcs.core.service.DeviceBarcodeService; |
| | | import com.zy.asrs.wcs.core.utils.RedisUtil; |
| | | import com.zy.asrs.wcs.rcs.News; |
| | | import com.zy.asrs.wcs.rcs.cache.OutputQueue; |
| | | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; |
| | | import com.zy.asrs.wcs.rcs.entity.Device; |
| | | import com.zy.asrs.wcs.rcs.model.dto.WorkModeTypeDto; |
| | | import com.zy.asrs.wcs.rcs.model.enums.SlaveType; |
| | | import com.zy.asrs.wcs.rcs.model.enums.WorkModeType; |
| | | import com.zy.asrs.wcs.rcs.model.protocol.StaProtocol; |
| | | import com.zy.asrs.wcs.rcs.thread.BarcodeThread; |
| | | import com.zy.asrs.wcs.rcs.thread.DevpThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | |
| | | staProtocol.setInEnable(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 14) == 1); // 可入 |
| | | staProtocol.setOutEnable(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 14) == 2);// 可出 |
| | | staProtocol.setWorkMode((int) siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 8));// 工作模式 |
| | | |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result.Content,58,8, "UTF-8");// 条码 |
| | | BasConveyorStaService basConveyorStaService = SpringUtils.getBean(BasConveyorStaService.class); |
| | | DeviceBarcodeService deviceBarcodeService = SpringUtils.getBean(DeviceBarcodeService.class); |
| | | BasConveyorSta basConveyorSta = basConveyorStaService.getOne(new LambdaQueryWrapper<BasConveyorSta>().eq(BasConveyorSta::getSiteNo, siteId)); |
| | | if (basConveyorSta != null) { |
| | | DeviceBarcode deviceBarcode = deviceBarcodeService.getById(basConveyorSta.getBarcodeId()); |
| | | if (deviceBarcode != null) { |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, Integer.parseInt(deviceBarcode.getDeviceId())); |
| | | if (barcodeThread != null) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // staProtocol.setEmptyMk(status[4]); // 空板信号 |
| | | // staProtocol.setFullPlt(status[5]); // 满托盘 |
| | | // staProtocol.setHigh(status[6]); // 高库位 |
| | |
| | | |
| | | String workNoAddress = "DB1001." + (index * 20 + 100 + 2); |
| | | String staNoAddress = "DB1001." + (index * 20 + 100 + 4); |
| | | OperateResult write1 = siemensS7Net.Write(workNoAddress, workNo); // 工作号 |
| | | OperateResult write2 = siemensS7Net.Write(staNoAddress, staNo); // 目标站 |
| | | OperateResult write1 = null; // 工作号 |
| | | OperateResult write2 = null; // 目标站 |
| | | |
| | | if (!(write1.IsSuccess && write2.IsSuccess)) { |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { |
| | | staProtocol.setPakMk(true); |
| | | //任务下发次数 |
| | | int writeCount = 0; |
| | | do { |
| | | write1 = siemensS7Net.Write(workNoAddress, workNo); // 工作号 |
| | | write2 = siemensS7Net.Write(staNoAddress, staNo); // 目标站 |
| | | if ((write1.IsSuccess && write2.IsSuccess)) { |
| | | OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB1000." + (index * 40 + 100 + 2), (short) 4); |
| | | if (readResult.IsSuccess) { |
| | | short workNo2 = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0); |
| | | short staNo2 = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 2); |
| | | if (workNo == workNo2 && staNo == staNo2) { |
| | | //任务命令写入成功 |
| | | log.info("写入输送线命令后返回成功,并且回读成功。输送线plc编号={},{},{},写入次数={}", siteId, JSON.toJSON(workNo), JSON.toJSON(staNo), writeCount); |
| | | return true; |
| | | } else {//返回结果是成功了,但是真实值不相同 |
| | | writeCount++; |
| | | log.error("写入输送线命令后返回成功,但是读取任务值不一致。输送线plc编号={},{},{},写入次数={}", siteId, JSON.toJSON(workNo), JSON.toJSON(staNo), writeCount); |
| | | } |
| | | } else { |
| | | writeCount++; |
| | | log.error("写入输送线命令后读取失败。输送线plc编号={},站点数据={},{},写入次数={}", siteId, JSON.toJSON(workNo), JSON.toJSON(staNo), writeCount); |
| | | } |
| | | }else { |
| | | writeCount++; |
| | | } |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", device.getId(), JSON.toJSON(staProtocol))); |
| | | log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", device.getId(), JSON.toJSON(staProtocol)); |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), device.getId(), JSON.toJSON(staNo))); |
| | | log.info("输送线命令下发 [id:{}] >>>>> 命令下发: {}", device.getId(), JSON.toJSON(staNo)); |
| | | return true; |
| | | }while (writeCount < 5) ; |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", device.getId(), JSON.toJSON(staProtocol))); |
| | | log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", device.getId(), JSON.toJSON(staProtocol)); |
| | | return false; |
| | | } |
| | | |