From e7895e150cbced03f3c0054ba68e33d8f6e7d8a8 Mon Sep 17 00:00:00 2001 From: tuqiang <437016993@qq.com> Date: Tue, 31 Oct 2023 14:37:20 +0800 Subject: [PATCH] fix --- .../device/device_driver/DriverTypeEnum.java | 2 + .../nl/acs/device_driver/DeviceDriver.java | 2 - .../agv/ndcone/AgvNdcOneDeviceDriver.java | 84 ++++- .../standard_autodoor/ItemProtocol.java | 72 ++++ .../StandardAutoDoorDefinition.java | 66 ++++ .../StandardAutoDoorDeviceDriver.java | 156 ++++++++ .../driver/AbstractDeviceDriver.java | 3 +- .../src/views/acs/device/config.vue | 4 +- .../acs/device/driver/standard_autodoor.vue | 352 ++++++++++++++++++ 9 files changed, 729 insertions(+), 12 deletions(-) create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/ItemProtocol.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/StandardAutoDoorDefinition.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/StandardAutoDoorDeviceDriver.java create mode 100644 acs/nladmin-ui/src/views/acs/device/driver/standard_autodoor.vue diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index 29d5415..b801eec 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -15,6 +15,8 @@ public enum DriverTypeEnum { STORAGE(3, "standard_storage", "标准版-货架", "storage"), + AUTODOOR(4, "standard_autodoor", "标准版-自动门", "autodoor"), + // SCANNER(4, "standard_scanner", "标准版-扫码器", "scanner"), // INSPECT_CONVEYOR_CONTROL(5, "standard_conveyor_control", "标准版-输送机-控制点", "conveyor"), diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/DeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/DeviceDriver.java index 3f702c5..921dd3f 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/DeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/DeviceDriver.java @@ -2,7 +2,6 @@ package org.nl.acs.device_driver; import org.nl.acs.opc.Device; -import java.util.List; public interface DeviceDriver { default String getDeviceCode() { @@ -19,5 +18,4 @@ public interface DeviceDriver { return this.getDriverDefination().getDriverCode(); } - } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java index 6ece9c1..efe2d60 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java @@ -14,6 +14,7 @@ import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device_driver.DeviceDriver; import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.standard_autodoor.StandardAutoDoorDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_storage.StandardStorageDeviceDriver; import org.nl.acs.device_driver.driver.AbstractDeviceDriver; @@ -124,6 +125,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic StandardStorageDeviceDriver standardStorageDeviceDriver; // SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; + //自动门 + StandardAutoDoorDeviceDriver standardAutoDoorDeviceDriver; //分配 车id //(不需要WCS反馈) @@ -398,16 +401,81 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); } else if (phase == 0x50) {//进入交通灯区域 - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); + //开门 + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); + return; + } + if (agvaddr != 0) { + old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + if (StrUtil.contains(old_device_code, "-")) { + String[] point = old_device_code.split("-"); + device_code = point[0]; + } else if (StrUtil.contains(old_device_code, ".")) { + String[] point = old_device_code.split("\\."); + device_code = point[0]; + emptyNum = point[1]; + } else { + device_code = old_device_code; + } + } + + device = deviceAppService.findDeviceByCode(device_code); + if (device.getDeviceDriver() instanceof StandardAutoDoorDeviceDriver) { + standardAutoDoorDeviceDriver = (StandardAutoDoorDeviceDriver) device.getDeviceDriver(); + standardAutoDoorDeviceDriver.OpenOrClose("1"); + standardAutoDoorDeviceDriver.writing(1); + if (standardAutoDoorDeviceDriver.getAction() == 1) { + standardAutoDoorDeviceDriver.OpenOrClose("1"); + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + } + } + if (!ObjectUtil.isEmpty(data)) { + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); + OneNDCSocketConnectionAutoRun.write(data); + } } else if (phase == 0x51) {//离开交通灯区域 - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); - } - if (!ObjectUtil.isEmpty(data)) { - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); - OneNDCSocketConnectionAutoRun.write(data); + //关门 + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); + return; + } + if (agvaddr != 0) { + old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + if (StrUtil.contains(old_device_code, "-")) { + String[] point = old_device_code.split("-"); + device_code = point[0]; + } else if (StrUtil.contains(old_device_code, ".")) { + String[] point = old_device_code.split("\\."); + device_code = point[0]; + emptyNum = point[1]; + } else { + device_code = old_device_code; + } + } + + device = deviceAppService.findDeviceByCode(device_code); + if (device.getDeviceDriver() instanceof StandardAutoDoorDeviceDriver) { + standardAutoDoorDeviceDriver = (StandardAutoDoorDeviceDriver) device.getDeviceDriver(); + standardAutoDoorDeviceDriver.OpenOrClose("2"); + standardAutoDoorDeviceDriver.writing(2); + if (standardAutoDoorDeviceDriver.getAction() == 2) { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + } + } + if (!ObjectUtil.isEmpty(data)) { + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); + OneNDCSocketConnectionAutoRun.write(data); + } } + } + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/ItemProtocol.java new file mode 100644 index 0000000..869a8b3 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/ItemProtocol.java @@ -0,0 +1,72 @@ +package org.nl.acs.device_driver.basedriver.standard_autodoor; + +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +public class ItemProtocol { + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_action = "action"; + public static String item_error = "error"; + public static String item_to_command = "to_command"; + + + private StandardAutoDoorDeviceDriver driver; + + public ItemProtocol(StandardAutoDoorDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + log.error("读取错误!"); + } else { + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList<>(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB600.B1", Boolean.TRUE)); + list.add(new ItemDto(item_action, "动作信号", "DB600.B2")); + list.add(new ItemDto(item_error, "报警信号", "DB600.B4")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList<>(); + list.add(new ItemDto(item_to_command, "作业命令", "DB601.W2", Boolean.TRUE)); + return list; + } + +} + diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/StandardAutoDoorDefinition.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/StandardAutoDoorDefinition.java new file mode 100644 index 0000000..b7867b7 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/StandardAutoDoorDefinition.java @@ -0,0 +1,66 @@ +package org.nl.acs.device_driver.basedriver.standard_autodoor; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 自动门驱动定义 + */ +@Service +public class StandardAutoDoorDefinition implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "standard_autodoor"; + } + + @Override + public String getDriverName() { + return "标准版-自动门"; + } + + @Override + public String getDriverDescription() { + return "标准版-自动门"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new StandardAutoDoorDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return StandardAutoDoorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList<>(); + types.add(DeviceType.conveyor); + return types; + } + + + public static List getReadableItemDtos2() { + return ItemProtocol.getReadableItemDtos(); + } + + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/StandardAutoDoorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/StandardAutoDoorDeviceDriver.java new file mode 100644 index 0000000..28de621 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_autodoor/StandardAutoDoorDeviceDriver.java @@ -0,0 +1,156 @@ +package org.nl.acs.device_driver.basedriver.standard_autodoor; + +import com.alibaba.fastjson.JSONObject; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.opc.Device; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 自动门驱动 + */ +@Slf4j +@Getter +@Setter +@RequiredArgsConstructor +public class StandardAutoDoorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + String devicecode; + int mode = 0; + int action = 0; + int error = 0; + Boolean iserror = false; + + int move = 0; + int task = 0; + int last_action = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + protected boolean hasGoods = false; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + + String message = ""; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + devicecode = this.getDevice().getDevice_code(); + mode = this.itemProtocol.getMode(); + action = this.itemProtocol.getAction(); + error = this.itemProtocol.getError(); + + + last_action = action; + last_mode = mode; + last_error = error; + } + + public synchronized String getStatus() { + JSONObject jo = new JSONObject(); + + if (action == 1) { + jo.put("name", this.getDevice().getDevice_code()); + jo.put("status", "OPEN"); + + } else if (action == 2) { + jo.put("name", this.getDevice().getDevice_code()); + jo.put("status", "CLOSE"); + + } else { + jo.put("name", this.getDevice().getDevice_code()); + jo.put("status", "ERROR"); + } + return jo.toString(); + } + + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + server.disconnect(); + log.info("下发PLC信号:{},{}", to_command, command); + System.out.println("设备:" + devicecode + ",下发PLC信号:" + to_command + ",value:" + command); + + } + + public synchronized void OpenOrClose(String type) { + + //开门 + if ("1".equals(type)) { + writing(1); + } else { + writing(2); + } + + } + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractDeviceDriver.java index e0c58cf..46f22e5 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractDeviceDriver.java @@ -30,9 +30,10 @@ public class AbstractDeviceDriver implements DeviceDriver { return this.driverDefination; } + @Override public DeviceDriver setDriverDefination(DeviceDriverDefination var1) { - this.driverDefination = driverDefination; + this.driverDefination = var1; return this; } diff --git a/acs/nladmin-ui/src/views/acs/device/config.vue b/acs/nladmin-ui/src/views/acs/device/config.vue index 477cdc6..f8d035a 100644 --- a/acs/nladmin-ui/src/views/acs/device/config.vue +++ b/acs/nladmin-ui/src/views/acs/device/config.vue @@ -95,6 +95,7 @@ import hongxiang_conveyor from '@/views/acs/device/driver/hongxiang_conveyor' import plug_pull_device_site from '@/views/acs/device/driver/plug_pull_device_site' import siemens_conveyor_labeling from '@/views/acs/device/driver/siemens_conveyor_labeling' import siemens_conveyor_ckk from '@/views/acs/device/driver/siemens_conveyor_ckk' +import standard_autodoor from '@/views/acs/device/driver/standard_autodoor' export default { name: 'DeviceConfig', @@ -120,7 +121,8 @@ export default { slit_two_manipulator, plug_pull_device_site, siemens_conveyor_labeling, - siemens_conveyor_ckk + siemens_conveyor_ckk, + standard_autodoor }, dicts: ['device_type'], mixins: [crud], diff --git a/acs/nladmin-ui/src/views/acs/device/driver/standard_autodoor.vue b/acs/nladmin-ui/src/views/acs/device/driver/standard_autodoor.vue new file mode 100644 index 0000000..41e2f46 --- /dev/null +++ b/acs/nladmin-ui/src/views/acs/device/driver/standard_autodoor.vue @@ -0,0 +1,352 @@ + + + + +