This commit is contained in:
2022-12-07 16:34:01 +08:00
parent 60cb32dc7e
commit 533073eb11
8 changed files with 630 additions and 149 deletions

View File

@@ -22,6 +22,7 @@ import org.nl.acs.device.service.*;
import org.nl.acs.device.service.dto.*;
import org.nl.acs.device_driver.DeviceDriverDefination;
import org.nl.acs.device_driver.ScannerDeviceDriver;
import org.nl.acs.device_driver.basedriver.slit_two_manipulator.SlitTwoManipulatorDeviceDriver;
import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver;
import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver;
import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver;
@@ -868,6 +869,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
throw new BadRequestException("未找到对应设备:" + device_code);
}
StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver;
SlitTwoManipulatorDeviceDriver slitTwoManipulatorDeviceDriver;
//检测站点
StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver;
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
@@ -926,6 +928,9 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
standardInspectSiteDeviceDriver.setBatch(batch);
device.setMaterial_type(material_type);
device.setBatch(batch);
} else if (device.getDeviceDriver() instanceof SlitTwoManipulatorDeviceDriver){
slitTwoManipulatorDeviceDriver = (SlitTwoManipulatorDeviceDriver) device.getDeviceDriver();
slitTwoManipulatorDeviceDriver.setDeviceStatus(form);
}
}

View File

@@ -99,6 +99,12 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
String device_code;
//0 无任务执行 1更新指令状态 2下发电气信号 3允许取货 允许放货 5放货完成
int now_steps_type = 0;
String notCreateTaskMessage = "";
String notCreateInstMessage = "";
String feedMessage = "";
@Override
public Device getDevice() {
@@ -180,11 +186,40 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
hongXiangConveyorDeviceDriver.writing("to_open_door", "1");
if (hongXiangConveyorDeviceDriver.getDoor() == 1 && hongXiangConveyorDeviceDriver.getAction() == 1 && hongXiangConveyorDeviceDriver.getError1() == 0) {
this.writing("to_command", "2");
this.setNow_steps_type(3);
}else {
if (this.getNow_steps_type() == 2){
feedMessage = "请检查烘箱door=1&&action==1&&error1=0";
}
}
} else {
this.writing("to_command", "2");
this.setNow_steps_type(3);
}
}
} else {
if (this.getNow_steps_type() == 2){
feedMessage = "请检查mode == 3 && action == 1 && move == 0 && task > 0";
}
}
//取货完成关闭烘箱门
if (mode == 3 && action == 2 && move == 1 && task > 0){
Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task));
if (ObjectUtil.isNotEmpty(inst2)) {
String start_device_code = inst2.getStart_device_code();
Device device = deviceAppService.findDeviceByCode(start_device_code);
HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver;
if (device.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) device.getDeviceDriver();
hongXiangConveyorDeviceDriver.writing("to_close_door", "1");
}
this.setNow_steps_type(4);
}
}else {
if (this.getNow_steps_type() == 3){
feedMessage = "请检查mode == 3 && action == 2 && move == 1 && task > 0";
}
}
//申请放货
@@ -198,9 +233,17 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
hongXiangConveyorDeviceDriver.writing("to_open_door", "1");
if (hongXiangConveyorDeviceDriver.getDoor() == 1 && hongXiangConveyorDeviceDriver.getAction() == 1 && hongXiangConveyorDeviceDriver.getError1() == 0) {
this.writing("to_command", "3");
this.setNow_steps_type(5);
}else {
feedMessage = "请检查烘箱door=1&&action==1&&error1=0";
}
} else {
this.writing("to_command", "3");
this.setNow_steps_type(5);
}
}else {
if (this.getNow_steps_type() == 4){
feedMessage = "请检查mode == 3 && action == 3 && move == 1 && task > 0";
}
}
@@ -226,24 +269,31 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
}
}
String next_device_code = taskDto.getNext_device_code();
String start_device_code = taskDto.getStart_device_code();
Device startDevice = deviceAppService.findDeviceByCode(start_device_code);
//String start_device_code = taskDto.getStart_device_code();
//Device startDevice = deviceAppService.findDeviceByCode(start_device_code);
Device nextDevice = deviceAppService.findDeviceByCode(next_device_code);
HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver;
if (startDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startDevice.getDeviceDriver();
hongXiangConveyorDeviceDriver.writing("to_close_door", "1");
}
// if (startDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
// hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startDevice.getDeviceDriver();
// hongXiangConveyorDeviceDriver.writing("to_close_door", "1");
// }
if (nextDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextDevice.getDeviceDriver();
hongXiangConveyorDeviceDriver.writing("to_close_door", "1");
}
this.writing("to_command", "0");
this.writing("to_onset", "0");
this.writing("to_target", "0");
this.writing("to_task", "0");
this.writing("to_command", "4");
this.setNow_steps_type(6);
this.setNow_steps_type(0);
feedMessage = "";
// this.writing("to_onset", "0");
// this.writing("to_target", "0");
// this.writing("to_task", "0");
}
}
}else {
if (this.getNow_steps_type() == 5){
feedMessage = "请检查mode == 3 && action == 4 && move == 0 && task > 0";
}
}
} catch (Exception var17) {
@@ -275,6 +325,20 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
//行架机械手申请任务
if (mode == 2 && move == 0 && task == 0 && !requireSucess) {
applyTask();
}else {
if (!requireSucess) {
String remark = "";
if (mode != 2) {
remark = remark + "mode不为2,";
}
if (move != 0) {
remark = remark + "move不为0,";
}
if (task != 0) {
remark = remark + "task不为0,";
}
this.setNotCreateTaskMessage(remark);
}
}
}
@@ -318,15 +382,13 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
String startDeviceCode = getDeviceCodeList.get(i);
List<TaskDto> taskDtos = taskserver.queryTaskByDeviceCodeAndStatus(startDeviceCode);
if (ObjectUtil.isNotEmpty(taskDtos)) {
//按照优先级排序 优先级相等按照创建时间排序
taskDtos = this.sortTask(taskDtos);
TaskDto taskDto = taskDtos.get(0);
Instruction instruction = instructionService.findByTaskcode(taskDto.getTask_code());
instruction.setInstruction_status("1");
instruction.setUpdate_time(DateUtil.now());
instructionService.update(instruction);
// int start_addrIndex = getDeviceCodeList.indexOf(instruction.getStart_device_code());
// int next_addrIndex = putDeviceCodeList.indexOf(instruction.getNext_device_code());
// writing("to_onset", String.valueOf(start_addrIndex + 1));
// writing("to_target", String.valueOf(next_addrIndex + 1));
Device startDevice = deviceAppService.findDeviceByCode(instruction.getStart_device_code());
Device nextDevice = deviceAppService.findDeviceByCode(instruction.getNext_device_code());
if (ObjectUtil.isEmpty(startDevice.getExtraValue().get("address"))){
@@ -341,11 +403,14 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
this.writing("to_target", next_addr);
this.writing("to_task", instruction.getInstruction_code());
this.writing("to_command", "1");
this.setNow_steps_type(2);
this.setRequireSucess(true);
return true;
} else {
List<TaskDto> taskDtoList = taskserver.queryTaskByDeviceCode(startDeviceCode);
if (ObjectUtil.isNotEmpty(taskDtoList)) {
//按照优先级排序 优先级相等按照创建时间排序
taskDtoList = this.sortTask(taskDtoList);
task = taskDtoList.get(0);
}
if (ObjectUtil.isNotEmpty(task)) break;
@@ -385,23 +450,22 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
try {
instructionService.create(instdto);
} catch (Exception e) {
notCreateInstMessage = e.getMessage();
e.printStackTrace();
return false;
}
//创建指令后修改任务状态
task.setTask_status("1");
task.setUpdate_time(DateUtil.now());
taskserver.update(task);
//根据获取托盘信息返回的结果 得到对应抓取工位/放货工位设备编码所在的索引位置
// int start_addrIndex = getDeviceCodeList.indexOf(start_device_code);
// int next_addrIndex = putDeviceCodeList.indexOf(next_device_code);
// writing("to_onset", String.valueOf(start_addrIndex + 1));
// writing("to_target", String.valueOf(next_addrIndex + 1));
Device startDevice = deviceAppService.findDeviceByCode(instdto.getStart_device_code());
Device nextDevice = deviceAppService.findDeviceByCode(instdto.getNext_device_code());
if (ObjectUtil.isEmpty(startDevice.getExtraValue().get("address"))){
notCreateInstMessage = "设备:" + startDevice.getDevice_code() + "未设置电气调度号!";
throw new BadRequestException("设备:" + startDevice.getDevice_code() + "未设置电气调度号!");
}
if (ObjectUtil.isEmpty(nextDevice.getExtraValue().get("address"))){
notCreateInstMessage = "设备:" + nextDevice.getDevice_code() + "未设置电气调度号!";
throw new BadRequestException("设备:" + nextDevice.getDevice_code() + "未设置电气调度号!");
}
String start_addr = startDevice.getExtraValue().get("address").toString();
@@ -410,7 +474,12 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
this.writing("to_target", next_addr);
this.writing("to_task", instdto.getInstruction_code());
this.writing("to_command", "1");
this.setNow_steps_type(2);
this.setRequireSucess(true);
notCreateInstMessage = "";
notCreateTaskMessage = "";
} else {
notCreateInstMessage = "未找到关联设备的任务,指令无法创建";
}
return true;
}
@@ -464,6 +533,23 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
return devicesList;
}
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 JSONObject getDeviceStatusName() {

View File

@@ -58,6 +58,9 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
//分切行架机械手是否禁用 0否 1是
private int is_disable = 0;
//工作模式
int mode = 0;
int last_mode = 0;
@@ -103,16 +106,33 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
int flag;
//前工位任务执行当前步骤
//0未执行 1更改指令状态 2下发电气任务信息 3前工位允许取货 4前工位允许放货 5放货完成
int now_steps_type1 = 0;
//后工位当前执行步骤
//0未执行 1更改指令状态 2下发电气任务信息 3后工位允许取货 4后工位允许放货 5放货完成
int now_steps_type2 = 0;
//双工位任务当前执行步骤
//0未执行 1更改指令状态 2下发电气任务信息 3后工位允许取货 4前工位允许取货 5后工位允许放货 6后工位放货完成 7前工位允许放货 8前工位放货完成
int now_steps_type3 = 0;
String device_code;
//请求超时时间
private int instruction_require_time_out = 3000;
//后工位申请任务请求时间
private Date instruction_require_time = new Date();
//前工位申请任务请求时间
private Date instruction_head_time = new Date();
String notCreateTaskMessage = "";
String notCreateInstMessage = "";
String feedMessage = "";
@Override
public Device getDevice() {
return this.device;
@@ -189,6 +209,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task1));
if (inst1 != null) {
if (StrUtil.equals(inst1.getInstruction_status(), "0")) {
//当前执行步骤为更新任务状态
inst1.setInstruction_status("1");
instructionService.update(inst1);
TaskDto taskDto = taskserver.findByCodeFromCache(inst1.getTask_code());
@@ -203,6 +224,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
}
}
;
//this.setNow_steps_type1(1);
}
}
}
@@ -213,6 +235,8 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task2));
if (inst2 != null) {
if (StrUtil.equals(inst2.getInstruction_status(), "0")) {
//当前指令更新状态
now_steps_type2 = 1;
inst2.setInstruction_status("1");
instructionService.update(inst2);
TaskDto taskDto = taskserver.findByCodeFromCache(inst2.getTask_code());
@@ -227,6 +251,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
}
}
;
// this.setNow_steps_type2(1);
}
}
}
@@ -237,6 +262,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task1));
if (inst2 != null) {
if (StrUtil.equals(inst2.getInstruction_status(), "0")) {
//当前指令更新状态
inst2.setInstruction_status("1");
instructionService.update(inst2);
TaskDto taskDto = taskserver.findByCodeFromCache(inst2.getTask_code());
@@ -251,6 +277,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
}
}
;
// this.setNow_steps_type3(1);
}
}
}
@@ -275,12 +302,18 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
}
;
this.writing("to_command1", "4");
this.setNow_steps_type1(5);
this.setNow_steps_type1(0);
// this.writing("to_onset1", "0");
// this.writing("to_target1", "0");
// this.writing("to_task1", "0");
// this.writing("to_type", "0");
}
}
} else {
if (this.getNow_steps_type1() == 4) {
feedMessage = "请检查:mode == 3 && action1 == 4 && move1 == 0 && task1 > 0 && type == 1";
}
}
//单任务 后工位放货完成 任务完成
@@ -303,17 +336,28 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
}
;
this.writing("to_command2", "4");
this.writing("to_onset2", "0");
this.writing("to_target2", "0");
this.writing("to_task2", "0");
this.writing("to_type", "0");
this.setNow_steps_type2(5);
this.setNow_steps_type2(0);
// this.writing("to_onset2", "0");
// this.writing("to_target2", "0");
// this.writing("to_task2", "0");
// this.writing("to_type", "0");
}
}
} else {
if (this.getNow_steps_type2() == 4) {
feedMessage = "请检查:mode == 3 && action2 == 4 && move2 == 0 && task2 > 0 && type == 2";
}
}
//双任务后工位反馈4
if (mode == 3 && action2 == 4 && move2 == 0 && task1 > 0 && task2 > 0 && type == 3 ){
if (mode == 3 && action2 == 4 && move2 == 0 && task1 > 0 && task2 > 0 && type == 3) {
this.writing("to_command2", "4");
this.setNow_steps_type3(6);
} else {
if (this.getNow_steps_type3() == 5) {
feedMessage = "请检查mode == 3 && action2 == 4 && move2 == 0 && task1 > 0 && task2 > 0 && type == 3";
}
}
//双工位 任务完成 前工位反馈4
@@ -333,8 +377,11 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
array.add(map);
acsToWmsService.feedbackTaskStatusToWms(array);
}
};
}
;
this.writing("to_command1", "4");
this.setNow_steps_type3(8);
this.setNow_steps_type3(0);
// this.writing("to_onset1", "0");
// this.writing("to_target1", "0");
// this.writing("to_task1", "0");
@@ -344,6 +391,10 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
// this.writing("to_type", "0");
}
}
} else {
if (this.getNow_steps_type3() == 7) {
feedMessage = "请检查mode == 3 && action1 == 4 && move1 == 0 && task1 > 0 && task2 > 0 && type == 3";
}
}
@@ -351,10 +402,10 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
if (mode == 3 && action2 == 1 && move2 == 0 && task2 > 0) {
Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task2));
String start_device_code = "";
if (type == 2){
if (type == 2) {
start_device_code = inst1.getStart_device_code();
}
if (type == 3){
if (type == 3) {
start_device_code = inst1.getStart_device_code2();
}
Device startDevice = deviceAppservice.findDeviceByCode(start_device_code);
@@ -365,20 +416,50 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
int mode = siemensConveyorDeviceDriver.getMode();
if (mode == 2 && move == 1) {
this.writing("to_command2", "2");
if (type == 2) {
this.setNow_steps_type2(3);
} else if (type == 3) {
this.setNow_steps_type3(3);
}
} else {
log.warn("前工位取货位无货,取货位:{},mode:{},move:{}", start_device_code, mode, move);
if (this.getNow_steps_type2() == 2 || this.getNow_steps_type3() == 2) {
feedMessage = "请检查输送线mode == 2 && move == 1";
}
}
}
} else {
if (this.getNow_steps_type2() == 2 || this.getNow_steps_type3() == 2) {
feedMessage = "请检查mode == 3 && action2 == 1 && move2 == 0 && task2 > 0";
}
}
//后工位允许放货
if (mode == 3 && action2 == 3 && move2 == 1 && task2 > 0) {
this.writing("to_command2", "3");
if (type == 2) {
this.setNow_steps_type2(4);
} else if (type == 3) {
this.setNow_steps_type3(5);
}
} else {
if (this.getNow_steps_type2() == 3 || this.getNow_steps_type3() == 4) {
feedMessage = "请检查mode == 3 && action2 == 3 && move2 == 1 && task2 > 0";
}
}
//前工位允许取货
if (mode == 3 && action1 == 1 && move1 == 0 && task1 > 0) {
this.writing("to_command1", "2");
if (type == 1) {
this.setNow_steps_type1(3);
} else if (type == 2) {
this.setNow_steps_type3(4);
}
} else {
if (this.getNow_steps_type1() == 2 || this.getNow_steps_type3() == 3) {
feedMessage = "请检查mode == 3 && action1 == 1 && move1 == 0 && task1 > 0";
}
}
//前工位放货时判断放货位光电信号
@@ -393,10 +474,22 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
int mode = siemensConveyorDeviceDriver.getMode();
if (move == 0 && mode == 2) {
this.writing("to_command1", "3");
if (type == 1) {
this.setNow_steps_type1(4);
} else if (type == 2) {
this.setNow_steps_type3(7);
}
} else {
log.warn("后工位放货位有货,放货位:{},mode:{},move:{}", next_device_code, mode, move);
if (this.getNow_steps_type1() == 3 || this.getNow_steps_type3() == 6) {
feedMessage = "请检查输送线move == 0 && mode == 2";
}
}
}
} else {
if (this.getNow_steps_type1() == 3 || this.getNow_steps_type3() == 6) {
feedMessage = "请检查mode == 3 && action1 == 3 && move1 == 1 && task1 > 0";
}
}
} catch (Exception var17) {
@@ -428,8 +521,58 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
case 2:
//申请任务
if (mode == 2 && move1 == 0 && move2 == 0 && action1 == 0 && action2 == 0 && task1 == 0 && task2 == 0 && !requireSucess) {
//获取关联设备驱动信息 判断关联设备是否禁用
Device device = deviceAppservice.findDeviceByCode(device_code);
SlitTwoManipulatorDeviceDriver slitTwoManipulatorDeviceDriver;
if (device.getDeviceDriver() instanceof SlitTwoManipulatorDeviceDriver) {
slitTwoManipulatorDeviceDriver = (SlitTwoManipulatorDeviceDriver) device.getDeviceDriver();
//如果禁用
if (slitTwoManipulatorDeviceDriver.getIs_disable() == 1) {
boolean flag = false;
try {
//就去走关联设备异常取放货工位的任务 任务生成成功返回true 就不会走下面正常生成任务的逻辑
flag = instruction_require2();
} catch (Exception e) {
flag = false;
}
if (flag) {
break;
}
}
}
//没有生成异常取放货工位的任务 就生成正常关联取放货工位的任务
instruction_require();
feedMessage = "";
logServer.deviceExecuteLog(device_code, "", String.valueOf(task1), "move2:" + move2 + ",action2:" + action2 + ",move1:" + move1 + ",action1:" + action1 + ",requireSucess:" + requireSucess);
} else {
// if (!requireSucess) {
// remark = remark + "请求标记为true,请检查mode是否由其他值变为2";
// }
if (!requireSucess) {
String remark = "";
if (mode != 2) {
remark = remark + "mode不为2,";
}
if (move1 != 0) {
remark = remark + "move1不为0,";
}
if (move2 != 0) {
remark = remark + "move2不为0,";
}
if (action1 != 0) {
remark = remark + "action1不为0,";
}
if (action2 != 0) {
remark = remark + "action2不为0,";
}
if (task1 != 0) {
remark = remark + "task1不为0,";
}
if (task2 != 0) {
remark = remark + "task2不为0,";
}
this.setNotCreateTaskMessage(remark);
}
}
break;
case 3:
@@ -450,8 +593,82 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
last_task2 = task2;
}
//申请任务
//关联设备异常申请任务
public synchronized boolean instruction_require2() {
Boolean flag = false;
Date date = new Date();
if (date.getTime() - this.instruction_head_time.getTime() < (long) this.instruction_require_time_out) {
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_head_time);
return false;
} else {
this.instruction_head_time = date;
//前工位取货关联设备
List<String> getDeviceCodeList = this.getExtraDeviceCodes("error_head_get_device_code");
//后工位取货关联设备
List<String> backGetDeviceCodeList = this.getExtraDeviceCodes("error_back_get_device_code");
TaskDto taskDto = null;
//遍历前工位取货点设备
for (String getDeviceCode : getDeviceCodeList) {
//去任务表中查询是否有前工位关联设备的重新创建指令的任务
List<TaskDto> taskDtos = taskserver.queryTaskByStartAndIntStatus(getDeviceCode);
//如果有
if (ObjectUtil.isNotEmpty(taskDtos)) {
//按照优先级排序 优先级相等按照创建时间排序
taskDtos = this.sortTask(taskDtos);
taskDto = taskDtos.get(0);
flag = this.executeBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList);
return flag;
} else {
//去任务表中查询是否有前工位关联设备的就绪状态下的任务
taskDtos = taskserver.queryTaskByStartDeviceCode(getDeviceCode);
if (ObjectUtil.isNotEmpty(taskDtos)) {
//按照优先级排序 优先级相等按照创建时间排序
taskDtos = this.sortTask(taskDtos);
taskDto = taskDtos.get(0);
break;
}
}
}
//如果任务表中起点1或起点2中 无前工位取货点关联设备
//就去查询任务表中查找起点1或起点2为后工位取货点关联设备的任务
if (ObjectUtil.isEmpty(taskDto)) {
for (String backGetDeviceCode : backGetDeviceCodeList) {
//去任务表中查询是否有前工位关联设备的重新创建指令的任务
List<TaskDto> taskDtos = taskserver.queryTaskByNextAndIntStatus(backGetDeviceCode);
if (ObjectUtil.isNotEmpty(taskDtos)) {
//按照优先级排序 优先级相等按照创建时间排序
taskDtos = this.sortTask(taskDtos);
taskDto = taskDtos.get(0);
flag = this.executeBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList);
return flag;
} else {
//去任务表中查询是否有后工位关联设备的就绪状态下的任务
taskDtos = taskserver.queryTaskByStartDeviceCode(backGetDeviceCode);
if (ObjectUtil.isNotEmpty(taskDtos)) {
//按照优先级排序 优先级相等按照创建时间排序
taskDtos = this.sortTask(taskDtos);
taskDto = taskDtos.get(0);
break;
}
}
}
}
if (!ObjectUtil.isEmpty(taskDto)) {
flag = this.executeReadyBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList);
if (flag) {
notCreateInstMessage = "";
}
} else {
notCreateTaskMessage = "";
notCreateInstMessage = "未找到关联设备禁用的任务!";
}
}
return flag;
}
//正常申请任务
public synchronized boolean instruction_require() {
boolean flag = false;
Date date = new Date();
if (date.getTime() - this.instruction_head_time.getTime() < (long) this.instruction_require_time_out) {
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_head_time);
@@ -469,13 +686,17 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
List<TaskDto> taskDtos = taskserver.queryTaskByStartAndIntStatus(getDeviceCode);
//如果有
if (ObjectUtil.isNotEmpty(taskDtos)) {
//按照优先级排序 优先级相等按照创建时间排序
taskDtos = this.sortTask(taskDtos);
taskDto = taskDtos.get(0);
this.executeBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList);
return true;
flag = this.executeBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList);
return flag;
} else {
//去任务表中查询是否有前工位关联设备的就绪状态下的任务
taskDtos = taskserver.queryTaskByStartDeviceCode(getDeviceCode);
if (ObjectUtil.isNotEmpty(taskDtos)) {
//按照优先级排序 优先级相等按照创建时间排序
taskDtos = this.sortTask(taskDtos);
taskDto = taskDtos.get(0);
break;
}
@@ -488,28 +709,40 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
//去任务表中查询是否有前工位关联设备的重新创建指令的任务
List<TaskDto> taskDtos = taskserver.queryTaskByNextAndIntStatus(backGetDeviceCode);
if (ObjectUtil.isNotEmpty(taskDtos)) {
//按照优先级排序 优先级相等按照创建时间排序
taskDtos = this.sortTask(taskDtos);
taskDto = taskDtos.get(0);
this.executeBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList);
return true;
flag = this.executeBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList);
return flag;
} else {
//去任务表中查询是否有后工位关联设备的就绪状态下的任务
taskDtos = taskserver.queryTaskByStartDeviceCode(backGetDeviceCode);
if (ObjectUtil.isNotEmpty(taskDtos)) {
//按照优先级排序 优先级相等按照创建时间排序
taskDtos = this.sortTask(taskDtos);
taskDto = taskDtos.get(0);
break;
}
}
}
}
if (!ObjectUtil.isEmpty(taskDto)) {
this.executeReadyBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList);
flag = this.executeReadyBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList);
if (flag) {
notCreateInstMessage = "";
}
} else {
notCreateTaskMessage = "";
notCreateInstMessage = "未找到正常关联设备的任务!";
}
}
return true;
return flag;
}
//执行重新生成指令的任务
public void executeBusiness(TaskDto taskDto, List<String> getDeviceCodeList, List<String> backGetDeviceCodeList) {
public synchronized boolean executeBusiness(TaskDto taskDto, List<String> getDeviceCodeList, List<String> backGetDeviceCodeList) {
boolean flag = false;
//任务类型 1.前工位任务 2.后工位任务 3.双工位任务
String type = "";
//获取指令信息
@@ -552,17 +785,33 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
//修改指令状态
instructionDto.setInstruction_status("1");
instructionDto.setUpdate_time(DateUtil.now());
instructionService.update(instructionDto);
try {
instructionService.update(instructionDto);
if (StrUtil.equals(type, "1")) {
this.setNow_steps_type1(1);
}
if (StrUtil.equals(type, "2")) {
this.setNow_steps_type2(1);
}
if (StrUtil.equals(type, "3")) {
this.setNow_steps_type3(1);
}
flag = true;
} catch (Exception e) {
logServer.deviceExecuteLog(device_code, "", instructionDto.getInstruction_code(), "执行重新生成指令的任务失败,原因->" + e.getMessage());
}
//下发电气信号
this.sendSignalType(instructionDto, type);
//请求任务成功
this.setRequireSucess(true);
return flag;
}
//执行就绪状态下的任务
public void executeReadyBusiness(TaskDto taskDto, List<String> getDeviceCodeList, List<String> backGetDeviceCodeList) {
public synchronized boolean executeReadyBusiness(TaskDto taskDto, List<String> getDeviceCodeList, List<String> backGetDeviceCodeList) {
boolean flag = false;
//任务类型 1.前工位任务 2.后工位任务 3.双工位任务
String type = "";
//获取任务表中的取货点1
@@ -639,8 +888,9 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
try {
instructionService.create(instdto);
flag = true;
} catch (Exception e) {
e.printStackTrace();
notCreateInstMessage = e.getMessage();
logServer.deviceExecuteLog(device_code, "", instdto.getInstruction_code(), "指令创建失败,原因->" + e.getMessage());
}
@@ -654,10 +904,11 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
//请求任务成功
this.setRequireSucess(true);
return flag;
}
//下发电气信号
public void sendSignalType(Instruction dto, String type) {
public synchronized void sendSignalType(Instruction dto, String type) {
String start_device_code = dto.getStart_device_code();
String next_device_code = dto.getNext_device_code();
Device startDevice = deviceAppservice.findDeviceByCode(start_device_code);
@@ -670,12 +921,14 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
this.writing("to_task1", dto.getInstruction_code());
this.writing("to_command1", "1");
this.writing("to_type", "1");
this.setNow_steps_type1(2);
} else if (StrUtil.equals(type, "2")) {
this.writing("to_onset2", start_addr);
this.writing("to_target2", next_addr);
this.writing("to_task2", dto.getInstruction_code());
this.writing("to_command2", "1");
this.writing("to_type", "2");
this.setNow_steps_type2(2);
} else if (StrUtil.equals(type, "3")) {
String start_device_code2 = dto.getStart_device_code2();
String next_device_code2 = dto.getNext_device_code2();
@@ -692,6 +945,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
this.writing("to_task2", dto.getInstruction_code());
this.writing("to_command2", "1");
this.writing("to_type", "3");
this.setNow_steps_type3(2);
}
}
@@ -699,6 +953,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
public void isSetAddress(Device device) {
if (ObjectUtil.isEmpty(device.getExtraValue().get("address"))) {
logServer.deviceExecuteLog(device_code, "", "task1:" + task1 + ",task2:" + task2, "设备:" + device.getDevice_code() + "未设置电气调度号!");
notCreateInstMessage = "设备:" + device.getDevice_code() + "未设置电气调度号!";
throw new BadRequestException("设备:" + device.getDevice_code() + "未设置电气调度号!");
}
}
@@ -795,16 +1050,35 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
return devicesList;
}
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 JSONObject getDeviceStatusName() {
JSONObject jo = new JSONObject();
String move1 = "";
String move2 = "";
String move_1 = "";
String move_2 = "";
String action1 = "";
String action2 = "";
String walk_y = "";
String mode = "";
String status = "";
String is_disable = "";
if (this.getMode() == 0) {
mode = "脱机";
@@ -816,7 +1090,9 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
mode = "运行中";
}
if (this.getStatus() == 1) {
if (this.getStatus() == 0) {
status = "0";
} else if (this.getStatus() == 1) {
status = "待机";
} else if (this.getStatus() == 2) {
status = "生产中";
@@ -825,15 +1101,15 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
}
if (this.getMove1() == 0) {
move1 = "无货";
move_1 = "无货";
} else if (this.getMove1() == 1) {
move1 = "有货";
move_1 = "有货";
}
if (this.getMove2() == 0) {
move2 = "无货";
move_2 = "无货";
} else if (this.getMove2() == 1) {
move2 = "有货";
move_2 = "有货";
}
if (this.getAction1() == 1) {
@@ -862,25 +1138,41 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
walk_y = "非原位";
}
if (this.getIs_disable() == 0) {
is_disable = "正常";
} else if (this.getIs_disable() == 1) {
is_disable = "禁用";
}
jo.put("device_name", this.getDevice().getDevice_name());
jo.put("mode", mode);
jo.put("status", status);
jo.put("move1", move1);
jo.put("move2", move2);
jo.put("action1", action1);
jo.put("action2", action2);
jo.put("move_1", move_1);
jo.put("move_2", move_2);
jo.put("action_1", action1);
jo.put("action_2", action2);
jo.put("walk_y", walk_y);
jo.put("error", this.getError());
jo.put("task1", this.getTask1());
jo.put("task2", this.getTask2());
jo.put("isOnline", this.getIsonline());
jo.put("isError", this.getIserror());
jo.put("is_disable1", this.getIs_disable());
jo.put("is_disable", is_disable);
jo.put("message", this.getMessage());
jo.put("is_click", true);
jo.put("driver_type", "slit_two_manipulator");
jo.put("notCreateTaskMessage", notCreateTaskMessage);
jo.put("notCreateInstMessage", notCreateInstMessage);
jo.put("feedMessage", feedMessage);
return jo;
}
@Override
public void setDeviceStatus(JSONObject data) {
String is_disable = data.getString("is_disable");
if (StrUtil.isNotEmpty(is_disable)) {
this.setIs_disable(Integer.parseInt(is_disable));
}
}
}