From 2f24f6b67e63f3ba80bef01e4f45b064ba3815fe Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Thu, 20 Jun 2024 08:59:35 +0800 Subject: [PATCH] =?UTF-8?q?rev=EF=BC=9A=E5=88=A0=E6=8E=89=E8=BE=93?= =?UTF-8?q?=E9=80=81=E7=BA=BF=E5=A4=9A=E4=BD=99=E4=BF=A1=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...InspectionScannerConveyorDeviceDriver.java | 167 ++++++++++++++---- .../ItemProtocol.java | 28 ++- 2 files changed, 144 insertions(+), 51 deletions(-) diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/AppearanceInspectionScannerConveyorDeviceDriver.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/AppearanceInspectionScannerConveyorDeviceDriver.java index 524bb48..8d0a42c 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/AppearanceInspectionScannerConveyorDeviceDriver.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/AppearanceInspectionScannerConveyorDeviceDriver.java @@ -17,6 +17,7 @@ import org.nl.acs.device.device.service.DeviceAssignedService; import org.nl.acs.device.device.service.dto.DeviceAssignedDto; import org.nl.acs.device.driver.*; import org.nl.acs.device.driver.conveyor.appearance_inspection_scannner_conveyor.enums.CommandEnum; +import org.nl.acs.device.driver.conveyor.strip_conveyor.StripConveyorDeviceDriver; import org.nl.acs.device.enums.RequestTypeEnum; import org.nl.acs.ext.UnifiedResponse; import org.nl.acs.ext.wms.service.AcsToWmsService; @@ -91,16 +92,6 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc */ private int task = 0; private int lastTask = 0; - /** - * 托盘类型 - */ - private int containerType = 0; - private int lastContainerType = 0; - /** - * 托盘方向 - */ - private int containerDirection = 0; - private int lastContainerDirection = 0; /** * 高度 */ @@ -134,8 +125,9 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc /** * 下发托盘类型 */ - private int toContainerType = 0; - private int lastToContainerType = 0; + private int toHeight = 0; + private int lastToHeight = 0; + /** * 当前设备编号 */ @@ -205,6 +197,15 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc if (this.move != 0 && this.task > 0) { this.update_instruction_status_by_task(); } + if (this.mode != this.lastMode) { + boolean pinkFlag = Optional.ofNullable(this.getExtraValue().get("pinkDevicePoint")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); + if (pinkFlag) { + JSONObject req = new JSONObject(); + req.put("device_code", this.currentDeviceCode); + req.put("type", this.mode); + //acsToWmsService.feedPinkStartStop(req); + } + } } @Override @@ -240,14 +241,35 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc this.applyInTask(); } else if (this.mode == 7 && this.move > 0 && StrUtil.isNotEmpty(this.barcode) && !requireSuccess) { this.applyAgvTask(); + } else if (this.mode == 8 && this.move > 0 && StrUtil.isNotEmpty(this.barcode) && !requireSuccess) { + this.getHeightByVehicleCode(); } } } + private boolean isTimeValid(long currentTimeMillis) { return currentTimeMillis - this.requireTime >= this.requireTimeOut; } + private void getHeightByVehicleCode() { + long currentTimeMillis = System.currentTimeMillis(); + if (!isTimeValid(currentTimeMillis)) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.requireTimeOut); + } else { + this.requireTime = currentTimeMillis; +// JSONObject requestParam = new JSONObject(); +// requestParam.put("type", RequestTypeEnum.APPLY_IN_TASK.getType()); +// JSONObject param = new JSONObject(); +// param.put(this.barcode, this.currentDeviceCode); +// requestParam.put("param", param); +// UnifiedResponse response = acsToWmsService.applyTaskToWms(requestParam); +// if (response.isSuccess()) { +// this.requireSuccess = true; +// } + } + } + /** * 申请入库任务 */ @@ -305,6 +327,7 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc return acsToWmsService.applyTaskToWms(requestParam); } + public void createInInstruction() { long currentTimeMillis = System.currentTimeMillis(); if (!isTimeValid(currentTimeMillis)) { @@ -360,9 +383,43 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc } Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); if (nextDevice == null) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "创建指令失败, 未配置指令终点驱动信息, 终点: " + instDto.getNext_device_code())); + logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "创建指令失败, 未配置指令终点驱动信息, 终点: " + next_device_code)); return; } + //判断入库任务的起点是否是双向点位,即既是起点又是终点 + boolean toWayFlag = Optional.ofNullable(this.getExtraValue().get("toWay")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); + //如果是双向点位 + if (toWayFlag) { + //获取该点所属输送线 + String belongToConveyor = Optional.ofNullable(this.getExtraValue().get("belongToConveyor")).map(Object::toString).orElse(null); + if (belongToConveyor != null) { + Device belongToConveyorDevice = deviceAppService.findDeviceByCode(belongToConveyor); + if (belongToConveyorDevice != null && belongToConveyorDevice.getDeviceDriver() instanceof StripConveyorDeviceDriver) { + StripConveyorDeviceDriver stripConveyorDeviceDriver = (StripConveyorDeviceDriver) belongToConveyorDevice.getDeviceDriver(); + //如果所属输送线不是入库模式 + if (stripConveyorDeviceDriver.getInOutMode() != 0) { + String samePoint = Optional.ofNullable(this.getExtraValue().get("samePoint")).map(Object::toString).orElse(null); + TaskDto existTask; + if (StrUtil.isNotEmpty(samePoint)) { + existTask = taskService.findByNextCode(samePoint); + } else { + existTask = taskService.findByNextCode(this.currentDeviceCode); + } + if (ObjectUtil.isNotEmpty(existTask)) { + return; + } + //判断所属输送线是否允许切换出入库模式 + if (stripConveyorDeviceDriver.getSwitchInOut() == 0) { + //切换出入库模式 + stripConveyorDeviceDriver.writing("toCommand", 0); + return; + } else { + return; + } + } + } + } + } if (nextDevice.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { setInstruction(instDto, taskDto, start_device_code, next_device_code); } else { @@ -373,7 +430,8 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc taskDto.setTask_status(TaskStatusEnum.BUSY.getIndex()); taskService.update(taskDto); if (nextDevice.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { - if (StrUtil.equals(this.getDevice().getRegion(), nextDevice.getRegion())) { + List targetDeviceCode = this.getExtraDeviceCodes("targetDeviceCode"); + if (targetDeviceCode != null && targetDeviceCode.contains(next_device_code)) { int nextAddress = Optional.ofNullable(nextDevice.getExtraValue().get("address")).map(Object::toString).map(Integer::parseInt).orElse(0); this.writing(Arrays.asList(ItemProtocol.TO_TARGET.getKey(), ItemProtocol.TO_TASK.getKey(), ItemProtocol.TO_COMMAND.getKey()), Arrays.asList(nextAddress, instDto.getInstruction_code(), CommandEnum.COMMAND_1.getValue())); } @@ -386,8 +444,9 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc } else if (ObjectUtil.isEmpty(taskDto) && ObjectUtil.isNotEmpty(instDto)) { String next_device_code = instDto.getNext_device_code(); Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); - if (nextDevice != null && StrUtil.equals(nextDevice.getDevice_type(), "conveyor")) { - if (StrUtil.equals(this.getDevice().getRegion(), nextDevice.getRegion())) { + if (nextDevice != null && nextDevice.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { + List targetDeviceCode = this.getExtraDeviceCodes("targetDeviceCode"); + if (targetDeviceCode != null && targetDeviceCode.contains(next_device_code)) { Integer address = Optional.ofNullable(nextDevice.getExtraValue().get("address")).map(Object::toString).map(Integer::parseInt).orElse(0); this.writing(Arrays.asList(ItemProtocol.TO_TASK.getKey(), ItemProtocol.TO_TARGET.getKey(), ItemProtocol.TO_COMMAND.getKey()), Arrays.asList(instDto.getInstruction_code(), address, CommandEnum.COMMAND_1.getValue())); this.requireSuccess = true; @@ -441,23 +500,25 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc Device device = deviceAppService.findDeviceByCode(next_device_code); if (device != null) { String pinkDeviceCode = Optional.ofNullable(device.getExtraValue().get("pinkDeviceCode")).map(Objects::toString).orElse(""); - Device pinkDevice = deviceAppService.findDeviceByCode(pinkDeviceCode); - if (pinkDevice != null && pinkDevice.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { - AppearanceInspectionScannerConveyorDeviceDriver appearanceInspectionScannerConveyorDeviceDriver = (AppearanceInspectionScannerConveyorDeviceDriver) pinkDevice.getDeviceDriver(); - if (appearanceInspectionScannerConveyorDeviceDriver.getMode() == 0) { - return; - } - Instruction inst = instructionService.findReadyInstByEnd(next_device_code); - if (ObjectUtil.isNotEmpty(inst)) { - String pinkDeviceCode2 = Optional.ofNullable(pinkDevice.getExtraValue().get("pinkDeviceCode")).map(Object::toString).orElse(""); - Device pinkDevice2 = deviceAppService.findDeviceByCode(pinkDeviceCode2); - if (pinkDevice2 != null && pinkDevice2.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { - AppearanceInspectionScannerConveyorDeviceDriver appearanceInspectionScannerConveyorDeviceDriver2 = (AppearanceInspectionScannerConveyorDeviceDriver) pinkDevice2.getDeviceDriver(); - if (appearanceInspectionScannerConveyorDeviceDriver2.getMode() == 0) { - String getLinkDeviceCode = Optional.ofNullable(device.getExtraValue().get("getLinkDeviceCode")).map(Objects::toString).orElse(""); - Instruction instruction = instructionService.findReadyInstByEnd(getLinkDeviceCode); - if (StrUtil.isNotEmpty(getLinkDeviceCode) && ObjectUtil.isEmpty(instruction)) { - next_device_code = getLinkDeviceCode; + if (StrUtil.equals(taskDto.getNext_device_code(), pinkDeviceCode)) { + Device pinkDevice = deviceAppService.findDeviceByCode(pinkDeviceCode); + if (pinkDevice != null && pinkDevice.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { + AppearanceInspectionScannerConveyorDeviceDriver appearanceInspectionScannerConveyorDeviceDriver = (AppearanceInspectionScannerConveyorDeviceDriver) pinkDevice.getDeviceDriver(); + if (appearanceInspectionScannerConveyorDeviceDriver.getMode() == 0) { + return; + } + Instruction inst = instructionService.findReadyInstByEnd(next_device_code); + if (ObjectUtil.isNotEmpty(inst)) { + String pinkDeviceCode2 = Optional.ofNullable(pinkDevice.getExtraValue().get("pinkDeviceCode")).map(Object::toString).orElse(""); + Device pinkDevice2 = deviceAppService.findDeviceByCode(pinkDeviceCode2); + if (pinkDevice2 != null && pinkDevice2.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { + AppearanceInspectionScannerConveyorDeviceDriver appearanceInspectionScannerConveyorDeviceDriver2 = (AppearanceInspectionScannerConveyorDeviceDriver) pinkDevice2.getDeviceDriver(); + if (appearanceInspectionScannerConveyorDeviceDriver2.getMode() == 0) { + String getLinkDeviceCode = Optional.ofNullable(device.getExtraValue().get("getLinkDeviceCode")).map(Objects::toString).orElse(""); + Instruction instruction = instructionService.findReadyInstByEnd(getLinkDeviceCode); + if (StrUtil.isNotEmpty(getLinkDeviceCode) && ObjectUtil.isEmpty(instruction)) { + next_device_code = getLinkDeviceCode; + } } } } @@ -469,12 +530,45 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc } else { start_point_code = start_device_code; } - setInstruction(instDto, taskDto, start_device_code, start_point_code, next_device_code, next_device_code); Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); if (nextDevice == null) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "创建指令失败, 未配置指令终点驱动信息, 终点: " + instDto.getNext_device_code())); + logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "创建指令失败, 未配置指令终点驱动信息, 终点: " + next_device_code)); return; } + //判断终点是否是双向点位 + boolean toWayFlag = Optional.ofNullable(cacheDevice.getExtraValue().get("toWay")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); + //如果是双向点位 + if (toWayFlag) { + //获取终点所属输送线 + String belongToConveyor = Optional.ofNullable(cacheDevice.getExtraValue().get("belongToConveyor")).map(Object::toString).orElse(null); + if (belongToConveyor != null) { + Device belongToConveyorDevice = deviceAppService.findDeviceByCode(belongToConveyor); + if (belongToConveyorDevice != null && belongToConveyorDevice.getDeviceDriver() instanceof StripConveyorDeviceDriver) { + StripConveyorDeviceDriver stripConveyorDeviceDriver = (StripConveyorDeviceDriver) belongToConveyorDevice.getDeviceDriver(); + //判断所属输送线是否是出库模式 + if (stripConveyorDeviceDriver.getInOutMode() != 1) { + String samePoint = Optional.ofNullable(this.getExtraValue().get("samePoint")).map(Object::toString).orElse(null); + TaskDto existTask; + if (StrUtil.isNotEmpty(samePoint)) { + existTask = taskService.findByStartCode(samePoint); + } else { + existTask = taskService.findByStartCode(this.currentDeviceCode); + } + if (ObjectUtil.isNotEmpty(existTask)) { + return; + } + //不是出库模式 判断是否允许切换出入库模式 + if (stripConveyorDeviceDriver.getSwitchInOut() == 0) { + stripConveyorDeviceDriver.writing("toCommand", 1); + return; + } else { + return; + } + } + } + } + } + setInstruction(instDto, taskDto, start_device_code, start_point_code, next_device_code, next_device_code); try { instructionService.create(instDto); taskDto.setTask_status(TaskStatusEnum.BUSY.getIndex()); @@ -507,7 +601,8 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc String next_device_code = inst.getNext_device_code(); Device next_device = deviceAppService.findDeviceByCode(next_device_code); if (next_device != null && next_device.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { - if (StrUtil.equals(this.getDevice().getRegion(), next_device.getRegion())) { + List targetDeviceCode = this.getExtraDeviceCodes("targetDeviceCode"); + if (targetDeviceCode != null && targetDeviceCode.contains(next_device_code)) { Integer address = Optional.ofNullable(next_device.getExtraValue().get("address")).map(Object::toString).map(Integer::parseInt).orElse(0); this.writing(Arrays.asList(ItemProtocol.TO_COMMAND.getKey(), ItemProtocol.TO_TASK.getKey(), ItemProtocol.TO_TARGET.getKey()), Arrays.asList(CommandEnum.COMMAND_1.getValue(), inst.getInstruction_code(), address)); this.requireSuccess = true; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/ItemProtocol.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/ItemProtocol.java index ab4c064..845ff0f 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/ItemProtocol.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/ItemProtocol.java @@ -8,21 +8,19 @@ import java.util.List; import java.util.ArrayList; public enum ItemProtocol implements DeviceDriverBaseReader.KeyProvider { - HEARTBEAT("heartbeat", "心跳", "DB600.B0"), - MODE("mode", "工作模式", "DB600.B1"), - MOVE("move", "光电信号", "DB600.B2"), - ACTION("action", "动作信号", "DB600.B3"), - ERROR("error", "报警信号", "DB600.B5"), - TASK("task", "任务号", "DB600.D6"), - CONTAINER_TYPE("containerType", "托盘类型", "DB600.B7"), - CONTAINER_DIRECTION("containerDirection", "托盘方向", "DB600.B8"), - HEIGHT("height", "高度", "DB600.B9"), - WEIGHT("weight", "重量", "DB600.D10"), - BARCODE("barcode", "托盘条码", "DB600.STRING1.50"), - TO_COMMAND("toCommand", "下发命令", "DB610.W0"), - TO_TARGET("toTarget", "下发目标站", "DB610.W4"), - TO_TASK("toTask", "下发任务号", "DB610.D6"), - TO_CONTAINER_TYPE("toContainerType", "下发托盘类型", "DB610.W8"); + HEARTBEAT("heartbeat", "心跳", "DB1000.B0"), + MODE("mode", "工作模式", "DB1101.B0"), + MOVE("move", "光电信号", "DB1101.B1"), + ACTION("action", "动作信号", "DB1101.B2"), + ERROR("error", "报警信号", "DB1101.B3"), + BARCODE("barcode", "托盘条码", "DB1101.STRING6"), + WEIGHT("weight", "重量", "DB1101.D262"), + HEIGHT("height", "高度", "DB1101.B266"), + TASK("task", "任务号", "DB1101.D268"), + TO_COMMAND("toCommand", "下发命令", "DB1101.W272"), + TO_TARGET("toTarget", "下发目标站", "DB1101.W274"), + TO_TASK("toTask", "下发任务号", "DB1101.D278"), + TO_HEIGHT("toHeight", "下发高度", "DB1101.W280"); private final String key; private final String description;