This commit is contained in:
2022-12-07 19:09:31 +08:00
parent 13dc4bfddc
commit 3cb3066f38
4 changed files with 118 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
package org.nl.acs.device_driver.basedriver.box_palletizing_manipulator;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.RequiredArgsConstructor;
@@ -218,6 +219,9 @@ public class BoxPalletizingManipulatorDeviceDriver extends AbstractOpcDeviceDriv
//将扩展表中的字符串数据转换成集合
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(",");

View File

@@ -1,6 +1,7 @@
package org.nl.acs.device_driver.basedriver.hongxiang_device;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
@@ -28,10 +29,7 @@ import org.nl.modules.wql.util.SpringContextHolder;
import org.openscada.opc.lib.da.Server;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* 烘箱对接位
@@ -226,6 +224,22 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple
ReadUtil.write(itemMap, server);
}
//将扩展表中的字符串数据转换成集合
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 void writing(String param, String value) {
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()

View File

@@ -160,8 +160,8 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
inst1.setInstruction_status("1");
instructionService.update(inst1);
TaskDto taskDto = taskserver.findByCodeFromCache(inst1.getTask_code());
if (ObjectUtil.isNotEmpty(taskDto)){
if (StrUtil.isNotEmpty(taskDto.getExt_task_id())){
if (ObjectUtil.isNotEmpty(taskDto)) {
if (StrUtil.isNotEmpty(taskDto.getExt_task_id())) {
JSONArray array = new JSONArray();
JSONObject map = new JSONObject();
map.put("task_id", taskDto.getExt_task_id());
@@ -187,8 +187,8 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
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){
} else {
if (this.getNow_steps_type() == 2) {
feedMessage = "请检查烘箱door=1&&action==1&&error1=0";
}
}
@@ -198,13 +198,13 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
}
}
} else {
if (this.getNow_steps_type() == 2){
if (this.getNow_steps_type() == 2) {
feedMessage = "请检查mode == 3 && action == 1 && move == 0 && task > 0";
}
}
//取货完成关闭烘箱门
if (mode == 3 && action == 2 && move == 1 && 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();
@@ -216,8 +216,8 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
}
this.setNow_steps_type(4);
}
}else {
if (this.getNow_steps_type() == 3){
} else {
if (this.getNow_steps_type() == 3) {
feedMessage = "请检查mode == 3 && action == 2 && move == 1 && task > 0";
}
}
@@ -234,15 +234,15 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
if (hongXiangConveyorDeviceDriver.getDoor() == 1 && hongXiangConveyorDeviceDriver.getAction() == 1 && hongXiangConveyorDeviceDriver.getError1() == 0) {
this.writing("to_command", "3");
this.setNow_steps_type(5);
}else {
} 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){
} else {
if (this.getNow_steps_type() == 4) {
feedMessage = "请检查mode == 3 && action == 3 && move == 1 && task > 0";
}
}
@@ -258,8 +258,8 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
e.printStackTrace();
}
TaskDto taskDto = taskserver.findByCode(inst2.getTask_code());
if (ObjectUtil.isNotEmpty(taskDto)){
if (StrUtil.isNotEmpty(taskDto.getExt_task_id())){
if (ObjectUtil.isNotEmpty(taskDto)) {
if (StrUtil.isNotEmpty(taskDto.getExt_task_id())) {
JSONArray array = new JSONArray();
JSONObject map = new JSONObject();
map.put("task_id", taskDto.getTask_id());
@@ -290,8 +290,8 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
// this.writing("to_task", "0");
}
}
}else {
if (this.getNow_steps_type() == 5){
} else {
if (this.getNow_steps_type() == 5) {
feedMessage = "请检查mode == 3 && action == 4 && move == 0 && task > 0";
}
}
@@ -325,7 +325,7 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
//行架机械手申请任务
if (mode == 2 && move == 0 && task == 0 && !requireSucess) {
applyTask();
}else {
} else {
if (!requireSucess) {
String remark = "";
if (mode != 2) {
@@ -386,15 +386,23 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
taskDtos = this.sortTask(taskDtos);
TaskDto taskDto = taskDtos.get(0);
Instruction instruction = instructionService.findByTaskcode(taskDto.getTask_code());
String start_device_code = instruction.getStart_device_code();
String next_device_code = instruction.getNext_device_code();
//判断关联的同一列烘箱设备是否都关门 都关门返回false有一个不关门就返回true
boolean isCloseDoor = this.judgeCloseDoor(start_device_code,next_device_code);
//未关门结束
if (isCloseDoor){
return false;
}
instruction.setInstruction_status("1");
instruction.setUpdate_time(DateUtil.now());
instructionService.update(instruction);
Device startDevice = deviceAppService.findDeviceByCode(instruction.getStart_device_code());
Device nextDevice = deviceAppService.findDeviceByCode(instruction.getNext_device_code());
if (ObjectUtil.isEmpty(startDevice.getExtraValue().get("address"))){
Device startDevice = deviceAppService.findDeviceByCode(start_device_code);
Device nextDevice = deviceAppService.findDeviceByCode(next_device_code);
if (ObjectUtil.isEmpty(startDevice.getExtraValue().get("address"))) {
throw new BadRequestException("设备:" + startDevice.getDevice_code() + "未设置电气调度号!");
}
if (ObjectUtil.isEmpty(nextDevice.getExtraValue().get("address"))){
if (ObjectUtil.isEmpty(nextDevice.getExtraValue().get("address"))) {
throw new BadRequestException("设备:" + nextDevice.getDevice_code() + "未设置电气调度号!");
}
String start_addr = startDevice.getExtraValue().get("address").toString();
@@ -447,6 +455,13 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
instdto.setInstruction_status("0");
instdto.setExecute_device_code(start_point_code);
//判断关联的同一列烘箱设备是否都关门 都关门返回false有一个不关门就返回true
boolean isCloseDoor = this.judgeCloseDoor(instdto.getStart_device_code(),instdto.getNext_device_code());
//如果未关门结束
if (isCloseDoor){
return false;
}
try {
instructionService.create(instdto);
} catch (Exception e) {
@@ -458,13 +473,14 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
task.setTask_status("1");
task.setUpdate_time(DateUtil.now());
taskserver.update(task);
Device startDevice = deviceAppService.findDeviceByCode(instdto.getStart_device_code());
Device nextDevice = deviceAppService.findDeviceByCode(instdto.getNext_device_code());
if (ObjectUtil.isEmpty(startDevice.getExtraValue().get("address"))){
if (ObjectUtil.isEmpty(startDevice.getExtraValue().get("address"))) {
notCreateInstMessage = "设备:" + startDevice.getDevice_code() + "未设置电气调度号!";
throw new BadRequestException("设备:" + startDevice.getDevice_code() + "未设置电气调度号!");
}
if (ObjectUtil.isEmpty(nextDevice.getExtraValue().get("address"))){
if (ObjectUtil.isEmpty(nextDevice.getExtraValue().get("address"))) {
notCreateInstMessage = "设备:" + nextDevice.getDevice_code() + "未设置电气调度号!";
throw new BadRequestException("设备:" + nextDevice.getDevice_code() + "未设置电气调度号!");
}
@@ -511,8 +527,54 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
ReadUtil.write(itemMap, server);
}
public void writing(int command) {
//判断取货位或放货位为烘箱设备时关联的同一列烘箱设备是否有开门
public boolean judgeCloseDoor(String start_device_code,String next_device_code) {
Boolean isClose = false;
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();
List<String> deviceCodes = hongXiangConveyorDeviceDriver.getExtraDeviceCodes("link_device_code");
if (ObjectUtil.isNotEmpty(deviceCodes)) {
for (String deviceCode : deviceCodes) {
Device linkDevice = deviceAppService.findDeviceByCode(deviceCode);
if (linkDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) linkDevice.getDeviceDriver();
//判断关联设备是否开门
if (hongXiangConveyorDeviceDriver.getDoor() == 1) {
isClose = true;
notCreateInstMessage = start_device_code + "关联设备->" + deviceCode + "烘箱门未关闭!";
break;
}
}
}
return isClose;
}
}
if (nextDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextDevice.getDeviceDriver();
List<String> deviceCodes = hongXiangConveyorDeviceDriver.getExtraDeviceCodes("link_device_code");
if (ObjectUtil.isNotEmpty(deviceCodes)) {
for (String deviceCode : deviceCodes) {
Device linkDevice = deviceAppService.findDeviceByCode(deviceCode);
if (linkDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) linkDevice.getDeviceDriver();
//判断关联设备是否开门
if (hongXiangConveyorDeviceDriver.getDoor() == 1) {
isClose = true;
notCreateInstMessage = next_device_code + "关联设备->" + deviceCode + "烘箱门未关闭!";
break;
}
}
}
return isClose;
}
}
return isClose;
}
public void writing(int command) {
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
@@ -523,6 +585,9 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
//将扩展表中的字符串数据转换成集合
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(",");
@@ -533,14 +598,14 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
return devicesList;
}
public List<TaskDto> sortTask(List<TaskDto> taskDtos){
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){
if (i == 0) {
//时间从早到晚
i = t1.getCreate_time().compareTo(t2.getCreate_time());
}
@@ -594,6 +659,9 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
jo.put("error", this.getError());
jo.put("isError", this.getIserror());
jo.put("message", this.getMessage());
jo.put("notCreateTaskMessage", notCreateTaskMessage);
jo.put("notCreateInstMessage", notCreateInstMessage);
jo.put("feedMessage", feedMessage);
return jo;
}

View File

@@ -1040,6 +1040,9 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl
//将扩展表中的字符串数组数据转换成集合
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(",");