驱动框架搭建

This commit is contained in:
2023-11-28 19:41:36 +08:00
parent 0914f3d94f
commit c8d804cb74
4 changed files with 1184 additions and 6 deletions

View File

@@ -35,13 +35,11 @@ public enum DriverTypeEnum {
SIEMENS_CONVEYOR(14,"siemens_conveyor","西门子-输送机驱动","conveyor"),
BELT_CONVEYOR(13,"belt_conveyor","标准版-输送","conveyor"),
BELT_CONVEYOR(13,"belt_conveyor","输送线","conveyor"),
//LAMP_THREE_COLOR(17,"lamp_three_color","标准版-三色灯","conveyor"),
//BOX_PALLETIZING_MANIPULATOR(16,"box_palletizing_manipulator","木箱码垛-行架机械手","station"),
SCREEN(15, "led_screen", "LED点阵屏", "screen");
SCREEN(15, "led_screen", "LED点阵屏", "screen"),
DOUBLE_STATION_STACKER(16, "double_station_stacker", "双工位堆垛机", "double_station_stacker"),
;

View File

@@ -0,0 +1,57 @@
package org.nl.acs.device_driver.basedriver.double_station_stacker;
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 DoubleStationStackerDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "double_station_stacker";
}
@Override
public String getDriverName() {
return "双工位堆垛机";
}
@Override
public String getDriverDescription() {
return "双工位堆垛机";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new DoubleStationStackerDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return DoubleStationStackerDeviceDriver.class;
}
@Override
public List<DeviceType> getFitDeviceTypes() {
List<DeviceType> types = new LinkedList();
types.add(DeviceType.stacker);
return types;
}
@Override
public List<ItemDto> getReadableItemDtos() {
return ItemProtocol.getReadableItemDtos();
}
@Override
public List<ItemDto> getWriteableItemDtos() {
return ItemProtocol.getWriteableItemDtos();
}
}

View File

@@ -0,0 +1,730 @@
package org.nl.acs.device_driver.basedriver.double_station_stacker;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.domain.Device;
import org.nl.acs.device.domain.DeviceExtra;
import org.nl.acs.device.enums.DeviceType;
import org.nl.acs.device.service.DeviceExtraService;
import org.nl.acs.device.service.impl.DeviceExtraServiceImpl;
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.siemens_conveyor.SiemensConveyorDeviceDriver;
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver;
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver;
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.opc.DeviceAppServiceImpl;
import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.route.service.dto.RouteLineDto;
import org.nl.acs.route.service.impl.RouteLineServiceImpl;
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.*;
/**
* 双工位堆垛机驱动
*/
@Slf4j
@Data
@RequiredArgsConstructor
public class DoubleStationStackerDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
@Autowired
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
@Autowired
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
@Autowired
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
@Autowired
DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
@Autowired
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class);
@Autowired
DeviceExtraService deviceExtraService = SpringContextHolder.getBean(DeviceExtraServiceImpl.class);
//心跳
Integer heartbeat = 0;
Integer last_heartbeat = 0;
//堆垛机号
Integer item_deviceCode = 0;
Integer last_item_deviceCode = 0;
//工作模式
Integer mode = 0;
Integer last_mode = 0;
//作业状态
Integer command = 0;
Integer last_command = 0;
//任务号
Integer task = 0;
Integer last_task = 0;
//y轴报警(载货台)
Integer error = 0;
Integer last_error = 0;
//行走排号
Integer z = 0;
Integer last_z = 0;
//行走列号
Integer x = null;
Integer last_x = null;
//行走层号
Integer y = 0;
Integer last_y = 0;
//行走开关信号
Float move = 0F;
Float last_move = 0F;
//载货台开关信号
Float cargoMove = 0F;
Float last_cargoMove = 0F;
//行走动作信号
Float action = 0F;
Float last_action = 0F;
//行走激光数值
Integer distancex = 0;
Integer last_distancex = 0;
//起升激光数值
Integer distancey = 0;
Integer last_distancey = 0;
//载货台超限信号
Float cargoError = 0F;
Float last_cargoError = 0F;
//货叉探货信号
Float forkCargo = 0F;
Float last_forkCargo = 0F;
//货叉位置信号
Float forkLocation = 0F;
Float last_forkLocation = 0F;
//货叉动作信号
Float forkAction = 0F;
Float last_forkAction = 0F;
//特殊开关量1
Float special1 = 0F;
Float last_special1 = 0F;
//特殊开关量2
Float special2 = 0F;
Float last_special2 = 0F;
//托盘条码
int[] trayCode;
int[] last_trayCode;
//水箱和消防缓存位有无货
Float storage_cache = 0F;
Float last_storage_cache = 0F;
String message = null;
String device_code = null;
String notCreateInstMessage = null;
private int instruction_require_time_out = 3000;
private int instruction_update_time_out = 3000;
private Date instruction_require_time = new Date();
private Date instruction_update_time = new Date();
List<String> getDeviceCodeList = null;
List<String> putDeviceCodeList = null;
//请求成功标记
Boolean requireSucess = false;
//当前指令
Instruction inst = null;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() throws Exception {
try {
device_code = this.getDeviceCode();
heartbeat = this.itemProtocol.getItem_heartbeat();
item_deviceCode = this.itemProtocol.getItem_deviceCode();
mode = this.itemProtocol.getItem_mode();
move = this.itemProtocol.getItem_move();
special1 = this.itemProtocol.getItem_special1();
special2 = this.itemProtocol.getItem_special2();
storage_cache = this.itemProtocol.getItem_storage_cache();
if (!item_deviceCode.equals(last_item_deviceCode)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(item_deviceCode));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_item_deviceCode + "->" + item_deviceCode);
}
if (!mode.equals(last_mode)) {
requireSucess = false;
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_mode + "->" + mode);
}
if (!command.equals(last_command)) {
requireSucess = false;
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(command));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_command + "->" + command);
}
if (!task.equals(last_task)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_task + "->" + task);
}
if (!error.equals(last_error)) {
if (0 != error) {
}
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(error));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_error + "->" + error);
}
if (!z.equals(last_z)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(z));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_z + "->" + z);
}
if (!x.equals(last_x)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(x));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_x + "->" + x);
}
if (!y.equals(last_y)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(y));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_y + "->" + y);
}
if (!move.equals(last_move)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(move));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_move + "->" + move);
}
if (!cargoMove.equals(last_cargoMove)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(cargoMove));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_cargoMove + "->" + cargoMove);
}
if (!action.equals(last_action)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(action));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_action + "->" + action);
}
if (!distancex.equals(last_distancex)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(distancex));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_distancex + "->" + distancex);
}
if (!distancey.equals(last_distancey)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(distancey));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_distancey + "->" + distancey);
}
if (!cargoError.equals(last_cargoError)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(cargoError));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_cargoError + "->" + cargoError);
}
if (!forkCargo.equals(last_forkCargo)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(forkCargo));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_forkCargo + "->" + forkCargo);
}
if (!forkLocation.equals(last_forkLocation)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(forkLocation));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_forkLocation + "->" + forkLocation);
}
if (!forkAction.equals(last_forkAction)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(forkAction));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_forkAction + "->" + forkAction);
}
if (!special1.equals(last_special1)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(special1));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_special1 + "->" + special1);
}
if (!special2.equals(last_special2)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(special2));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_special2 + "->" + special2);
}
if (!Arrays.equals(trayCode, last_trayCode)) {
logServer.deviceItemValue(this.device_code, "mode", Arrays.toString(trayCode));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + Arrays.toString(last_trayCode) + "->" + Arrays.toString(trayCode));
}
if (!storage_cache.equals(last_storage_cache)) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(storage_cache));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_storage_cache + "->" + storage_cache);
}
// 更新指令状态
if (mode == 3 && task > 0) {
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;
//更改指令状态
if (task > 0) {
Instruction inst = checkInst();
if (inst != null) {
if (StrUtil.equals(inst.getInstruction_status(), "0")) {
inst.setInstruction_status("1");
inst.setExecute_device_code(this.device_code);
instructionService.update(inst);
}
}
}
}
}
} catch (Exception var17) {
var17.printStackTrace();
logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol));
}
if (mode != 3) {
message = "未联机";
} else if (error != 0) {
message = "有报警";
//指定库位满入
if (error == 5) {
}
//空出
if (error == 6) {
}
//浅货位有货
if (error == 16) {
//放货
if (cargoMove == 1) {
} else if (cargoMove == 0) {
//取货
}
}
} else {
HashMap map = new HashMap();
switch (command) {
case 0:
applyTask();
requireSucess = true;
break;
case 1:
message = "取货中";
break;
case 2:
message = "取货完成";
Instruction instruction = checkInst();
String next_device_code = instruction.getNext_device_code();
Device nextDevice = deviceAppService.findDeviceByCode(next_device_code);
if (StrUtil.equals(nextDevice.getDevice_type(), DeviceType.conveyor.name())) {
List<DeviceExtra> list = deviceExtraService.list(Wrappers.lambdaQuery(DeviceExtra.class).eq(DeviceExtra::getDevice_code, next_device_code));
for (DeviceExtra deviceExtra : list) {
if ("x".equals(deviceExtra.getExtra_code()) && StrUtil.isNotEmpty(deviceExtra.getExtra_value())) {
map.put("to_x", deviceExtra.getExtra_value());
}
if ("z".equals(deviceExtra.getExtra_code()) && StrUtil.isNotEmpty(deviceExtra.getExtra_value())) {
map.put("to_z", deviceExtra.getExtra_value());
}
if ("y".equals(deviceExtra.getExtra_code()) && StrUtil.isNotEmpty(deviceExtra.getExtra_value())) {
map.put("to_y", deviceExtra.getExtra_value());
}
}
}
if (StrUtil.equals(nextDevice.getDevice_type(), DeviceType.storage.name())) {
map.put("to_y", inst.getFrom_z());
if (inst.getFrom_x().length() > 1) {
String substring = inst.getFrom_x().substring(1);
map.put("to_z", substring);
} else {
map.put("to_z", inst.getFrom_x());
}
map.put("to_x", inst.getFrom_y());
}
map.put("to_command", 2);
requireSucess = true;
break;
case 3:
message = "放货中";
break;
case 4:
message = "请求卸货(申请卸货)";
Instruction instruction1 = checkInst();
String next_device_code1 = instruction1.getNext_device_code();
Device nextDevice1 = deviceAppService.findDeviceByCode(next_device_code1);
if (ObjectUtil.isNotNull(instruction1)) {
//指令为执行
SiemensConveyorDeviceDriver siemensConveyorDeviceDriver;
if (nextDevice1.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) {
siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) nextDevice1.getDeviceDriver();
if (siemensConveyorDeviceDriver.getMode() != 2 || siemensConveyorDeviceDriver.getMove() == 1) {
notCreateInstMessage = "未下发电气信号原因->输送线-货架对接位:" + siemensConveyorDeviceDriver.getDevice_code() +
"有货或未联机,无法下发指令!指令号:" + inst.getInstruction_code();
return;
}
}
map.put("to_command", 3);
}
requireSucess = true;
break;
case 5:
message = "放货完成";
map.put("to_command", 5);
Instruction inst = checkInst();
try {
finish_instruction(inst);
} catch (Exception e) {
e.printStackTrace();
}
requireSucess = true;
break;
case 6:
message = "取货准备(会库位台)";
map.put("to_command", 6);
requireSucess = true;
break;
case 7:
message = "召回";
map.put("to_command", 7);
requireSucess = true;
break;
case 8:
message = "急停";
map.put("to_command", 8);
requireSucess = true;
break;
default:
message = "不明";
requireSucess = true;
break;
}
if (ObjectUtil.isNotNull(map)) {
this.writing(map);
}
}
last_heartbeat = heartbeat;
last_item_deviceCode = item_deviceCode;
last_mode = mode;
last_command = command;
last_task = task;
last_error = error;
last_z = z;
last_x = x;
last_y = y;
last_move = move;
last_cargoMove = cargoMove;
last_action = action;
last_distancex = distancex;
last_distancey = distancey;
last_cargoError = cargoError;
last_forkCargo = forkCargo;
last_forkLocation = forkLocation;
last_forkAction = forkAction;
last_special1 = special1;
last_special2 = special2;
last_trayCode = trayCode;
last_storage_cache = storage_cache;
/*last_stacker_rpm = stacker_rpm;
last_stacker_electricCurrent = stacker_electricCurrent;
last_stacker_runing_time = stacker_runing_time;
last_stacker_workingHours = stacker_workingHours;
last_cargo_rpm = cargo_rpm;
last_cargo_electric_Current = cargo_electric_Current;
last_cargo_workingHour = cargo_workingHour;
last_cargo_runingTimes = cargo_runingTimes;
last_fork_rpm = fork_rpm;
last_fork_electric_Current = fork_electric_Current;
last_fork_workingHours = fork_workingHours;
last_fork_runingTimes = fork_runingTimes;*/
}
/**
* 申请任务
*
* @param
*/
public synchronized boolean applyTask() {
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 instruction1 = new Instruction();
instruction1.setInstruction_status("0");
List<Instruction> instructions = instructionService.findByDeviceCodes(instruction1, false);
if (CollUtil.isEmpty(instructions) || instructions.size() < 1) {
return false;
}
List<Instruction> instructionList = new ArrayList<>();
for (Instruction instruction : instructions) {
List<RouteLineDto> routeLineDtos = routeLineService.selectDeviceCodeList(instruction.getStart_device_code());
if (CollUtil.isEmpty(routeLineDtos) || routeLineDtos.size() < 1) {
message = "没有输送线到堆垛机的路由";
logServer.deviceExecuteLog(this.device_code, "", "", "没有" + instruction.getStart_device_code() + "->"
+ this.device_code + "的路由");
continue;
}
for (RouteLineDto routeLineDto : routeLineDtos) {
if (this.getDeviceCode().equals(routeLineDto.getNext_device_code())) {
List<RouteLineDto> routeLineDtoList = routeLineService.selectDeviceCodeList(this.getDeviceCode());
if (CollUtil.isEmpty(routeLineDtos) || routeLineDtos.size() < 1) {
message = "没有输送线到堆垛机的路由";
logServer.deviceExecuteLog(this.device_code, "", "", "没有" + instruction.getStart_device_code() + "->"
+ this.device_code + "的路由");
continue;
}
for (RouteLineDto routeLinedto : routeLineDtoList) {
if (instruction.getNext_device_code().equals(routeLinedto.getNext_device_code())) {
instructionList.add(instruction);
}
}
}
}
}
if (CollUtil.isEmpty(instructionList) || instructionList.size() < 1) {
return false;
}
instructionList = this.sortInst(instructionList);
inst = instructionList.get(0);
//指令未执行
if (StrUtil.equals(inst.getInstruction_status(), "0")) {
String start_device_code = inst.getStart_device_code();
Device startDevice = deviceAppService.findDeviceByCode(start_device_code);
BeltConveyorDeviceDriver beltConveyorDeviceDriver;
if (startDevice.getDeviceDriver() instanceof BeltConveyorDeviceDriver) {
beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) startDevice.getDeviceDriver();
if (beltConveyorDeviceDriver.getMode() != 2 || beltConveyorDeviceDriver.getMove() == 0) {
notCreateInstMessage = "未下发电气信号原因->输送线-货架对接位:" + beltConveyorDeviceDriver.getDevice_code() +
"无货或未联机,无法下发指令!指令号:" + inst.getInstruction_code();
return false;
}
}
HashMap map = new HashMap();
map.put("to_device_code", this.getDevice().getAddress());
map.put("to_command", 1);
// map.put("to_type", inst.getMaterial());
map.put("to_task", inst.getInstruction_code());
if (StrUtil.equals(startDevice.getDevice_type(), DeviceType.conveyor.name())) {
List<DeviceExtra> list = deviceExtraService.list(Wrappers.lambdaQuery(DeviceExtra.class).eq(DeviceExtra::getDevice_code, start_device_code));
for (DeviceExtra deviceExtra : list) {
if ("x".equals(deviceExtra.getExtra_code()) && StrUtil.isNotEmpty(deviceExtra.getExtra_value())) {
map.put("to_x", deviceExtra.getExtra_value());
}
if ("z".equals(deviceExtra.getExtra_code()) && StrUtil.isNotEmpty(deviceExtra.getExtra_value())) {
map.put("to_z", deviceExtra.getExtra_value());
}
if ("y".equals(deviceExtra.getExtra_code()) && StrUtil.isNotEmpty(deviceExtra.getExtra_value())) {
map.put("to_y", deviceExtra.getExtra_value());
}
}
}
if (StrUtil.equals(startDevice.getDevice_type(), DeviceType.storage.name())) {
map.put("to_y", inst.getFrom_z());
if (inst.getFrom_x().length() > 1) {
String substring = inst.getFrom_x().substring(1);
map.put("to_z", substring);
} else {
map.put("to_z", inst.getFrom_x());
}
map.put("to_x", inst.getFrom_y());
}
this.writing(map);
}
}
return false;
}
/**
* 将指令根据优先级和创建时间排序
*
* @param instructions
* @return
*/
private List<Instruction> sortInst(List<Instruction> instructions) {
Collections.sort(instructions, (t1, t2) -> {
//优先级从大到小
int i = t2.getPriority().compareTo(t1.getPriority());
//如果优先级相等
if (i == 0) {
//时间从早到晚
i = t1.getCreate_time().compareTo(t2.getCreate_time());
}
return i;
});
return instructions;
}
/**
* 更新指令状态
*/
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;
//更改指令状态
if (task > 0) {
//inst_message
Instruction inst = checkInst();
if (inst != null) {
if (StrUtil.equals(inst.getInstruction_status(), "0")) {
inst.setInstruction_status("1");
inst.setExecute_device_code(this.device_code);
instructionService.update(inst);
}
}
}
HashMap map = new HashMap();
//取货完成
if (command == 2) {
map.put("to_command", 2);
}
//请求卸货(申请卸货)
if (command == 4) {
Instruction instruction = checkInst();
if (ObjectUtil.isNotNull(instruction)) {
//指令为执行
String next_device_code = instruction.getNext_device_code();
Device startDevice = deviceAppService.findDeviceByCode(next_device_code);
SiemensConveyorDeviceDriver siemensConveyorDeviceDriver;
if (startDevice.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) {
siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) startDevice.getDeviceDriver();
if (siemensConveyorDeviceDriver.getMode() != 2 || siemensConveyorDeviceDriver.getMove() == 1) {
notCreateInstMessage = "未下发电气信号原因->输送线-货架对接位:" + siemensConveyorDeviceDriver.getDevice_code() +
"有货或未联机,无法下发指令!指令号:" + inst.getInstruction_code();
return;
}
}
map.put("to_command", 3);
}
}
//放货完成
if (command == 5) {
map.put("to_command", 5);
try {
finish_instruction(inst);
} catch (Exception e) {
e.printStackTrace();
}
}
//取货准备(回库台位)
if (command == 6) {
map.put("to_command", 6);
}
//召回
if (command == 7) {
map.put("to_command", 7);
}
//急停
if (command == 8) {
map.put("to_command", 8);
}
this.writing(map);
}
}
@Override
public JSONObject getDeviceStatusName() throws Exception {
return null;
}
@Override
public void setDeviceStatus(JSONObject data) {
}
/**
* 完成指令
*
* @param inst
* @return
* @throws Exception
*/
public synchronized boolean finish_instruction(Instruction inst) throws Exception {
instructionService.finish(inst);
return true;
}
public String getToParam() {
return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + ".";
}
public void writing(Map<String, Object> map) {
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
Map<String, Object> 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 List<TaskDto> sortTask(List<TaskDto> taskDtos) {
Collections.sort(taskDtos, new Comparator<TaskDto>() {
@Override
public int compare(TaskDto t1, TaskDto t2) {
//优先级从大到小
int i = t2.getPriority().compareTo(t1.getPriority());
//如果优先级相等
if (i == 0) {
//时间从早到晚
i = t1.getCreate_time().compareTo(t2.getCreate_time());
}
return i;
}
});
return taskDtos;
}
//将扩展表中的字符串数据转换成集合
@Override
public List<String> getExtraDeviceCodes(String extraName) {
String extraValue = (String) this.getDevice().getExtraValue().get(extraName);
if (StrUtil.isEmpty(extraValue)) {
return new ArrayList<>();
}
String devicesString = extraValue.substring(1, extraValue.length() - 1);
List<String> devicesList = new ArrayList<>();
String[] devices = devicesString.split(",");
for (int i = 0; i < devices.length; i++) {
String s = devices[i].replace("\"", "").replace("\"", "");
devicesList.add(s);
}
return devicesList;
}
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;
}
}

View File

@@ -0,0 +1,393 @@
package org.nl.acs.device_driver.basedriver.double_station_stacker;
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_deviceCode = "deviceCode";
//工作模式
public static String item_mode = "mode";
//行走动作信号
public static String item_action = "action";
//前叉行走排号
public static String item_front_z = "front_z";
//前叉行走列号
public static String item_front_x = "front_x";
//前叉行走层号
public static String item_front_y = "front_y";
//后叉行走排号
public static String item_back_z = "back_z";
//后叉行走列号
public static String item_back_x = "back_x";
//后叉行走层号
public static String item_back_y = "back_y";
//行走开关信号
public static String item_move = "move";
//行走激光数值
public static String item_distancex = "distancex";
//特殊开关量1
public static String item_special1 = "special1";
//特殊开关量2
public static String item_special2 = "special2";
//水箱和消防缓存位有无货
public static String item_storage_cache = "storage_cache";
//速度(转/分钟)
public static String item_stacker_rpm = "stacker_rpm";
//电流
public static String item_stacker_electricCurrent = "stacker_electricCurrent";
//轴工作时间(小时)
public static String item_stacker_workingHours = "stacker_workingHours";
//轴运行次数
public static String item_stacker_runingTime = "stacker_runingTime";
//心跳
public static String item_to_heartbeat = "to_heartbeat";
//堆垛机号
public static String item_to_device_code = "to_device_code";
//作业命令
public static String item_to_command = "to_command";
//物料类型
public static String item_to_type = "to_type";
//任务号
public static String item_to_task = "to_task";
//作业排
public static String item_to_z = "to_z";
//作业列
public static String item_to_x = "to_x";
//作业层
public static String item_to_y = "to_y";
//托盘号
public static String item_to_trayCode = "to_trayCode";
//堆垛机主体报警
public static String item_stacker_error = "stackerError";
//前叉作业状态
public static String item_front_command = "front_command";
//前叉任务号
public static String item_front_task = "front_task";
//前叉Y轴报警载货台
public static String item_front_YError = "front_YError";
//前叉Z轴报警货叉
public static String item_front_ZError= "front_ZError";
//前叉载货台开关信号
public static String item_front_cargoMove = "front_cargoMove";
//前叉载货台升降动作信号
public static String item_front_action = "front_action";
//前叉载货台超限信号
public static String item_front_cargoError = "front_cargoError";
//前叉载货台起升激光值
public static String item_front_distanceY = "front_distanceY";
//前叉货叉探货信号
public static String item_front_forkCargo = "front_forkCargo";
//前叉货叉位置信号
public static String item_front_forkLocation = "front_forkLocation";
//前叉货叉动作信号
public static String item_front_forkAction = "front_forkAction";
//前叉托盘条码
public static String item_front_trayCode = "front_trayCode";
//前叉载货台速度(转/分钟)
public static String item_front_y_rpm = "front_y_rpm";
//前叉载货台电流
public static String item_front_y_electricCurrent = "front_y_electricCurrent";
//前叉载货台轴工作小时数
public static String item_front_y_workingHours = "front_y_workingHours";
//前叉载货台轴运行次数
public static String item_front_y_runingTimes = "front_y_runingTimes";
//前叉货叉速度(转/分钟)
public static String item_front_z_rpm = "front_z_rpm";
//前叉货叉电流
public static String item_front_z_electricCurrent = "front_z_electricCurrent";
//前叉货叉轴工作时间(小时)
public static String item_front_z_workingHours = "item_front_z_workingHours";
//前叉货叉轴运行次数
public static String item_front_z_runingTimes = "front_front_z_runingTimes";
//后叉作业状态
public static String item_back_command = "back_command";
//后叉任务号
public static String item_back_task = "back_task";
//后叉Y轴报警载货台
public static String item_back_YError = "back_YError";
//后叉Z轴报警货叉
public static String item_back_ZError = "back_ZError";
//后叉载货台开关信号
public static String item_back_cargoMove = "back_cargoMove";
//后叉载货台升降动作信号
public static String item_back_action = "back_action";
//后叉载货台超限信号
public static String item_back_cargoError = "back_cargoError";
//后叉载货台起升激光值
public static String item_back_distanceY = "back_distanceY";
//后叉货叉探货信号
public static String item_back_forkCargo = "back_forkCargo";
//后叉货叉位置信号
public static String item_back_forkLocation = "back_forkLocation";
//后叉货叉动作信号
public static String item_back_forkAction = "back_forkAction";
//后叉托盘条码
public static String item_back_trayCode = "back_trayCode";
//后叉载货台速度(转/分钟)
public static String item_back_y_rpm = "back_y_rpm";
//后叉载货台电流
public static String item_back_y_electricCurrent = "back_y_electricCurrent";
//后叉载货台轴工作小时数
public static String item_back_y_workingHours = "back_y_workingHours";
//后叉载货台轴运行次数
public static String item_back_y_runingTimes = "back_y_runingTimes";
//后叉货叉速度(转/分钟)
public static String item_back_z_rpm = "back_z_rpm";
//后叉货叉电流
public static String item_back_z_electricCurrent = "back_z_electricCurrent";
//后叉货叉轴工作时间(小时)
public static String item_back_z_workingHours = "back_z_workingHours";
//后叉货叉轴运行次数
public static String item_back_z_runingTimes = "back_z_runingTimes";
//托盘类型
public static String item_to_container_type = "to_container_type";
//货叉选择
public static String item_to_chooseFork = "to_chooseFork";
//前叉任务号
public static String item_to_front_task = "to_front_task";
//前叉托盘号
public static String item_to_front_trayCode = "to_front_trayCode";
//后叉任务号
public static String item_to_back_task = "to_back_task";
//后叉托盘号
public static String item_to_back_trayCode = "to_back_trayCode";
Boolean isonline;
private DoubleStationStackerDeviceDriver driver;
public ItemProtocol(DoubleStationStackerDeviceDriver driver) {
this.driver = driver;
}
public Integer getItem_heartbeat(){
return this.getOpcIntegerValue(item_heartbeat);
}
public Integer getItem_deviceCode(){
return this.getOpcIntegerValue(item_deviceCode);
}
public Integer getItem_mode(){
return this.getOpcIntegerValue(item_mode);
} ;
public float getItem_move(){
return this.getOpcFloatValue(item_move);
}
public Integer getItem_distancex(){
return this.getOpcIntegerValue(item_distancex);
}
public float getItem_special1(){
return this.getOpcFloatValue(item_special1);
}
public float getItem_special2(){
return this.getOpcFloatValue(item_special2);
}
public float getItem_storage_cache(){
return this.getOpcFloatValue(item_storage_cache);
}
public Integer getItem_stacker_rpm(){
return this.getOpcIntegerValue(item_stacker_rpm);
}
public Integer getItem_stacker_electricCurrent(){
return this.getOpcIntegerValue(item_stacker_electricCurrent);
}
public Integer getItem_stacker_workingHours(){
return this.getOpcIntegerValue(item_stacker_workingHours);
}
public Integer getItem_stacker_runingTime(){
return this.getOpcIntegerValue(item_stacker_runingTime);
}
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 (value == null) {
setIsonline(false);
return "0";
} else {
setIsonline(true);
return value;
}
}
public int[] getOpcIntegerArrayValue(String protocol) {
int[] value = this.driver.getIntegerArrayValue(protocol);
if (value == null) {
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return new int[20];
}
public float getOpcFloatValue(String protocol) {
Float value = this.driver.getDoubleValue(protocol);
if (value == null) {
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return 0;
}
public Long getOpcLongValue(String protocol) {
Long value = this.driver.getLongValue(protocol);
if (value == null) {
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return 0L;
}
public static List<ItemDto> getReadableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_heartbeat, "心跳", "DB101.BO"));
list.add(new ItemDto(item_deviceCode, "堆垛机号", "DB101.B1"));
list.add(new ItemDto(item_mode, "工作模式", "DB101.B2"));
list.add(new ItemDto(item_stacker_error, "堆垛机主体报警", "DB101.B3"));
list.add(new ItemDto(item_move, "行走开关信号", "DB101.D4"));
list.add(new ItemDto(item_action, "行走动作信号", "DB101.B5"));
list.add(new ItemDto(item_distancex, "行走激光数值", "DB101.D6"));
list.add(new ItemDto(item_special1, "特殊开关量1", "DB101.B10"));
list.add(new ItemDto(item_special2, "特殊开关量2", "DB101.B11"));
list.add(new ItemDto(item_stacker_rpm, "速度(转/分钟)", "DB101.W12"));
list.add(new ItemDto(item_stacker_electricCurrent, "电流", "DB101.W14"));
list.add(new ItemDto(item_stacker_workingHours, "轴工作时间(小时)", "DB101.D16"));
list.add(new ItemDto(item_stacker_runingTime, "轴运行次数", "DB101.D20"));
list.add(new ItemDto(item_storage_cache, "水箱和消防缓存位有无货", "DB101.B24"));
list.add(new ItemDto(item_front_command, "前叉作业状态", "DB101.B31"));
list.add(new ItemDto(item_front_task, "前叉任务号", "DB101.D32"));
list.add(new ItemDto(item_front_YError, "前叉Y轴报警载货台", "DB101.B36"));
list.add(new ItemDto(item_front_ZError, "前叉Z轴报警货叉", "DB101.B37"));
list.add(new ItemDto(item_front_z, "前叉行走排号", "DB101.B38"));
list.add(new ItemDto(item_front_x, "前叉行走列号", "DB101.B39"));
list.add(new ItemDto(item_front_y, "前叉行走层号", "DB101.B40"));
list.add(new ItemDto(item_front_cargoMove, "前叉载货台开关信号", "DB101.B41"));
list.add(new ItemDto(item_front_action, "前叉载货台升降动作信号", "DB101.B42"));
list.add(new ItemDto(item_front_cargoError, "前叉载货台超限信号", "DB101.B43"));
list.add(new ItemDto(item_front_distanceY, "前叉载货台起升激光值", "DB101.D44"));
list.add(new ItemDto(item_front_forkCargo, "前叉货叉探货信号", "DB101.B48"));
list.add(new ItemDto(item_front_forkLocation, "前叉货叉位置信号", "DB101.B49"));
list.add(new ItemDto(item_front_forkAction, "前叉货叉动作信号", "DB101.B50"));
list.add(new ItemDto(item_front_trayCode, "前叉托盘条码", "DB101.B51.20"));
list.add(new ItemDto(item_front_y_rpm, "前叉载货台速度(转/分钟)", "DB101.W72"));
list.add(new ItemDto(item_front_y_electricCurrent, "前叉载货台电流", "DB101.W74"));
list.add(new ItemDto(item_front_y_workingHours, "前叉载货台轴工作小时数", "DB101.D76"));
list.add(new ItemDto(item_front_y_runingTimes, "前叉载货台轴运行次数", "DB101.B80"));
list.add(new ItemDto(item_front_z_rpm, "前叉货叉速度(转/分钟)", "DB101.W84"));
list.add(new ItemDto(item_front_z_electricCurrent, "前叉货叉电流", "DB101.W86"));
list.add(new ItemDto(item_front_z_workingHours, "前叉货叉轴工作时间(小时)", "DB101.D88"));
list.add(new ItemDto(item_front_z_runingTimes, "前叉货叉轴运行次数", "DB101.D92"));
list.add(new ItemDto(item_back_command, "后叉作业状态", "DB101.B101"));
list.add(new ItemDto(item_back_task, "后叉任务号", "DB101.D102"));
list.add(new ItemDto(item_back_YError, "后叉Y轴报警载货台", "DB101.B106"));
list.add(new ItemDto(item_back_ZError, "后叉Z轴报警货叉", "DB101.B107"));
list.add(new ItemDto(item_back_z, "后叉行走排号", "DB101.B108"));
list.add(new ItemDto(item_back_x, "后叉行走列号", "DB101.B109"));
list.add(new ItemDto(item_back_y, "后叉行走层号", "DB101.B110"));
list.add(new ItemDto(item_back_cargoMove, "后叉载货台开关信号", "DB101.B111"));
list.add(new ItemDto(item_back_action, "后叉载货台升降动作信号", "DB101.B112"));
list.add(new ItemDto(item_back_cargoError, "后叉载货台超限信号", "DB101.B113"));
list.add(new ItemDto(item_back_distanceY, "后叉载货台起升激光值", "DB101.D114"));
list.add(new ItemDto(item_back_forkCargo, "后叉货叉探货信号", "DB101.B118"));
list.add(new ItemDto(item_back_forkLocation, "后叉货叉位置信号", "DB101.B119"));
list.add(new ItemDto(item_back_forkAction, "后叉货叉动作信号", "DB101.B120"));
list.add(new ItemDto(item_back_y_rpm, "后叉载货台速度(转/分钟)", "DB101.W142"));
list.add(new ItemDto(item_back_y_electricCurrent, "后叉载货台电流", "DB101.W144"));
list.add(new ItemDto(item_back_y_runingTimes, "后叉载货台轴运行次数", "DB101.D150"));
list.add(new ItemDto(item_back_z_rpm, "后叉货叉速度(转/分钟)", "DB101.W154"));
list.add(new ItemDto(item_back_z_electricCurrent, "后叉货叉电流", "DB101.W156"));
list.add(new ItemDto(item_back_z_workingHours, "后叉货叉轴工作时间(小时)", "DB101.D158"));
list.add(new ItemDto(item_back_z_runingTimes, "后叉货叉轴运行次数", "DB101.D162"));
return list;
}
public static List<ItemDto> getWriteableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_to_heartbeat, "心跳", "DB100.B0"));
list.add(new ItemDto(item_to_device_code, "堆垛机号", "DB100.B1"));
list.add(new ItemDto(item_to_command, "作业命令", "DB100.B2"));
list.add(new ItemDto(item_to_container_type, "托盘类型", "DB100.B3"));
list.add(new ItemDto(item_to_chooseFork, "货叉选择", "DB100.W4"));
list.add(new ItemDto(item_to_z, "作业排", "DB100.B6"));
list.add(new ItemDto(item_to_x, "作业列", "DN100.B7"));
list.add(new ItemDto(item_to_y, "作业层", "DB100.B8"));
list.add(new ItemDto(item_to_front_task, "前叉任务号", "DB100.D10"));
list.add(new ItemDto(item_to_front_trayCode, "前叉托盘号", "DB100.B14.20"));
list.add(new ItemDto(item_to_back_task, "后叉任务号", "DB100.D34"));
list.add(new ItemDto(item_to_back_trayCode, "后叉托盘号", "DB100.B38.20"));
return list;
}
@Override
public String toString() {
return "";
}
}