From 15ae1507d1aa38e28bc4373ee1449d1f27d569ee Mon Sep 17 00:00:00 2001 From: lishuai <1793460677@qq.com> Date: Wed, 6 Dec 2023 15:55:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?add:=20=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/device_driver/DriverTypeEnum.java | 4 +- .../WithStationDefination.java | 53 ++ .../WithStationDeviceDriver.java | 281 ++++++++ .../DoubleBeltConveyorDefination.java | 61 ++ .../DoubleBeltConveyorDeviceDriver.java | 647 ++++++++++++++++++ .../double_belt_conveyor/ItemProtocol.java | 181 +++++ .../double_belt_conveyor/Paper.java | 19 + .../device/driver/double_station_stacker.vue | 17 + 8 files changed, 1262 insertions(+), 1 deletion(-) create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDefination.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDeviceDriver.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDefination.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDeviceDriver.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/ItemProtocol.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/Paper.java diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index 0b87c2a..24175d4 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -39,7 +39,9 @@ public enum DriverTypeEnum { LED_SCREEN(15, "led_screen", "LED点阵屏", "screen"), - DOUBLE_STATION_STACKER(16, "double_station_stacker", "标准版-双工位堆垛机", "double_station_stacker"); + DOUBLE_STATION_STACKER(16, "double_station_stacker", "标准版-双工位堆垛机", "double_station_stacker"), + + DOUBLE_BELT_CONVEYOR(17, "double_belt_conveyor", "双工位输送线虚拟站点", "double_belt_conveyor"); diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDefination.java new file mode 100644 index 0000000..d751e39 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDefination.java @@ -0,0 +1,53 @@ +package org.nl.acs.device_driver.basedriver.belt_with_station; + +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.enums.DeviceType; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.DeviceDriverDefination; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 说明:关联站点驱动 + */ +@Service +public class WithStationDefination implements DeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_with_station"; + } + + @Override + public String getDriverName() { + return "关联驱动"; + } + + @Override + public String getDriverDescription() { + return "关联驱动"; + } + + + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new WithStationDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return WithStationDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDeviceDriver.java new file mode 100644 index 0000000..8f3f61c --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDeviceDriver.java @@ -0,0 +1,281 @@ +package org.nl.acs.device_driver.basedriver.belt_with_station; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.basedriver.belt_conveyor.BeltConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.double_belt_conveyor.DoubleBeltConveyorDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.domain.Instruction; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.config.SpringContextHolder; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * 关联驱动 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class WithStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskServer = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); + @Autowired + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); + + + Integer hasGoods = 0; + int error = 0; + Boolean iserror = false; + Boolean islock = false; + + int branchProtocol = 0; + int last_branchProtocol = 0; + //是否需要输入物料 + String input_material = "0"; + //备注 + String remark = ""; + //数量 + String qty = ""; + //批次 + String batch = ""; + //物料 + String material = ""; + //目标点位 + String purpose = ""; + + //上次指令 + Instruction last_inst = null; + + boolean requireSucess = false; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + // 1取货完成 2放货完成 3进入区域 4离开区域 + private int flag; + + //人工确认信号 默认0 agv到达后请求置1 等人工确认后变为2 反馈agv后继续为0 + private int manua_confirm = 0; + + String device_code = null; + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out = 30000; + + String message; + + // 1 上位系统允许进入 2 上位系统允许离开 + int option = 0; + + //agv请求当前信息 + private int agvphase = 0; + private int index = 0; + + int mode = 2; + + int move; + + @Override + public void execute() { + + device_code = this.getDeviceCode(); + + + + //取关联设备 list 要求:先配置外侧的站点 + //遍历 + List sddjExtraCodeList = this.getExtraDeviceCodes("link_device_code"); + //只需要判断对接位就可以 + for (int i = 0; i < 1; i++) { + Device sddjExtraCode1 = deviceAppservice.findDeviceByCode(sddjExtraCodeList.get(i)); + Device sddjExtraCode2 = deviceAppservice.findDeviceByCode(sddjExtraCodeList.get(i+1)); + DoubleBeltConveyorDeviceDriver doubleBeltConveyorDeviceDriver1; + DoubleBeltConveyorDeviceDriver doubleBeltConveyorDeviceDriver2; + if (sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver && sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver ) { + doubleBeltConveyorDeviceDriver1 = (DoubleBeltConveyorDeviceDriver) sddjExtraCode1.getDeviceDriver(); + doubleBeltConveyorDeviceDriver2 = (DoubleBeltConveyorDeviceDriver) sddjExtraCode2.getDeviceDriver(); + //判断输送线是否有任务,有任务进行创建指令。 + List taskDtos1 = taskServer.queryTaskByStartDeviceCode(doubleBeltConveyorDeviceDriver1.getDevice_code()); + List taskDtos2 = taskServer.queryTaskByStartDeviceCode(doubleBeltConveyorDeviceDriver2.getDevice_code()); + if (CollectionUtil.isNotEmpty(taskDtos1) && CollectionUtil.isNotEmpty(taskDtos2)) { + if(doubleBeltConveyorDeviceDriver1.getMove() == 0){ + requireSucess =false; + } + if(doubleBeltConveyorDeviceDriver2.getMove() == 0){ + requireSucess =false; + } + //判断关联的输送线是否满足状态 + if (doubleBeltConveyorDeviceDriver1.getMode() == 2 && doubleBeltConveyorDeviceDriver1.getMove() == 1 && !requireSucess &&doubleBeltConveyorDeviceDriver2.getMode() == 2 && doubleBeltConveyorDeviceDriver2.getMove() == 1 + ) { + + + //判断是否超过等待时间 + if (System.currentTimeMillis() - doubleBeltConveyorDeviceDriver1.getInstruction_require_time().getTime() + > Integer.parseInt(this.getExtraValue().get("apply_time").toString()) * 1000) { + //否则对接位单独申请任务 + JSONObject reqParam = new JSONObject(); + reqParam.put("type", StatusEnum.HAIROU_LIKU_REQ.getCode()); + reqParam.put("device_code_one", hailiangHrSsxDeviceDriver.getDevice_code()); + reqParam.put("vehicle_code_one", hailiangHrSsxDeviceDriver.getBarcode()); + log.info("单工位请求成功"); + requireSucess = true; + + } else { + //否则判断另一个位置 + Device neiRouDevice = deviceAppservice.findDeviceByCode(haiRouDeviceCodeList.get(i+1)); + if (neiRouDevice.getDeviceDriver() instanceof HailiangHrSsxDeviceDriver) { + hailiangHrSsxDeviceDriver2 = (HailiangHrSsxDeviceDriver) neiRouDevice.getDeviceDriver(); + if (hailiangHrSsxDeviceDriver2.getMode() == 2 && + hailiangHrSsxDeviceDriver2.getMove() == 1 && + ObjectUtil.isNotEmpty(hailiangHrSsxDeviceDriver2.getBarcode()) + ) { + JSONObject reqParam = new JSONObject(); + //半成品库任务 + reqParam.put("type", StatusEnum.HAIROU_LIKU_REQ.getCode()); + //具体海柔出入库任务类型 + reqParam.put("item_type", DeviceEnum.getTypeByCode(hailiangHrSsxDeviceDriver.getDevice_code())); + reqParam.put("device_code_one", hailiangHrSsxDeviceDriver.getDevice_code()); + reqParam.put("vehicle_code_one", hailiangHrSsxDeviceDriver.getBarcode()); + reqParam.put("device_code_two", hailiangHrSsxDeviceDriver2.getDevice_code()); + reqParam.put("vehicle_code_two", hailiangHrSsxDeviceDriver2.getBarcode()); + //向lms请求任务 + // 联调时加上 +// HttpResponse httpResponse = acsToWmsService.applyTaskToWms(reqParam); +// if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) { +// requireSucess = true; +// } + log.info("双工位请求成功"); + requireSucess = true; + } + } + } + + } else { + //todo 输出不满足的原因 + + } + } + } + } + + + } + + //将扩展表中的字符串数据转换成集合 + @Override + public List getExtraDeviceCodes(String extraName) { + String extraValue = (String) this.getDevice().getExtraValue().get(extraName); + String devices1 = extraValue.substring(1, extraValue.length() - 1); + List devicesList = new ArrayList<>(); + String[] devices = devices1.split(","); + for (int i = 0; i < devices.length; i++) { + String s = devices[i].replace("\"", "").replace("\"", ""); + devicesList.add(s); + } + return devicesList; + } + + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + String mode = ""; + String action = ""; + String move = ""; + String option = ""; + if (this.getOption() == 0) { + option = "禁止进出"; + } else if (this.getOption() == 1) { + option = "允许进入"; + } else if (this.getOption() == 2) { + option = "允许离开"; + } + + if (this.getMode() == 0) { + mode = "未联机"; + } else if (this.getMode() == 1) { + mode = "单机"; + } else if (this.getMode() == 2) { + mode = "联机"; + } else if (this.getMode() == 3) { + mode = "运行中"; + } + + if (this.getMove() == 0) { + move = "无货"; + jo.put("hasGoods", false); + } else if (this.getMove() == 1) { + move = "有货"; + jo.put("hasGoods", true); + } else if (this.getMove() == 2) { + move = "有托盘有货"; + jo.put("hasGoods", true); + } + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("mode", mode); + jo.put("move", move); + jo.put("action", action); + jo.put("isOnline", true); + jo.put("error", this.getError()); + jo.put("isError", this.getIserror()); + jo.put("option", option); + jo.put("is_click", true); + return jo; + } + + + @Override + public void setDeviceStatus(JSONObject data) { + String flag = data.getString("option"); + if (StrUtil.isNotEmpty(flag)) { + option = Integer.parseInt(flag); + } + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDefination.java new file mode 100644 index 0000000..8776feb --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.double_belt_conveyor; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.enums.DeviceType; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 标准版-输送机 + */ +@Service +public class DoubleBeltConveyorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "belt_conveyor"; + } + + @Override + public String getDriverName() { + return "标准版-输送机"; + } + + @Override + public String getDriverDescription() { + return "标准版-输送机"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new DoubleBeltConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return DoubleBeltConveyorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDeviceDriver.java new file mode 100644 index 0000000..af813d8 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDeviceDriver.java @@ -0,0 +1,647 @@ +package org.nl.acs.device_driver.basedriver.double_belt_conveyor; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.domain.Instruction; +import org.nl.acs.instruction.enums.InstructionStatusEnum; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.config.SpringContextHolder; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +import static redis.clients.jedis.HostAndPort.localhost; + +/** + * 输送线 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class DoubleBeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); + AgvService agvService = SpringContextHolder.getBean(AgvService.class); + + private Date instruction_update_time = new Date(); + private Date require_apply_strangulation_time = new Date(); + private int instruction_update_time_out = 500; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + + //心跳 + int heartbeat = 0; + int last_heartbeat = 0; + //工作模式 + int mode = 0; + int last_mode = 0; + //光电信号 + int move = 0; + int last_move = 0; + //托盘方向 + int container_direction = 0; + int last_container_direction = 0; + //报警 + int error = 0; + int last_error = 0; + //动作信号 + int action = 0; + int last_action = 0; + //任务号 + int task = 0; + int last_task = 0; + //托盘类型 + int container_type = 0; + int last_container_type = 0; + //纯数字托盘号 + int container_no = 0; + int last_container_no = 0; + + int inventory_qty = 0; + int out_finish = 0; + //下发命令 + int to_command = 0; + int last_to_command = 0; + //下发目标站 + int to_target = 0; + int last_to_target = 0; + //下发任务号 + int to_task = 0; + int last_to_task = 0; + //下发接纯数字托盘号 + int to_container_no = 0; + int last_to_container_no = 0; + //下发托盘类型 + int to_container_type = 0; + int last_to_container_type = 0; + + + + + //当前指令 + Instruction inst = null; + + String material = null; + + Boolean isonline = true; + + Boolean iserror = false; + + //1-执行任务;2-取货完成;3-放货完成; + int flag; + + + int last_inventory_qty = 0; + int last_out_finish = 0; + + String last_material = null; + String message = null; + String device_code; + String task_code = null; + String vehicle_code; + String inst_message; + + //led点阵屏信息 + JSONObject led_message = null; + + + @Override + public Device getDevice() { + return this.device; + } + + //请求成功标记 + Boolean requireSucess = false; + + @Override + public void execute() { + try { + device_code = this.getDeviceCode(); + heartbeat = this.itemProtocol.getHeartbeat(); + mode = this.itemProtocol.getMode(); + move = this.itemProtocol.getMove(); + action = this.itemProtocol.getAction(); + container_direction = this.itemProtocol.getContainer_direction(); + container_type = this.itemProtocol.getContainer_type(); + error = this.itemProtocol.getError(); + task = this.itemProtocol.getTask(); + container_no = this.itemProtocol.getContainer_no(); + to_command = this.itemProtocol.getTo_command(); + to_target = this.itemProtocol.getTotarget(); + to_task = this.itemProtocol.getTo_task(); + to_container_no = this.itemProtocol.getContainer_direction(); + to_container_type = this.itemProtocol.getContainer_no(); + + if (mode != last_mode) { + JSONObject param = new JSONObject(); + param.put("device_code", this.device_code); + param.put("mode", Math.min(mode, 3)); + param.put("device_name", this.getDevice().getDevice_name()); + param.put("device_type", "1"); + requireSucess = false; + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode + "复位请求标记:" + requireSucess); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); + } + if (container_direction != last_container_direction) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(container_direction)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号container_direction:" + last_container_direction + "->" + container_direction); + } + if (container_type != last_container_type) { + logServer.deviceItemValue(this.device_code, "container_type", String.valueOf(container_type)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号container_type:" + last_container_type + "->" + container_type); + } + if (container_no != last_container_no) { + logServer.deviceItemValue(this.device_code, "container_no", String.valueOf(container_no)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号container_no:" + last_container_no + "->" + container_no); + } + if (action != last_action) { + logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); + } + if (to_command != last_to_command) { + logServer.deviceItemValue(this.device_code, "to_command", String.valueOf(to_command)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); + } + if (to_target != last_to_target) { + logServer.deviceItemValue(this.device_code, "to_target", String.valueOf(to_target)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); + } + if (to_task != last_to_task) { + logServer.deviceItemValue(this.device_code, "to_task", String.valueOf(to_task)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); + } + if (to_container_no != last_to_container_no) { + logServer.deviceItemValue(this.device_code, "to_container_no", String.valueOf(to_container_no)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_container_no:" + last_to_container_no + "->" + to_container_no); + } + if (to_container_type != last_to_container_type) { + logServer.deviceItemValue(this.device_code, "to_container_type", String.valueOf(to_container_type)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_container_type:" + last_to_container_type + "->" + to_container_type); + } + if (error != last_error) { + if (error != 0) { + + } + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); + } + + + if (move != 0 && task > 0) { + update_instruction_status(); + } + + } catch (Exception var17) { + var17.printStackTrace(); + logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol)); + } + + + if (mode == 0) { + this.setIsonline(false); + message = "未联机"; + } else if (error != 0) { + this.setIserror(true); + message = "有报警"; + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + + //纸管库申请任务 + switch (mode) { + case 1: + log.debug("弃用(留作兼容)"); + break; + case 2: + //申请任务 + if (move == 1 && !requireSucess) { + instruction_require(); + } + break; + case 3: + log.info("运行中"); + break; + case 4: + //申请出货 + if (move == 1 && !requireSucess) { + //request_for_shipment(String.valueOf(mode), item_out_seq_arr, item_out_qty_arr); + } + break; + default: + break; + } + } + last_heartbeat = heartbeat; + last_mode = mode; + last_move = move; + last_error = error; + last_container_direction = container_direction; + last_container_no = container_no; + last_container_type = container_type; + last_action = action; + last_task = task; + last_to_command = to_command; + last_to_target = to_target; + last_to_task = to_task; + last_to_container_no = to_container_no; + last_to_container_type = to_container_type; + + } + + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + + Map itemMap = new HashMap(); + this.control(itemMap); + } + + + public void writing(Map map) { + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + Map itemMap = new LinkedHashMap<>(); + map.forEach((key, value) -> { + if (ObjectUtil.isNotEmpty(value)) { + itemMap.put(getToParam() + key, value); + } + }); + if (ObjectUtil.isNotEmpty(itemMap)) { + this.control(itemMap); + logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); + } + } + + + /*public synchronized void request_for_shipment(String mode, String item_out_seq_arr, int[] item_out_qty_arr) { + Date date = new Date(); + if (date.getTime() - this.require_apply_strangulation_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + } else { + this.require_apply_strangulation_time = date; + ApplyPaperActionRequest applyPaperActionRequest = new ApplyPaperActionRequest(); + applyPaperActionRequest.setDevice_code(this.device_code); + applyPaperActionRequest.setType("1"); + applyPaperActionRequest.setTask_code(String.valueOf(task)); + //获取出库顺序 + boolean contains = item_out_seq_arr.contains(","); + boolean contains1 = item_out_seq_arr.contains(","); + + if (contains) { + String[] split = item_out_seq_arr.split(","); + applyPaperActionRequest.setMaterial1(split[0]); + applyPaperActionRequest.setMaterial1(split[1]); + } else if (contains1) { + String[] split = item_out_seq_arr.split(","); + applyPaperActionRequest.setMaterial1(split[0]); + applyPaperActionRequest.setMaterial1(split[1]); + } else { + applyPaperActionRequest.setMaterial1(item_out_seq_arr); + } + if (item_out_qty_arr.length >= 1 && item_out_qty_arr.length < 4) { + applyPaperActionRequest.setQty1(String.valueOf(item_out_qty_arr[0])); + applyPaperActionRequest.setQty2(String.valueOf(item_out_qty_arr[1])); + } + ApplyPaperActionResponse applyPaperActionResponse = acsToWmsService.applyPaperActionRequest(applyPaperActionRequest); + if (ObjectUtil.isNull(applyPaperActionResponse)) { + message = "请求失败"; + requireSucess = false; + return; + } + Map map3 = new HashMap(); + if (applyPaperActionResponse.getstatus() == 200) { + map3.put("to_command", "4"); + this.writing(map3); + requireSucess = true; + logServer.deviceExecuteLog(this.device_code, "", "", "申请出纸管,返回参数:" + applyPaperActionResponse); + message = "申请出货成功"; + } else { + message = applyPaperActionResponse.getMessage(); + map3.put("to_command", "5"); + this.writing(map3); + requireSucess = false; + message = "出库顺序错误"; + logServer.deviceExecuteLog(this.device_code, "", "", "申请出纸管,返回参数:" + applyPaperActionResponse); + } + } + } +*/ + + /** + * 申请任务 + */ + public synchronized Boolean instruction_require() { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + //查找有没有对应的指令 + Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code); + if (ObjectUtil.isNotNull(inst) && "1".equals(inst.getInstruction_type())) { + Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code()); + String next_addr = nextdevice.getExtraValue().get("address").toString(); + TaskDto taskDto = taskserver.findByCodeFromCache(inst.getTask_code()); + //List paperArray = getPaperArray(null); + if (ObjectUtil.isEmpty(inst)) { + return false; + } + Map map = new HashMap(); + map.put("to_target", next_addr); + map.put("to_task", inst.getInstruction_code()); + map.put("to_command", "1"); + map.put("to_container_type", "1"); + map.put("to_container_no", "1"); + this.writing(map); + led_message = getLedMessage(inst); + requireSucess = true; + return true; + } else { + //判断是否有相同起点的,任务状态就绪的任务 + TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code); + if (ObjectUtil.isNull(taskdto)) { + return false; + } + if (ObjectUtil.isNotNull(taskdto) && "1".equals(taskdto.getTask_type())) { + //判断指令的起点和当前的设备号相同 + if (!taskdto.getStart_device_code().equals(device_code)) { + return false; + } + //判断当前任务号是否存在指令 + String taskid = taskdto.getTask_id(); + String taskcode = taskdto.getTask_code(); + String priority = taskdto.getPriority(); + String start_point_code = taskdto.getStart_point_code(); + String start_device_code = taskdto.getStart_device_code(); + String route_plan_code = taskdto.getRoute_plan_code(); + String next_device_code = ""; + /** + * 开始平均分配 + */ + String this_coevice_code = taskserver.queryAssignedByDevice(device_code, taskdto.getNext_device_code()); + if (StrUtil.isEmpty(this_coevice_code)) { + List shortPathsList = routeLineService.getShortPathLines(start_device_code, taskdto.getNext_device_code(), route_plan_code); + RouteLineDto routeLineDto = shortPathsList.get(0); + + String path = routeLineDto.getPath(); + String type = routeLineDto.getType(); + String[] str = path.split("->"); + + List pathlist = Arrays.asList(str); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(start_device_code)) { + index = m + 1; + break; + } + } + next_device_code = pathlist.get(index); + } else { + next_device_code = this_coevice_code; + } + //校验路由关系 + List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + if (ObjectUtils.isEmpty(shortPathsList) || shortPathsList.size()<1) { + throw new RuntimeException("路由不通!"); + } + Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); + Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); + String next_point_code; + if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = taskdto.getTo_x() + "-" + taskdto.getTo_y() + "-" + taskdto.getTo_z(); + } else { + next_point_code = next_device_code; + } + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(taskdto.getRemark()); + instdto.setMaterial(taskdto.getMaterial()); + instdto.setQuantity(taskdto.getQuantity()); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setPriority(priority); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(start_point_code); + log.error("=================================,{}",instdto.getCreate_by()); + try { + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("指令创建失败!", e.getMessage()); + return false; + } + taskdto.setTask_status("1"); + taskserver.update(taskdto); + requireSucess = true; + Map map = new HashMap(); + String next_addr = nextdevice.getExtraValue().get("address").toString(); + map.put("to_target", next_addr); + map.put("to_task", instdto.getInstruction_code()); + map.put("to_command", "1"); + map.put("to_container_type", "1"); + map.put("to_container_no", "1"); + this.writing(map); + led_message = getLedMessage(instdto); + requireSucess = true; + return true; + } + } + return false; + } + } + + public void writeData(String next_addr, Instruction instdto, Map map) { + + } + + public String getToParam() { + return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; + } + + + + public void writing(String key, String param) { + + String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + param; + //String opcservcerid = this.getDevice().getOpc_server_id(); + //Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + + itemMap.put(to_param, Integer.parseInt(param)); + //itemMap.put(to_param, Integer.parseInt(value)); + this.control(itemMap); + logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + param); + } + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + String mode = ""; + + if (this.getMode() == 0) { + mode = "未联机"; + } else if (this.getMode() == 1) { + mode = "单机"; + } else if (this.getMode() == 2) { + mode = "联机"; + } else if (this.getMode() == 3) { + mode = "入库中"; + } else if (this.getMode() == 4) { + mode = "出库中"; + } + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("mode", mode); + //jo.put("error", ErrorUtil.getDictDetail("ssx_error_type", String.valueOf(this.getError()))); + jo.put("inventory_qty", inventory_qty); + jo.put("out_finish", out_finish); + jo.put("material", material); + jo.put("isOnline", this.getIsonline()); + + return jo; + } + + /** + * 获取任务信息 + */ + public JSONObject getLedMessage(Instruction instdto){ + JSONObject json = new JSONObject(); + json.put("task_code", instdto.getTask_code()); + json.put("inst_code", instdto.getInstruction_code()); + json.put("start_device_code", instdto.getStart_device_code()); + json.put("next_device_code", instdto.getNext_device_code()); + json.put("material_type", instdto.getMaterial()); + json.put("quantity", instdto.getQuantity()); + json.put("vehicle_code", instdto.getVehicle_code()); + json.put("instruction_status",instdto.getInstruction_status()); + json.put("entry_time", instdto.getCreate_time()); + json.put("ip", localhost); + return json; + } + + + + /** + * 更新指令状态 + */ + public synchronized void update_instruction_status() throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); + } else { + this.instruction_update_time = date; + inst = checkInst(); + if (inst != null) { + //a点到b点,给状态说允许取货 + if (StrUtil.equals(inst.getInstruction_status(), InstructionStatusEnum.READY.getIndex()) && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { + inst.setInstruction_status(InstructionStatusEnum.BUSY.getIndex()); + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task); + } + //当货物到达b点,实现完成指令 + if (StrUtil.equals(inst.getInstruction_status(), InstructionStatusEnum.BUSY.getIndex()) || StrUtil.equals(inst.getInstruction_status(), InstructionStatusEnum.READY.getIndex())) { + if (StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { + inst.setExecute_device_code(this.device_code); + finish_instruction(); + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task); + } + } + + } + } + } + + public Instruction checkInst() { + if (ObjectUtil.isNotEmpty(this.inst)) { + if (this.task > 0) { + if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) { + return this.inst; + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + } + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + return null; + } + + + @Override + public void setDeviceStatus(JSONObject data) { + + } + + public static boolean arrayEquals(int[] a, int[] b) { + // 判断两个数组长度是否相等 + if (a.length != b.length) { + return false; + } + // 判断两个数组对应位置上的元素是否相同 + for (int i = 0; i < a.length; i++) { + if (a[i] != b[i]) { + return false; + } + } + return true; + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/ItemProtocol.java new file mode 100644 index 0000000..9faeed6 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/ItemProtocol.java @@ -0,0 +1,181 @@ +package org.nl.acs.device_driver.basedriver.double_belt_conveyor; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + //心跳 + public static String item_heartbeat = "heartbeat"; + //工作模式 + public static String item_mode = "mode"; + //光电信号 + public static String item_move = "move"; + //动作信号 + public static String item_action = "action"; + //报警 + public static String item_error = "error"; + //托盘方向 + public static String item_container_direction = "container_direction"; + //托盘类型 + public static String item_container_type = "container_type"; + //任务号 + public static String item_task = "task"; + //出数字托盘号 + public static String item_container_no = "container_no"; + + //下发命令 + public static String item_to_command = "to_command"; + //下发托盘类型 + public static String item_to_container_type = "to_container_type"; + //下发接纯数字托盘号 + public static String item_to_container_no = "to_container_no"; + //下发任务号 + public static String item_to_task = "to_task"; + //下发目标站 + public static String item_to_target = "to_target"; + + + + private DoubleBeltConveyorDeviceDriver driver; + + public ItemProtocol(DoubleBeltConveyorDeviceDriver driver) { + this.driver = driver; + } + + + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getContainer_direction() { + return this.getOpcIntegerValue(item_container_direction); + } + + public int getContainer_type() { + return this.getOpcIntegerValue(item_container_type); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getContainer_no() { + return this.getOpcIntegerValue(item_container_no); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + public int getTo_task() { + return this.getOpcIntegerValue(item_to_task); + } + + + public int getTotarget() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_container_type() { + return this.getOpcIntegerValue(item_to_container_type); + } + + public int getTo_container_no() { + return this.getOpcIntegerValue(item_to_container_no); + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + + public String getOpcStringValue(String protocol) { + String value = this.driver.getStringValue(protocol); + if (StrUtil.isBlank(value)) { + + } else { + return value; + } + return "0"; + } + + public int[] getOpcArrayValue(String protocol) { + int[] arrayValue = this.driver.getIntegeregerArrayValue(protocol); + if (ObjectUtil.isNull(arrayValue)) { + + } else { + return arrayValue; + } + return new int[3]; + } + + + + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB101.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB101.B2")); + list.add(new ItemDto(item_move, "光电信号", "DB101.B3")); + list.add(new ItemDto(item_container_direction, "托盘方向", "DB101.B4")); + list.add(new ItemDto(item_container_type, "托盘类型", "DB101.B5")); + list.add(new ItemDto(item_container_no, "纯数字托盘号", "DB101.D7")); + list.add(new ItemDto(item_action, "动作类型", "DB101.B6")); + list.add(new ItemDto(item_error, "报警", "DB101.B58")); + list.add(new ItemDto(item_task, "任务号", "DB101.D68")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_target , "下发仓位号", "DB102.W2")); + list.add(new ItemDto(item_to_command, "下发命令", "DB102.W4")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB102.D1")); + list.add(new ItemDto(item_to_container_no, "下发接纯数字托盘号", "DB102.D3")); + list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB102.B5")); + return list; + } + + @Override + public String toString() { + return ""; + } + +} + diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/Paper.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/Paper.java new file mode 100644 index 0000000..f0b530d --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/Paper.java @@ -0,0 +1,19 @@ +package org.nl.acs.device_driver.basedriver.double_belt_conveyor; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Paper implements Serializable { + //设备号 + private String device_code; + // + private String material_code; + private String qty; + +} diff --git a/acs/nladmin-ui/src/views/acs/device/driver/double_station_stacker.vue b/acs/nladmin-ui/src/views/acs/device/driver/double_station_stacker.vue index 0bafa74..053b0d5 100644 --- a/acs/nladmin-ui/src/views/acs/device/driver/double_station_stacker.vue +++ b/acs/nladmin-ui/src/views/acs/device/driver/double_station_stacker.vue @@ -96,6 +96,23 @@ + + + + + + + Date: Thu, 7 Dec 2023 14:29:12 +0800 Subject: [PATCH 2/4] =?UTF-8?q?add:=20=E5=85=B3=E8=81=94=E7=AB=99=E7=82=B9?= =?UTF-8?q?=E5=BC=80=E5=8F=91,=E4=BB=A3=E7=A1=AE=E8=AE=A4=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BeltConveyorDeviceDriver.java | 3 +- .../WithStationDeviceDriver.java | 226 +++++++++++++----- .../DoubleBeltConveyorDeviceDriver.java | 8 - .../service/impl/InstructionServiceImpl.java | 1 - 4 files changed, 167 insertions(+), 71 deletions(-) diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDeviceDriver.java index dec70e1..2533ec1 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDeviceDriver.java @@ -381,7 +381,8 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements /** * 申请任务 */ - public synchronized Boolean instruction_require() { + public synchronized Boolean + instruction_require() { Date date = new Date(); if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDeviceDriver.java index 8f3f61c..c2fc855 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_with_station/WithStationDeviceDriver.java @@ -1,12 +1,15 @@ package org.nl.acs.device_driver.basedriver.belt_with_station; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; import org.nl.acs.agv.server.NDCAgvService; import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; import org.nl.acs.device.domain.Device; @@ -25,14 +28,13 @@ import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.monitor.DeviceStageMonitor; import org.nl.acs.opc.DeviceAppService; import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; import org.nl.config.SpringContextHolder; import org.springframework.beans.factory.annotation.Autowired; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; /** * 关联驱动 @@ -129,86 +131,188 @@ public class WithStationDeviceDriver extends AbstractOpcDeviceDriver implements device_code = this.getDeviceCode(); - //取关联设备 list 要求:先配置外侧的站点 //遍历 List sddjExtraCodeList = this.getExtraDeviceCodes("link_device_code"); //只需要判断对接位就可以 for (int i = 0; i < 1; i++) { Device sddjExtraCode1 = deviceAppservice.findDeviceByCode(sddjExtraCodeList.get(i)); - Device sddjExtraCode2 = deviceAppservice.findDeviceByCode(sddjExtraCodeList.get(i+1)); + Device sddjExtraCode2 = deviceAppservice.findDeviceByCode(sddjExtraCodeList.get(i + 1)); DoubleBeltConveyorDeviceDriver doubleBeltConveyorDeviceDriver1; DoubleBeltConveyorDeviceDriver doubleBeltConveyorDeviceDriver2; - if (sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver && sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver ) { + if (sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver && sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver) { doubleBeltConveyorDeviceDriver1 = (DoubleBeltConveyorDeviceDriver) sddjExtraCode1.getDeviceDriver(); doubleBeltConveyorDeviceDriver2 = (DoubleBeltConveyorDeviceDriver) sddjExtraCode2.getDeviceDriver(); //判断输送线是否有任务,有任务进行创建指令。 - List taskDtos1 = taskServer.queryTaskByStartDeviceCode(doubleBeltConveyorDeviceDriver1.getDevice_code()); - List taskDtos2 = taskServer.queryTaskByStartDeviceCode(doubleBeltConveyorDeviceDriver2.getDevice_code()); - if (CollectionUtil.isNotEmpty(taskDtos1) && CollectionUtil.isNotEmpty(taskDtos2)) { - if(doubleBeltConveyorDeviceDriver1.getMove() == 0){ - requireSucess =false; + TaskDto taskDtos1 = taskServer.findByStartCodeAndReady(doubleBeltConveyorDeviceDriver1.getDevice_code()); + TaskDto taskDtos2 = taskServer.findByStartCodeAndReady(doubleBeltConveyorDeviceDriver1.getDevice_code()); + if (ObjectUtil.isNotEmpty(taskDtos1) && ObjectUtil.isNotEmpty(taskDtos2)) { + if (doubleBeltConveyorDeviceDriver1.getMove() == 0) { + requireSucess = false; } - if(doubleBeltConveyorDeviceDriver2.getMove() == 0){ - requireSucess =false; + if (doubleBeltConveyorDeviceDriver2.getMove() == 0) { + requireSucess = false; } - //判断关联的输送线是否满足状态 - if (doubleBeltConveyorDeviceDriver1.getMode() == 2 && doubleBeltConveyorDeviceDriver1.getMove() == 1 && !requireSucess &&doubleBeltConveyorDeviceDriver2.getMode() == 2 && doubleBeltConveyorDeviceDriver2.getMove() == 1 - ) { - - - //判断是否超过等待时间 - if (System.currentTimeMillis() - doubleBeltConveyorDeviceDriver1.getInstruction_require_time().getTime() - > Integer.parseInt(this.getExtraValue().get("apply_time").toString()) * 1000) { - //否则对接位单独申请任务 - JSONObject reqParam = new JSONObject(); - reqParam.put("type", StatusEnum.HAIROU_LIKU_REQ.getCode()); - reqParam.put("device_code_one", hailiangHrSsxDeviceDriver.getDevice_code()); - reqParam.put("vehicle_code_one", hailiangHrSsxDeviceDriver.getBarcode()); - log.info("单工位请求成功"); - requireSucess = true; - - } else { - //否则判断另一个位置 - Device neiRouDevice = deviceAppservice.findDeviceByCode(haiRouDeviceCodeList.get(i+1)); - if (neiRouDevice.getDeviceDriver() instanceof HailiangHrSsxDeviceDriver) { - hailiangHrSsxDeviceDriver2 = (HailiangHrSsxDeviceDriver) neiRouDevice.getDeviceDriver(); - if (hailiangHrSsxDeviceDriver2.getMode() == 2 && - hailiangHrSsxDeviceDriver2.getMove() == 1 && - ObjectUtil.isNotEmpty(hailiangHrSsxDeviceDriver2.getBarcode()) - ) { - JSONObject reqParam = new JSONObject(); - //半成品库任务 - reqParam.put("type", StatusEnum.HAIROU_LIKU_REQ.getCode()); - //具体海柔出入库任务类型 - reqParam.put("item_type", DeviceEnum.getTypeByCode(hailiangHrSsxDeviceDriver.getDevice_code())); - reqParam.put("device_code_one", hailiangHrSsxDeviceDriver.getDevice_code()); - reqParam.put("vehicle_code_one", hailiangHrSsxDeviceDriver.getBarcode()); - reqParam.put("device_code_two", hailiangHrSsxDeviceDriver2.getDevice_code()); - reqParam.put("vehicle_code_two", hailiangHrSsxDeviceDriver2.getBarcode()); - //向lms请求任务 - // 联调时加上 -// HttpResponse httpResponse = acsToWmsService.applyTaskToWms(reqParam); -// if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) { -// requireSucess = true; -// } - log.info("双工位请求成功"); - requireSucess = true; - } + //判断任务列是否相邻 + String nextDeviceCode1 = taskDtos1.getNext_device_code(); + String nextDeviceCode2 = taskDtos2.getNext_device_code(); + if (StrUtil.contains(nextDeviceCode1, "-") && StrUtil.contains(nextDeviceCode2, "-")) { + String[] split1 = nextDeviceCode1.split("-"); + String nextPointCodeDown = split1[0] + "-" + (Integer.parseInt(split1[1]) - 1) + "-" + split1[2]; + String nextPointCodeUp = split1[0] + "-" + (Integer.parseInt(split1[1]) + 1) + "-" + split1[2]; + if (!nextDeviceCode2.equals(nextPointCodeDown) || !nextDeviceCode2.equals(nextPointCodeUp)) { + //创建指令 + if (ObjectUtil.isNotNull(taskDtos1) && "1".equals(taskDtos1.getTask_type())) { + creatInstruction(taskDtos1); } } - } else { - //todo 输出不满足的原因 - + requireSucess = false; } + + //判断关联的输送线是否满足状态 + if (doubleBeltConveyorDeviceDriver1.getMode() == 2 && doubleBeltConveyorDeviceDriver1.getMove() == 1 && !requireSucess && doubleBeltConveyorDeviceDriver2.getMode() == 2 && doubleBeltConveyorDeviceDriver2.getMove() == 1) { + //判断是否大于等待时间 + if (System.currentTimeMillis() - doubleBeltConveyorDeviceDriver1.getInstruction_require_time().getTime() + > Integer.parseInt(this.getExtraValue().get("apply_time").toString()) * 1000) { + //创建指令 + if (ObjectUtil.isNotNull(taskDtos1) && "1".equals(taskDtos1.getTask_type())) { + creatInstruction(taskDtos1); + } + } + log.info("单工位请求成功"); + requireSucess = true; + } else { + //创建指令 + if (ObjectUtil.isNotNull(taskDtos1) && "1".equals(taskDtos1.getTask_type())) { + creatInstruction(taskDtos1); + } + if (ObjectUtil.isNotNull(taskDtos2) && "1".equals(taskDtos1.getTask_type())) { + creatInstruction(taskDtos2); + } + log.info("双工位指令创建成功"); + requireSucess = true; + } + } } } - - } + private void creatInstruction(TaskDto taskDtos1) { + + //判断当前任务号是否存在指令 + String taskid = taskDtos1.getTask_id(); + String taskcode = taskDtos1.getTask_code(); + String priority = taskDtos1.getPriority(); + String start_point_code = taskDtos1.getStart_point_code(); + String start_device_code = taskDtos1.getStart_device_code(); + String route_plan_code = taskDtos1.getRoute_plan_code(); + String next_device_code = ""; + /** + * 开始平均分配 + */ + String this_coevice_code = taskServer.queryAssignedByDevice(device_code, taskDtos1.getNext_device_code()); + if (StrUtil.isEmpty(this_coevice_code)) { + List shortPathsList = routeLineService.getShortPathLines(start_device_code, taskDtos1.getNext_device_code(), route_plan_code); + RouteLineDto routeLineDto = shortPathsList.get(0); + + String path = routeLineDto.getPath(); + String type = routeLineDto.getType(); + String[] str = path.split("->"); + + List pathlist = Arrays.asList(str); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(start_device_code)) { + index = m + 1; + break; + } + } + next_device_code = pathlist.get(index); + } else { + next_device_code = this_coevice_code; + } + //校验路由关系 + List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + if (ObjectUtils.isEmpty(shortPathsList) || shortPathsList.size() < 1) { + throw new RuntimeException("路由不通!"); + } + Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); + String next_point_code; + if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = taskDtos1.getTo_x() + "-" + taskDtos1.getTo_y() + "-" + taskDtos1.getTo_z(); + } else { + next_point_code = next_device_code; + } + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(taskDtos1.getRemark()); + instdto.setMaterial(taskDtos1.getMaterial()); + instdto.setQuantity(taskDtos1.getQuantity()); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setPriority(priority); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(start_point_code); + log.error("=================================,{}", instdto.getCreate_by()); + try { + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("指令创建失败!", e.getMessage()); + } + taskDtos1.setTask_status("1"); + taskServer.update(taskDtos1); + requireSucess = true; + Map map = new HashMap(); + String next_addr = nextdevice.getExtraValue().get("address").toString(); + map.put("to_target", next_addr); + map.put("to_task", instdto.getInstruction_code()); + map.put("to_command", "1"); + map.put("to_container_type", "1"); + map.put("to_container_no", "1"); + this.writing(map); + requireSucess = true; + } + + + public void writing(Map map) { + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + Map itemMap = new LinkedHashMap<>(); + map.forEach((key, value) -> { + if (ObjectUtil.isNotEmpty(value)) { + itemMap.put(getToParam() + key, value); + } + }); + if (ObjectUtil.isNotEmpty(itemMap)) { + try { + this.checkcontrol(itemMap); + } catch (Exception e) { + e.printStackTrace(); + try { + this.checkcontrol(itemMap); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); + } + } + + public String getToParam() { + return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; + } + + //将扩展表中的字符串数据转换成集合 @Override public List getExtraDeviceCodes(String extraName) { diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDeviceDriver.java index af813d8..d0c9c6e 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/double_belt_conveyor/DoubleBeltConveyorDeviceDriver.java @@ -595,14 +595,6 @@ public class DoubleBeltConveyorDeviceDriver extends AbstractOpcDeviceDriver impl instructionService.update(inst); logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task); } - //当货物到达b点,实现完成指令 - if (StrUtil.equals(inst.getInstruction_status(), InstructionStatusEnum.BUSY.getIndex()) || StrUtil.equals(inst.getInstruction_status(), InstructionStatusEnum.READY.getIndex())) { - if (StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { - inst.setExecute_device_code(this.device_code); - finish_instruction(); - logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task); - } - } } } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index cfb6cbe..595c460 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -683,7 +683,6 @@ public class InstructionServiceImpl extends CommonServiceImpl Date: Thu, 7 Dec 2023 15:13:14 +0800 Subject: [PATCH 3/4] =?UTF-8?q?add:=20=E5=85=B3=E8=81=94=E7=AB=99=E7=82=B9?= =?UTF-8?q?=E5=BC=80=E5=8F=91,=E4=BB=A3=E7=A1=AE=E8=AE=A4=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/device_driver/DriverTypeEnum.java | 2 +- .../device/driver/double_belt_conveyor.vue | 668 ++++++++++++++++++ .../device/driver/double_station_stacker.vue | 18 +- 3 files changed, 670 insertions(+), 18 deletions(-) create mode 100644 acs/nladmin-ui/src/views/acs/device/driver/double_belt_conveyor.vue diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index 24175d4..8e68dab 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -41,7 +41,7 @@ public enum DriverTypeEnum { DOUBLE_STATION_STACKER(16, "double_station_stacker", "标准版-双工位堆垛机", "double_station_stacker"), - DOUBLE_BELT_CONVEYOR(17, "double_belt_conveyor", "双工位输送线虚拟站点", "double_belt_conveyor"); + DOUBLE_BELT_CONVEYOR(17, "double_belt_conveyor", "双工位输送线", "double_belt_conveyor"); diff --git a/acs/nladmin-ui/src/views/acs/device/driver/double_belt_conveyor.vue b/acs/nladmin-ui/src/views/acs/device/driver/double_belt_conveyor.vue new file mode 100644 index 0000000..378c09c --- /dev/null +++ b/acs/nladmin-ui/src/views/acs/device/driver/double_belt_conveyor.vue @@ -0,0 +1,668 @@ + + + + + diff --git a/acs/nladmin-ui/src/views/acs/device/driver/double_station_stacker.vue b/acs/nladmin-ui/src/views/acs/device/driver/double_station_stacker.vue index 053b0d5..1968e06 100644 --- a/acs/nladmin-ui/src/views/acs/device/driver/double_station_stacker.vue +++ b/acs/nladmin-ui/src/views/acs/device/driver/double_station_stacker.vue @@ -96,23 +96,7 @@ - - - - - - - + Date: Fri, 8 Dec 2023 15:36:06 +0800 Subject: [PATCH 4/4] =?UTF-8?q?add:=E5=8F=8C=E5=B7=A5=E4=BD=8D=E8=BE=93?= =?UTF-8?q?=E9=80=81=E7=BA=BF=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- acs/nladmin-ui/src/views/acs/device/config.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/acs/nladmin-ui/src/views/acs/device/config.vue b/acs/nladmin-ui/src/views/acs/device/config.vue index 1751d4d..0e4749b 100644 --- a/acs/nladmin-ui/src/views/acs/device/config.vue +++ b/acs/nladmin-ui/src/views/acs/device/config.vue @@ -101,7 +101,7 @@ import agv_ndc_two from '@/views/acs/device/driver/agv/agv_ndc_two' import xg_agv from '@/views/acs/device/driver/agv/xg_agv' import led_screen from './driver/led_screen' import standard_station from '@/views/acs/device/driver/standard_station' - +import double_belt_conveyor from '@/views/acs/device/driver/double_belt_conveyor.vue' export default { name: 'DeviceConfig', components: { @@ -132,7 +132,8 @@ export default { standard_station, oven_manipulator, plug_pull_device_site, - slit_two_manipulator + slit_two_manipulator, + double_belt_conveyor }, dicts: ['device_type'],