更新 分切
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
package org.nl.acs.device_driver.basedriver.slit_two_manipulator;
|
||||
|
||||
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.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -8,6 +13,7 @@ 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.RouteableDeviceDriver;
|
||||
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.ext.wms.service.AcsToWmsService;
|
||||
@@ -20,6 +26,7 @@ import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.opc.DeviceAppServiceImpl;
|
||||
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.modules.wql.util.SpringContextHolder;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -83,7 +90,6 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
|
||||
int last_task2 = 0;
|
||||
|
||||
|
||||
|
||||
Boolean isonline = true;
|
||||
//后工位申请任务请求标记
|
||||
Boolean requireBackSucess = false;
|
||||
@@ -104,6 +110,11 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
|
||||
//请求超时时间
|
||||
private int instruction_require_time_out = 3000;
|
||||
|
||||
//后工位申请任务请求时间
|
||||
private Date instruction_require_time = new Date();
|
||||
//前工位申请任务请求时间
|
||||
private Date instruction_head_time = new Date();
|
||||
|
||||
@Override
|
||||
public Device getDevice() {
|
||||
return this.device;
|
||||
@@ -167,6 +178,139 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号task2:" + last_task2 + "->" + task2);
|
||||
}
|
||||
|
||||
//前工位任务就绪->执行
|
||||
if (task1 > 0) {
|
||||
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.findByCode(inst1.getTask_code());
|
||||
JSONArray array = new JSONArray();
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("task_id", taskDto.getExt_task_id());
|
||||
map.put("task_status", "1");
|
||||
array.add(map);
|
||||
acsToWmsService.feedbackTaskStatusToWms(array);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//前工位放货完成 任务完成
|
||||
if (action1 == 4 && move1 == 0 && task1 > 0) {
|
||||
//inst_message
|
||||
Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task1));
|
||||
if (inst1 != null) {
|
||||
if (StrUtil.equals(inst1.getInstruction_status(), "1")) {
|
||||
finish_instruction(inst1);
|
||||
JSONArray array = new JSONArray();
|
||||
TaskDto taskDto = taskserver.findByCode(inst1.getTask_code());
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("task_id", taskDto.getExt_task_id());
|
||||
map.put("task_status", "2");
|
||||
map.put("finished_type", "1");
|
||||
array.add(map);
|
||||
acsToWmsService.feedbackTaskStatusToWms(array);
|
||||
writing("to_command1", "0");
|
||||
writing("to_onset1", "0");
|
||||
writing("to_target1", "0");
|
||||
writing("to_task1", "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//后工位任务就绪->执行
|
||||
if (task2 > 0) {
|
||||
//inst_message
|
||||
Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task2));
|
||||
if (inst2 != null) {
|
||||
if (StrUtil.equals(inst2.getInstruction_status(), "0")) {
|
||||
inst2.setInstruction_status("1");
|
||||
instructionService.update(inst2);
|
||||
TaskDto taskDto = taskserver.findByCode(inst2.getTask_code());
|
||||
JSONArray array = new JSONArray();
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("task_id", taskDto.getExt_task_id());
|
||||
map.put("task_status", "1");
|
||||
array.add(map);
|
||||
acsToWmsService.feedbackTaskStatusToWms(array);
|
||||
}
|
||||
}
|
||||
}
|
||||
//后工位放货完成 任务完成
|
||||
if (action2 == 4 && move2 == 0 && task2 > 0) {
|
||||
//inst_message
|
||||
Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task2));
|
||||
if (inst2 != null) {
|
||||
if (StrUtil.equals(inst2.getInstruction_status(), "1")) {
|
||||
finish_instruction(inst2);
|
||||
JSONArray array = new JSONArray();
|
||||
TaskDto taskDto = taskserver.findByCode(inst1.getTask_code());
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("task_id", taskDto.getExt_task_id());
|
||||
map.put("task_status", "2");
|
||||
map.put("finished_type", "1");
|
||||
array.add(map);
|
||||
acsToWmsService.feedbackTaskStatusToWms(array);
|
||||
writing("to_command2", "0");
|
||||
writing("to_onset2", "0");
|
||||
writing("to_target2", "0");
|
||||
writing("to_task2", "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//双任务 - 前工位取货时判断取货位光电信号
|
||||
if (mode == 3 && action1 == 1 && move1 == 0 && task1 > 0 && task2 > 0) {
|
||||
Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task1));
|
||||
String start_device_code = inst1.getStart_device_code();
|
||||
Device startDevice = deviceAppservice.findDeviceByCode(start_device_code);
|
||||
SiemensConveyorDeviceDriver siemensConveyorDeviceDriver;
|
||||
if (startDevice.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) {
|
||||
siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) startDevice.getDeviceDriver();
|
||||
int move = siemensConveyorDeviceDriver.getMove();
|
||||
int mode = siemensConveyorDeviceDriver.getMode();
|
||||
if (mode == 2 && move == 1) {
|
||||
this.writing("to_command1", "2");
|
||||
} else {
|
||||
log.warn("前工位取货位无货,取货位:{},mode:{},move:{}", start_device_code, mode, move);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//单任务 - 前工位直接允许取货
|
||||
if (mode == 3 && action1 == 1 && move1 == 0 && task1 > 0 && task2 == 0) {
|
||||
this.writing("to_command1", "2");
|
||||
}
|
||||
|
||||
//前工位放货时判断放货位光电信号
|
||||
if (mode == 3 && action1 == 3 && move1 == 1 && task1 > 0) {
|
||||
this.writing("to_command1", "3");
|
||||
}
|
||||
|
||||
//后工位取货时判断取货位光电信号
|
||||
if (mode == 3 && action2 == 2 && move2 == 0 && task2 > 0) {
|
||||
this.writing("to_command2", "2");
|
||||
}
|
||||
|
||||
//后工位放货时判断放货位光电信号
|
||||
if (mode == 3 && action2 == 3 && move2 == 1 && task2 > 0) {
|
||||
Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task2));
|
||||
String next_device_code = inst1.getNext_device_code();
|
||||
Device nextDevice = deviceAppservice.findDeviceByCode(next_device_code);
|
||||
SiemensConveyorDeviceDriver siemensConveyorDeviceDriver;
|
||||
if (nextDevice.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) {
|
||||
siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) nextDevice.getDeviceDriver();
|
||||
int move = siemensConveyorDeviceDriver.getMove();
|
||||
int mode = siemensConveyorDeviceDriver.getMode();
|
||||
if (move == 0 && mode == 2) {
|
||||
this.writing("to_command2", "3");
|
||||
} else {
|
||||
log.warn("后工位放货位有货,放货位:{},mode:{},moce:{}", next_device_code, mode, move);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception var17) {
|
||||
return;
|
||||
}
|
||||
@@ -192,7 +336,29 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
|
||||
message = "";
|
||||
Instruction instruction = null;
|
||||
List toInstructions;
|
||||
|
||||
switch (mode) {
|
||||
case 1:
|
||||
log.debug("设备运转模式:等待工作");
|
||||
return;
|
||||
case 2:
|
||||
//前工位申请任务 取空放空
|
||||
if (move1 == 0 && action1 == 0 && !requireHeadSucess) {
|
||||
instruction_require();
|
||||
logServer.deviceExecuteLog(device_code, "", String.valueOf(task1), "move1:" + move1 + ",action1:" + action1 + ",move2:" + move2 + ",task1:" + task1 + ",requireHeadSucess:" + requireHeadSucess);
|
||||
}
|
||||
//后工位申请任务 取满放满
|
||||
if (move2 == 0 && action2 == 0 && task2 == 0 && move1 == 0 && task1 > 0 && !requireBackSucess) {
|
||||
instruction_require2();
|
||||
logServer.deviceExecuteLog(device_code, "", String.valueOf(task1), "move2:" + move2 + ",action2:" + action2 + ",move1:" + move1 + ",task2:" + task2 + ",requireBackSucess:" + requireBackSucess);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
//后工位申请任务 取满放满
|
||||
if (task1 > 0 && move1 == 1 && action1 == 1 && move2 == 0 && action2 == 0 && !requireBackSucess) {
|
||||
instruction_require2();
|
||||
logServer.deviceExecuteLog(device_code, "", String.valueOf(task1), "move2:" + move2 + ",action2:" + action2 + ",move1:" + move1 + ",task2:" + task2 + ",requireBackSucess:" + requireBackSucess);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
last_mode = mode;
|
||||
@@ -207,6 +373,195 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
|
||||
last_task2 = task2;
|
||||
}
|
||||
|
||||
//申请前工位任务
|
||||
public synchronized boolean instruction_require() throws Exception {
|
||||
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("head_get_device_code");
|
||||
//后工位放货关联设备
|
||||
List<String> putDeviceCodeList = this.getExtraDeviceCodes("head_put_device_code");
|
||||
TaskDto task = null;
|
||||
for (int i = 0; i < getDeviceCodeList.size(); i++) {
|
||||
String startDeviceCode = getDeviceCodeList.get(i);
|
||||
List<TaskDto> taskDtos = taskserver.queryTaskByDeviceCodeAndStatus(startDeviceCode);
|
||||
if (ObjectUtil.isNotEmpty(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());
|
||||
this.writing("to_onset1", String.valueOf(start_addrIndex));
|
||||
this.writing("to_target1", String.valueOf(next_addrIndex));
|
||||
this.writing("to_task1", instruction.getInstruction_code());
|
||||
this.writing("to_command1", "1");
|
||||
requireHeadSucess = true;
|
||||
return true;
|
||||
} else {
|
||||
List<TaskDto> taskDtoList = taskserver.queryTaskByDeviceCode(startDeviceCode);
|
||||
if (ObjectUtil.isNotEmpty(taskDtoList)) {
|
||||
task = taskDtoList.get(0);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(task)) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ObjectUtil.isEmpty(task)) {
|
||||
String taskid = task.getTask_id();
|
||||
String taskcode = task.getTask_code();
|
||||
String vehiclecode = task.getVehicle_code();
|
||||
String priority = task.getPriority();
|
||||
String start_point_code = task.getStart_point_code();
|
||||
String start_device_code = task.getStart_device_code();
|
||||
String route_plan_code = task.getRoute_plan_code();
|
||||
String next_point_code = task.getNext_point_code();
|
||||
String next_device_code = task.getNext_device_code();
|
||||
|
||||
Instruction instdto = new Instruction();
|
||||
instdto.setInstruction_id(IdUtil.simpleUUID());
|
||||
instdto.setRoute_plan_code(route_plan_code);
|
||||
instdto.setRemark(task.getRemark());
|
||||
instdto.setMaterial(task.getMaterial());
|
||||
instdto.setQuantity(task.getQuantity());
|
||||
instdto.setTask_id(taskid);
|
||||
instdto.setTask_code(taskcode);
|
||||
instdto.setVehicle_code(vehiclecode);
|
||||
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);
|
||||
|
||||
try {
|
||||
instructionService.create(instdto);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//创建指令后修改任务状态
|
||||
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);
|
||||
this.writing("to_onset1", String.valueOf(start_addrIndex));
|
||||
this.writing("to_target1", String.valueOf(next_addrIndex));
|
||||
this.writing("to_task1", instdto.getInstruction_code());
|
||||
this.writing("to_command1", "1");
|
||||
requireHeadSucess = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//申请后工位任务
|
||||
public synchronized boolean instruction_require2() throws Exception {
|
||||
Date date = new Date();
|
||||
if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) {
|
||||
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time);
|
||||
return false;
|
||||
} else {
|
||||
this.instruction_require_time = date;
|
||||
|
||||
//后工位取货关联设备
|
||||
List<String> getDeviceCodeList = this.getExtraDeviceCodes("back_get_device_code");
|
||||
//后工位放货关联设备
|
||||
List<String> putDeviceCodeList = this.getExtraDeviceCodes("back_put_device_code");
|
||||
|
||||
TaskDto task = null;
|
||||
for (int i = 0; i < getDeviceCodeList.size(); i++) {
|
||||
String startDeviceCode = getDeviceCodeList.get(i);
|
||||
List<TaskDto> taskDtos = taskserver.queryTaskByDeviceCodeAndStatus(startDeviceCode);
|
||||
if (ObjectUtil.isNotEmpty(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());
|
||||
this.writing("to_onset2", String.valueOf(start_addrIndex));
|
||||
this.writing("to_target2", String.valueOf(next_addrIndex));
|
||||
this.writing("to_task2", instruction.getInstruction_code());
|
||||
this.writing("to_command2", "1");
|
||||
requireBackSucess = true;
|
||||
return true;
|
||||
} else {
|
||||
List<TaskDto> taskDtoList = taskserver.queryTaskByDeviceCode(startDeviceCode);
|
||||
if (ObjectUtil.isNotEmpty(taskDtoList)) {
|
||||
task = taskDtoList.get(0);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(task)) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ObjectUtil.isEmpty(task)) {
|
||||
String taskid = task.getTask_id();
|
||||
String taskcode = task.getTask_code();
|
||||
String vehiclecode = task.getVehicle_code();
|
||||
String priority = task.getPriority();
|
||||
String start_point_code = task.getStart_point_code();
|
||||
String start_device_code = task.getStart_device_code();
|
||||
String route_plan_code = task.getRoute_plan_code();
|
||||
String next_point_code = task.getNext_point_code();
|
||||
String next_device_code = task.getNext_device_code();
|
||||
|
||||
Instruction instdto = new Instruction();
|
||||
instdto.setInstruction_id(IdUtil.simpleUUID());
|
||||
instdto.setRoute_plan_code(route_plan_code);
|
||||
instdto.setRemark(task.getRemark());
|
||||
instdto.setMaterial(task.getMaterial());
|
||||
instdto.setQuantity(task.getQuantity());
|
||||
instdto.setTask_id(taskid);
|
||||
instdto.setTask_code(taskcode);
|
||||
instdto.setVehicle_code(vehiclecode);
|
||||
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);
|
||||
|
||||
try {
|
||||
instructionService.create(instdto);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//创建指令后修改任务状态
|
||||
task.setTask_status("1");
|
||||
taskserver.update(task);
|
||||
|
||||
//根据查询的任务起始点位 得出取放工位的索引值 写入后工位电气中
|
||||
int start_addrIndex = getDeviceCodeList.indexOf(start_device_code);
|
||||
int next_addrIndex = putDeviceCodeList.indexOf(next_device_code);
|
||||
this.writing("to_onset2", String.valueOf(start_addrIndex));
|
||||
this.writing("to_target2", String.valueOf(next_addrIndex));
|
||||
this.writing("to_task2", instdto.getInstruction_code());
|
||||
this.writing("to_command2", "1");
|
||||
requireBackSucess = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean exe_error() {
|
||||
if (this.error == 0) {
|
||||
@@ -289,7 +644,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
|
||||
}
|
||||
|
||||
//将扩展表中的字符串数组数据转换成集合
|
||||
public List<String> getExtraDeviceCodes(String extraName){
|
||||
public List<String> getExtraDeviceCodes(String extraName) {
|
||||
String extraValue = (String) this.getDevice().getExtraValue().get(extraName);
|
||||
String devicesString = extraValue.substring(1, extraValue.length() - 1);
|
||||
List<String> devicesList = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user