Merge branch 'lzhl_tow_acs_ls'
This commit is contained in:
@@ -40,7 +40,9 @@ public enum DriverTypeEnum {
|
||||
|
||||
LED_SCREEN(15, "led_screen", "LED点阵屏", "screen"),
|
||||
|
||||
DOUBLE_STATION_STACKER(16, "double_station_stacker", "标准版-双工位堆垛机", "double_station_stacker");
|
||||
DOUBLE_STATION_STACKER(16, "double_station_stacker", "标准版-双工位堆垛机", "double_station_stacker"),
|
||||
|
||||
DOUBLE_BELT_CONVEYOR(17, "double_belt_conveyor", "双工位输送线", "double_belt_conveyor");
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -427,7 +427,8 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
|
||||
/**
|
||||
* 申请任务
|
||||
*/
|
||||
public synchronized Boolean instruction_require() {
|
||||
public synchronized Boolean
|
||||
instruction_require() {
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.nl.acs.device_driver.basedriver.belt_with_station;
|
||||
|
||||
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.DeviceDriverDefination;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 说明:关联站点驱动
|
||||
*/
|
||||
@Service
|
||||
public class WithStationDefination implements DeviceDriverDefination {
|
||||
@Override
|
||||
public String getDriverCode() {
|
||||
return "hailiang_with_station";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverName() {
|
||||
return "关联驱动";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverDescription() {
|
||||
return "关联驱动";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public DeviceDriver getDriverInstance(Device device) {
|
||||
return (new WithStationDeviceDriver()).setDevice(device).setDriverDefination(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends DeviceDriver> getDeviceDriverType() {
|
||||
return WithStationDeviceDriver.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceType> getFitDeviceTypes() {
|
||||
List<DeviceType> types = new LinkedList();
|
||||
types.add(DeviceType.conveyor);
|
||||
return types;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
package org.nl.acs.device_driver.basedriver.belt_with_station;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
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.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.nl.acs.agv.server.NDCAgvService;
|
||||
import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun;
|
||||
import org.nl.acs.device.domain.Device;
|
||||
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.belt_conveyor.BeltConveyorDeviceDriver;
|
||||
import org.nl.acs.device_driver.basedriver.double_belt_conveyor.DoubleBeltConveyorDeviceDriver;
|
||||
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver;
|
||||
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver;
|
||||
import org.nl.acs.ext.wms.service.AcsToWmsService;
|
||||
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl;
|
||||
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.route.service.RouteLineService;
|
||||
import org.nl.acs.route.service.dto.RouteLineDto;
|
||||
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 WithStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
|
||||
@Autowired
|
||||
DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class);
|
||||
@Autowired
|
||||
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
|
||||
@Autowired
|
||||
DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl");
|
||||
@Autowired
|
||||
RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl");
|
||||
@Autowired
|
||||
TaskService taskServer = SpringContextHolder.getBean("taskServiceImpl");
|
||||
@Autowired
|
||||
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class);
|
||||
@Autowired
|
||||
AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class);
|
||||
@Autowired
|
||||
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class);
|
||||
@Autowired
|
||||
NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class);
|
||||
|
||||
|
||||
Integer hasGoods = 0;
|
||||
int error = 0;
|
||||
Boolean iserror = false;
|
||||
Boolean islock = false;
|
||||
|
||||
int branchProtocol = 0;
|
||||
int last_branchProtocol = 0;
|
||||
//是否需要输入物料
|
||||
String input_material = "0";
|
||||
//备注
|
||||
String remark = "";
|
||||
//数量
|
||||
String qty = "";
|
||||
//批次
|
||||
String batch = "";
|
||||
//物料
|
||||
String material = "";
|
||||
//目标点位
|
||||
String purpose = "";
|
||||
|
||||
//上次指令
|
||||
Instruction last_inst = null;
|
||||
|
||||
boolean requireSucess = false;
|
||||
|
||||
//触摸屏手动触发任务
|
||||
private Boolean is_has_task = false;
|
||||
|
||||
//申请搬运任务
|
||||
private Boolean apply_handling = false;
|
||||
//申请物料
|
||||
private Boolean apply_material = false;
|
||||
|
||||
// 1取货完成 2放货完成 3进入区域 4离开区域
|
||||
private int flag;
|
||||
|
||||
//人工确认信号 默认0 agv到达后请求置1 等人工确认后变为2 反馈agv后继续为0
|
||||
private int manua_confirm = 0;
|
||||
|
||||
String device_code = null;
|
||||
String container;
|
||||
String container_type_desc;
|
||||
String last_container_type_desc;
|
||||
String last_container;
|
||||
private Date instruction_require_time = new Date();
|
||||
private Date instruction_finished_time = new Date();
|
||||
|
||||
private int instruction_require_time_out = 30000;
|
||||
|
||||
String message;
|
||||
|
||||
// 1 上位系统允许进入 2 上位系统允许离开
|
||||
int option = 0;
|
||||
|
||||
//agv请求当前信息
|
||||
private int agvphase = 0;
|
||||
private int index = 0;
|
||||
|
||||
int mode = 2;
|
||||
|
||||
int move;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
device_code = this.getDeviceCode();
|
||||
|
||||
|
||||
//取关联设备 list 要求:先配置外侧的站点
|
||||
//遍历
|
||||
List<String> sddjExtraCodeList = this.getExtraDeviceCodes("link_device_code");
|
||||
//只需要判断对接位就可以
|
||||
for (int i = 0; i < 1; i++) {
|
||||
Device sddjExtraCode1 = deviceAppservice.findDeviceByCode(sddjExtraCodeList.get(i));
|
||||
Device sddjExtraCode2 = deviceAppservice.findDeviceByCode(sddjExtraCodeList.get(i + 1));
|
||||
DoubleBeltConveyorDeviceDriver doubleBeltConveyorDeviceDriver1;
|
||||
DoubleBeltConveyorDeviceDriver doubleBeltConveyorDeviceDriver2;
|
||||
if (sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver && sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver) {
|
||||
doubleBeltConveyorDeviceDriver1 = (DoubleBeltConveyorDeviceDriver) sddjExtraCode1.getDeviceDriver();
|
||||
doubleBeltConveyorDeviceDriver2 = (DoubleBeltConveyorDeviceDriver) sddjExtraCode2.getDeviceDriver();
|
||||
//判断输送线是否有任务,有任务进行创建指令。
|
||||
TaskDto taskDtos1 = taskServer.findByStartCodeAndReady(doubleBeltConveyorDeviceDriver1.getDevice_code());
|
||||
TaskDto taskDtos2 = taskServer.findByStartCodeAndReady(doubleBeltConveyorDeviceDriver1.getDevice_code());
|
||||
if (ObjectUtil.isNotEmpty(taskDtos1) && ObjectUtil.isNotEmpty(taskDtos2)) {
|
||||
if (doubleBeltConveyorDeviceDriver1.getMove() == 0) {
|
||||
requireSucess = false;
|
||||
}
|
||||
if (doubleBeltConveyorDeviceDriver2.getMove() == 0) {
|
||||
requireSucess = false;
|
||||
}
|
||||
//判断任务列是否相邻
|
||||
String nextDeviceCode1 = taskDtos1.getNext_device_code();
|
||||
String nextDeviceCode2 = taskDtos2.getNext_device_code();
|
||||
if (StrUtil.contains(nextDeviceCode1, "-") && StrUtil.contains(nextDeviceCode2, "-")) {
|
||||
String[] split1 = nextDeviceCode1.split("-");
|
||||
String nextPointCodeDown = split1[0] + "-" + (Integer.parseInt(split1[1]) - 1) + "-" + split1[2];
|
||||
String nextPointCodeUp = split1[0] + "-" + (Integer.parseInt(split1[1]) + 1) + "-" + split1[2];
|
||||
if (!nextDeviceCode2.equals(nextPointCodeDown) || !nextDeviceCode2.equals(nextPointCodeUp)) {
|
||||
//创建指令
|
||||
if (ObjectUtil.isNotNull(taskDtos1) && "1".equals(taskDtos1.getTask_type())) {
|
||||
creatInstruction(taskDtos1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
requireSucess = false;
|
||||
}
|
||||
|
||||
//判断关联的输送线是否满足状态
|
||||
if (doubleBeltConveyorDeviceDriver1.getMode() == 2 && doubleBeltConveyorDeviceDriver1.getMove() == 1 && !requireSucess && doubleBeltConveyorDeviceDriver2.getMode() == 2 && doubleBeltConveyorDeviceDriver2.getMove() == 1) {
|
||||
//判断是否大于等待时间
|
||||
if (System.currentTimeMillis() - doubleBeltConveyorDeviceDriver1.getInstruction_require_time().getTime()
|
||||
> Integer.parseInt(this.getExtraValue().get("apply_time").toString()) * 1000) {
|
||||
//创建指令
|
||||
if (ObjectUtil.isNotNull(taskDtos1) && "1".equals(taskDtos1.getTask_type())) {
|
||||
creatInstruction(taskDtos1);
|
||||
}
|
||||
}
|
||||
log.info("单工位请求成功");
|
||||
requireSucess = true;
|
||||
} else {
|
||||
//创建指令
|
||||
if (ObjectUtil.isNotNull(taskDtos1) && "1".equals(taskDtos1.getTask_type())) {
|
||||
creatInstruction(taskDtos1);
|
||||
}
|
||||
if (ObjectUtil.isNotNull(taskDtos2) && "1".equals(taskDtos1.getTask_type())) {
|
||||
creatInstruction(taskDtos2);
|
||||
}
|
||||
log.info("双工位指令创建成功");
|
||||
requireSucess = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void creatInstruction(TaskDto taskDtos1) {
|
||||
|
||||
//判断当前任务号是否存在指令
|
||||
String taskid = taskDtos1.getTask_id();
|
||||
String taskcode = taskDtos1.getTask_code();
|
||||
String priority = taskDtos1.getPriority();
|
||||
String start_point_code = taskDtos1.getStart_point_code();
|
||||
String start_device_code = taskDtos1.getStart_device_code();
|
||||
String route_plan_code = taskDtos1.getRoute_plan_code();
|
||||
String next_device_code = "";
|
||||
/**
|
||||
* 开始平均分配
|
||||
*/
|
||||
String this_coevice_code = taskServer.queryAssignedByDevice(device_code, taskDtos1.getNext_device_code());
|
||||
if (StrUtil.isEmpty(this_coevice_code)) {
|
||||
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, taskDtos1.getNext_device_code(), route_plan_code);
|
||||
RouteLineDto routeLineDto = shortPathsList.get(0);
|
||||
|
||||
String path = routeLineDto.getPath();
|
||||
String type = routeLineDto.getType();
|
||||
String[] str = path.split("->");
|
||||
|
||||
List<String> pathlist = Arrays.asList(str);
|
||||
int index = 0;
|
||||
for (int m = 0; m < pathlist.size(); m++) {
|
||||
if (pathlist.get(m).equals(start_device_code)) {
|
||||
index = m + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
next_device_code = pathlist.get(index);
|
||||
} else {
|
||||
next_device_code = this_coevice_code;
|
||||
}
|
||||
//校验路由关系
|
||||
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code);
|
||||
if (ObjectUtils.isEmpty(shortPathsList) || shortPathsList.size() < 1) {
|
||||
throw new RuntimeException("路由不通!");
|
||||
}
|
||||
Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code);
|
||||
String next_point_code;
|
||||
if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) {
|
||||
next_point_code = taskDtos1.getTo_x() + "-" + taskDtos1.getTo_y() + "-" + taskDtos1.getTo_z();
|
||||
} else {
|
||||
next_point_code = next_device_code;
|
||||
}
|
||||
Instruction instdto = new Instruction();
|
||||
instdto.setInstruction_id(IdUtil.simpleUUID());
|
||||
instdto.setRoute_plan_code(route_plan_code);
|
||||
instdto.setRemark(taskDtos1.getRemark());
|
||||
instdto.setMaterial(taskDtos1.getMaterial());
|
||||
instdto.setQuantity(taskDtos1.getQuantity());
|
||||
instdto.setTask_id(taskid);
|
||||
instdto.setTask_code(taskcode);
|
||||
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);
|
||||
log.error("=================================,{}", instdto.getCreate_by());
|
||||
try {
|
||||
instructionService.create(instdto);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("指令创建失败!", e.getMessage());
|
||||
}
|
||||
taskDtos1.setTask_status("1");
|
||||
taskServer.update(taskDtos1);
|
||||
requireSucess = true;
|
||||
Map map = new HashMap();
|
||||
String next_addr = nextdevice.getExtraValue().get("address").toString();
|
||||
map.put("to_target", next_addr);
|
||||
map.put("to_task", instdto.getInstruction_code());
|
||||
map.put("to_command", "1");
|
||||
map.put("to_container_type", "1");
|
||||
map.put("to_container_no", "1");
|
||||
this.writing(map);
|
||||
requireSucess = true;
|
||||
}
|
||||
|
||||
|
||||
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)) {
|
||||
try {
|
||||
this.checkcontrol(itemMap);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
this.checkcontrol(itemMap);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||
}
|
||||
}
|
||||
|
||||
public String getToParam() {
|
||||
return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + ".";
|
||||
}
|
||||
|
||||
|
||||
//将扩展表中的字符串数据转换成集合
|
||||
@Override
|
||||
public List<String> getExtraDeviceCodes(String extraName) {
|
||||
String extraValue = (String) this.getDevice().getExtraValue().get(extraName);
|
||||
String devices1 = extraValue.substring(1, extraValue.length() - 1);
|
||||
List<String> devicesList = new ArrayList<>();
|
||||
String[] devices = devices1.split(",");
|
||||
for (int i = 0; i < devices.length; i++) {
|
||||
String s = devices[i].replace("\"", "").replace("\"", "");
|
||||
devicesList.add(s);
|
||||
}
|
||||
return devicesList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getDeviceStatusName() {
|
||||
JSONObject jo = new JSONObject();
|
||||
String mode = "";
|
||||
String action = "";
|
||||
String move = "";
|
||||
String option = "";
|
||||
if (this.getOption() == 0) {
|
||||
option = "禁止进出";
|
||||
} else if (this.getOption() == 1) {
|
||||
option = "允许进入";
|
||||
} else if (this.getOption() == 2) {
|
||||
option = "允许离开";
|
||||
}
|
||||
|
||||
if (this.getMode() == 0) {
|
||||
mode = "未联机";
|
||||
} else if (this.getMode() == 1) {
|
||||
mode = "单机";
|
||||
} else if (this.getMode() == 2) {
|
||||
mode = "联机";
|
||||
} else if (this.getMode() == 3) {
|
||||
mode = "运行中";
|
||||
}
|
||||
|
||||
if (this.getMove() == 0) {
|
||||
move = "无货";
|
||||
jo.put("hasGoods", false);
|
||||
} else if (this.getMove() == 1) {
|
||||
move = "有货";
|
||||
jo.put("hasGoods", true);
|
||||
} else if (this.getMove() == 2) {
|
||||
move = "有托盘有货";
|
||||
jo.put("hasGoods", true);
|
||||
}
|
||||
jo.put("device_name", this.getDevice().getDevice_name());
|
||||
jo.put("mode", mode);
|
||||
jo.put("move", move);
|
||||
jo.put("action", action);
|
||||
jo.put("isOnline", true);
|
||||
jo.put("error", this.getError());
|
||||
jo.put("isError", this.getIserror());
|
||||
jo.put("option", option);
|
||||
jo.put("is_click", true);
|
||||
return jo;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setDeviceStatus(JSONObject data) {
|
||||
String flag = data.getString("option");
|
||||
if (StrUtil.isNotEmpty(flag)) {
|
||||
option = Integer.parseInt(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.nl.acs.device_driver.basedriver.double_belt_conveyor;
|
||||
|
||||
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 DoubleBeltConveyorDefination implements OpcDeviceDriverDefination {
|
||||
@Override
|
||||
public String getDriverCode() {
|
||||
return "belt_conveyor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverName() {
|
||||
return "标准版-输送机";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverDescription() {
|
||||
return "标准版-输送机";
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceDriver getDriverInstance(Device device) {
|
||||
return (new DoubleBeltConveyorDeviceDriver()).setDevice(device).setDriverDefination(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends DeviceDriver> getDeviceDriverType() {
|
||||
return DoubleBeltConveyorDeviceDriver.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceType> getFitDeviceTypes() {
|
||||
List<DeviceType> types = new LinkedList();
|
||||
types.add(DeviceType.conveyor);
|
||||
return types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemDto> getReadableItemDtos() {
|
||||
return ItemProtocol.getReadableItemDtos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemDto> getWriteableItemDtos() {
|
||||
return ItemProtocol.getWriteableItemDtos();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,639 @@
|
||||
package org.nl.acs.device_driver.basedriver.double_belt_conveyor;
|
||||
|
||||
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.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.nl.acs.agv.server.AgvService;
|
||||
import org.nl.acs.device.domain.Device;
|
||||
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.driver.AbstractOpcDeviceDriver;
|
||||
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver;
|
||||
import org.nl.acs.ext.wms.service.AcsToWmsService;
|
||||
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl;
|
||||
import org.nl.acs.instruction.domain.Instruction;
|
||||
import org.nl.acs.instruction.enums.InstructionStatusEnum;
|
||||
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.route.service.RouteLineService;
|
||||
import org.nl.acs.route.service.dto.RouteLineDto;
|
||||
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.*;
|
||||
|
||||
import static redis.clients.jedis.HostAndPort.localhost;
|
||||
|
||||
/**
|
||||
* 输送线
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
public class DoubleBeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
|
||||
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
||||
DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class);
|
||||
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
||||
DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class);
|
||||
TaskService taskserver = SpringContextHolder.getBean(TaskService.class);
|
||||
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class);
|
||||
AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class);
|
||||
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class);
|
||||
AgvService agvService = SpringContextHolder.getBean(AgvService.class);
|
||||
|
||||
private Date instruction_update_time = new Date();
|
||||
private Date require_apply_strangulation_time = new Date();
|
||||
private int instruction_update_time_out = 500;
|
||||
private Date instruction_require_time = new Date();
|
||||
private Date instruction_finished_time = new Date();
|
||||
private Date instruction_apply_time = new Date();
|
||||
private int instruction_require_time_out = 3000;
|
||||
|
||||
//心跳
|
||||
int heartbeat = 0;
|
||||
int last_heartbeat = 0;
|
||||
//工作模式
|
||||
int mode = 0;
|
||||
int last_mode = 0;
|
||||
//光电信号
|
||||
int move = 0;
|
||||
int last_move = 0;
|
||||
//托盘方向
|
||||
int container_direction = 0;
|
||||
int last_container_direction = 0;
|
||||
//报警
|
||||
int error = 0;
|
||||
int last_error = 0;
|
||||
//动作信号
|
||||
int action = 0;
|
||||
int last_action = 0;
|
||||
//任务号
|
||||
int task = 0;
|
||||
int last_task = 0;
|
||||
//托盘类型
|
||||
int container_type = 0;
|
||||
int last_container_type = 0;
|
||||
//纯数字托盘号
|
||||
int container_no = 0;
|
||||
int last_container_no = 0;
|
||||
|
||||
int inventory_qty = 0;
|
||||
int out_finish = 0;
|
||||
//下发命令
|
||||
int to_command = 0;
|
||||
int last_to_command = 0;
|
||||
//下发目标站
|
||||
int to_target = 0;
|
||||
int last_to_target = 0;
|
||||
//下发任务号
|
||||
int to_task = 0;
|
||||
int last_to_task = 0;
|
||||
//下发接纯数字托盘号
|
||||
int to_container_no = 0;
|
||||
int last_to_container_no = 0;
|
||||
//下发托盘类型
|
||||
int to_container_type = 0;
|
||||
int last_to_container_type = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
//当前指令
|
||||
Instruction inst = null;
|
||||
|
||||
String material = null;
|
||||
|
||||
Boolean isonline = true;
|
||||
|
||||
Boolean iserror = false;
|
||||
|
||||
//1-执行任务;2-取货完成;3-放货完成;
|
||||
int flag;
|
||||
|
||||
|
||||
int last_inventory_qty = 0;
|
||||
int last_out_finish = 0;
|
||||
|
||||
String last_material = null;
|
||||
String message = null;
|
||||
String device_code;
|
||||
String task_code = null;
|
||||
String vehicle_code;
|
||||
String inst_message;
|
||||
|
||||
//led点阵屏信息
|
||||
JSONObject led_message = null;
|
||||
|
||||
|
||||
@Override
|
||||
public Device getDevice() {
|
||||
return this.device;
|
||||
}
|
||||
|
||||
//请求成功标记
|
||||
Boolean requireSucess = false;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
device_code = this.getDeviceCode();
|
||||
heartbeat = this.itemProtocol.getHeartbeat();
|
||||
mode = this.itemProtocol.getMode();
|
||||
move = this.itemProtocol.getMove();
|
||||
action = this.itemProtocol.getAction();
|
||||
container_direction = this.itemProtocol.getContainer_direction();
|
||||
container_type = this.itemProtocol.getContainer_type();
|
||||
error = this.itemProtocol.getError();
|
||||
task = this.itemProtocol.getTask();
|
||||
container_no = this.itemProtocol.getContainer_no();
|
||||
to_command = this.itemProtocol.getTo_command();
|
||||
to_target = this.itemProtocol.getTotarget();
|
||||
to_task = this.itemProtocol.getTo_task();
|
||||
to_container_no = this.itemProtocol.getContainer_direction();
|
||||
to_container_type = this.itemProtocol.getContainer_no();
|
||||
|
||||
if (mode != last_mode) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("device_code", this.device_code);
|
||||
param.put("mode", Math.min(mode, 3));
|
||||
param.put("device_name", this.getDevice().getDevice_name());
|
||||
param.put("device_type", "1");
|
||||
requireSucess = false;
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode + "复位请求标记:" + requireSucess);
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode);
|
||||
}
|
||||
if (move != last_move) {
|
||||
logServer.deviceItemValue(this.device_code, "move", String.valueOf(move));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move);
|
||||
}
|
||||
if (container_direction != last_container_direction) {
|
||||
logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(container_direction));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号container_direction:" + last_container_direction + "->" + container_direction);
|
||||
}
|
||||
if (container_type != last_container_type) {
|
||||
logServer.deviceItemValue(this.device_code, "container_type", String.valueOf(container_type));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号container_type:" + last_container_type + "->" + container_type);
|
||||
}
|
||||
if (container_no != last_container_no) {
|
||||
logServer.deviceItemValue(this.device_code, "container_no", String.valueOf(container_no));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号container_no:" + last_container_no + "->" + container_no);
|
||||
}
|
||||
if (action != last_action) {
|
||||
logServer.deviceItemValue(this.device_code, "action", String.valueOf(action));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action);
|
||||
}
|
||||
if (to_command != last_to_command) {
|
||||
logServer.deviceItemValue(this.device_code, "to_command", String.valueOf(to_command));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command);
|
||||
}
|
||||
if (to_target != last_to_target) {
|
||||
logServer.deviceItemValue(this.device_code, "to_target", String.valueOf(to_target));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target);
|
||||
}
|
||||
if (to_task != last_to_task) {
|
||||
logServer.deviceItemValue(this.device_code, "to_task", String.valueOf(to_task));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task);
|
||||
}
|
||||
if (to_container_no != last_to_container_no) {
|
||||
logServer.deviceItemValue(this.device_code, "to_container_no", String.valueOf(to_container_no));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号to_container_no:" + last_to_container_no + "->" + to_container_no);
|
||||
}
|
||||
if (to_container_type != last_to_container_type) {
|
||||
logServer.deviceItemValue(this.device_code, "to_container_type", String.valueOf(to_container_type));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号to_container_type:" + last_to_container_type + "->" + to_container_type);
|
||||
}
|
||||
if (error != last_error) {
|
||||
if (error != 0) {
|
||||
|
||||
}
|
||||
logServer.deviceItemValue(this.device_code, "error", String.valueOf(error));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error);
|
||||
}
|
||||
if (task != last_task) {
|
||||
logServer.deviceItemValue(this.device_code, "task", String.valueOf(task));
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task);
|
||||
}
|
||||
|
||||
|
||||
if (move != 0 && task > 0) {
|
||||
update_instruction_status();
|
||||
}
|
||||
|
||||
} catch (Exception var17) {
|
||||
var17.printStackTrace();
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol));
|
||||
}
|
||||
|
||||
|
||||
if (mode == 0) {
|
||||
this.setIsonline(false);
|
||||
message = "未联机";
|
||||
} else if (error != 0) {
|
||||
this.setIserror(true);
|
||||
message = "有报警";
|
||||
} else {
|
||||
this.setIsonline(true);
|
||||
this.setIserror(false);
|
||||
message = "";
|
||||
Instruction instruction = null;
|
||||
List toInstructions;
|
||||
|
||||
//纸管库申请任务
|
||||
switch (mode) {
|
||||
case 1:
|
||||
log.debug("弃用(留作兼容)");
|
||||
break;
|
||||
case 2:
|
||||
//申请任务
|
||||
if (move == 1 && !requireSucess) {
|
||||
instruction_require();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
log.info("运行中");
|
||||
break;
|
||||
case 4:
|
||||
//申请出货
|
||||
if (move == 1 && !requireSucess) {
|
||||
//request_for_shipment(String.valueOf(mode), item_out_seq_arr, item_out_qty_arr);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
last_heartbeat = heartbeat;
|
||||
last_mode = mode;
|
||||
last_move = move;
|
||||
last_error = error;
|
||||
last_container_direction = container_direction;
|
||||
last_container_no = container_no;
|
||||
last_container_type = container_type;
|
||||
last_action = action;
|
||||
last_task = task;
|
||||
last_to_command = to_command;
|
||||
last_to_target = to_target;
|
||||
last_to_task = to_task;
|
||||
last_to_container_no = to_container_no;
|
||||
last_to_container_type = to_container_type;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void writing(int command) {
|
||||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||
+ "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command;
|
||||
|
||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
this.control(itemMap);
|
||||
}
|
||||
|
||||
|
||||
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 synchronized void request_for_shipment(String mode, String item_out_seq_arr, int[] item_out_qty_arr) {
|
||||
Date date = new Date();
|
||||
if (date.getTime() - this.require_apply_strangulation_time.getTime() < (long) this.instruction_require_time_out) {
|
||||
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out);
|
||||
} else {
|
||||
this.require_apply_strangulation_time = date;
|
||||
ApplyPaperActionRequest applyPaperActionRequest = new ApplyPaperActionRequest();
|
||||
applyPaperActionRequest.setDevice_code(this.device_code);
|
||||
applyPaperActionRequest.setType("1");
|
||||
applyPaperActionRequest.setTask_code(String.valueOf(task));
|
||||
//获取出库顺序
|
||||
boolean contains = item_out_seq_arr.contains(",");
|
||||
boolean contains1 = item_out_seq_arr.contains(",");
|
||||
|
||||
if (contains) {
|
||||
String[] split = item_out_seq_arr.split(",");
|
||||
applyPaperActionRequest.setMaterial1(split[0]);
|
||||
applyPaperActionRequest.setMaterial1(split[1]);
|
||||
} else if (contains1) {
|
||||
String[] split = item_out_seq_arr.split(",");
|
||||
applyPaperActionRequest.setMaterial1(split[0]);
|
||||
applyPaperActionRequest.setMaterial1(split[1]);
|
||||
} else {
|
||||
applyPaperActionRequest.setMaterial1(item_out_seq_arr);
|
||||
}
|
||||
if (item_out_qty_arr.length >= 1 && item_out_qty_arr.length < 4) {
|
||||
applyPaperActionRequest.setQty1(String.valueOf(item_out_qty_arr[0]));
|
||||
applyPaperActionRequest.setQty2(String.valueOf(item_out_qty_arr[1]));
|
||||
}
|
||||
ApplyPaperActionResponse applyPaperActionResponse = acsToWmsService.applyPaperActionRequest(applyPaperActionRequest);
|
||||
if (ObjectUtil.isNull(applyPaperActionResponse)) {
|
||||
message = "请求失败";
|
||||
requireSucess = false;
|
||||
return;
|
||||
}
|
||||
Map map3 = new HashMap();
|
||||
if (applyPaperActionResponse.getstatus() == 200) {
|
||||
map3.put("to_command", "4");
|
||||
this.writing(map3);
|
||||
requireSucess = true;
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "申请出纸管,返回参数:" + applyPaperActionResponse);
|
||||
message = "申请出货成功";
|
||||
} else {
|
||||
message = applyPaperActionResponse.getMessage();
|
||||
map3.put("to_command", "5");
|
||||
this.writing(map3);
|
||||
requireSucess = false;
|
||||
message = "出库顺序错误";
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "申请出纸管,返回参数:" + applyPaperActionResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* 申请任务
|
||||
*/
|
||||
public synchronized Boolean instruction_require() {
|
||||
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 inst = instructionService.findByDeviceCodeFromCache(this.device_code);
|
||||
if (ObjectUtil.isNotNull(inst) && "1".equals(inst.getInstruction_type())) {
|
||||
Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code());
|
||||
String next_addr = nextdevice.getExtraValue().get("address").toString();
|
||||
TaskDto taskDto = taskserver.findByCodeFromCache(inst.getTask_code());
|
||||
//List<Paper> paperArray = getPaperArray(null);
|
||||
if (ObjectUtil.isEmpty(inst)) {
|
||||
return false;
|
||||
}
|
||||
Map map = new HashMap();
|
||||
map.put("to_target", next_addr);
|
||||
map.put("to_task", inst.getInstruction_code());
|
||||
map.put("to_command", "1");
|
||||
map.put("to_container_type", "1");
|
||||
map.put("to_container_no", "1");
|
||||
this.writing(map);
|
||||
led_message = getLedMessage(inst);
|
||||
requireSucess = true;
|
||||
return true;
|
||||
} else {
|
||||
//判断是否有相同起点的,任务状态就绪的任务
|
||||
TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code);
|
||||
if (ObjectUtil.isNull(taskdto)) {
|
||||
return false;
|
||||
}
|
||||
if (ObjectUtil.isNotNull(taskdto) && "1".equals(taskdto.getTask_type())) {
|
||||
//判断指令的起点和当前的设备号相同
|
||||
if (!taskdto.getStart_device_code().equals(device_code)) {
|
||||
return false;
|
||||
}
|
||||
//判断当前任务号是否存在指令
|
||||
String taskid = taskdto.getTask_id();
|
||||
String taskcode = taskdto.getTask_code();
|
||||
String priority = taskdto.getPriority();
|
||||
String start_point_code = taskdto.getStart_point_code();
|
||||
String start_device_code = taskdto.getStart_device_code();
|
||||
String route_plan_code = taskdto.getRoute_plan_code();
|
||||
String next_device_code = "";
|
||||
/**
|
||||
* 开始平均分配
|
||||
*/
|
||||
String this_coevice_code = taskserver.queryAssignedByDevice(device_code, taskdto.getNext_device_code());
|
||||
if (StrUtil.isEmpty(this_coevice_code)) {
|
||||
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, taskdto.getNext_device_code(), route_plan_code);
|
||||
RouteLineDto routeLineDto = shortPathsList.get(0);
|
||||
|
||||
String path = routeLineDto.getPath();
|
||||
String type = routeLineDto.getType();
|
||||
String[] str = path.split("->");
|
||||
|
||||
List<String> pathlist = Arrays.asList(str);
|
||||
int index = 0;
|
||||
for (int m = 0; m < pathlist.size(); m++) {
|
||||
if (pathlist.get(m).equals(start_device_code)) {
|
||||
index = m + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
next_device_code = pathlist.get(index);
|
||||
} else {
|
||||
next_device_code = this_coevice_code;
|
||||
}
|
||||
//校验路由关系
|
||||
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code);
|
||||
if (ObjectUtils.isEmpty(shortPathsList) || shortPathsList.size()<1) {
|
||||
throw new RuntimeException("路由不通!");
|
||||
}
|
||||
Device startdevice = deviceAppservice.findDeviceByCode(start_device_code);
|
||||
Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code);
|
||||
String next_point_code;
|
||||
if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) {
|
||||
next_point_code = taskdto.getTo_x() + "-" + taskdto.getTo_y() + "-" + taskdto.getTo_z();
|
||||
} else {
|
||||
next_point_code = next_device_code;
|
||||
}
|
||||
Instruction instdto = new Instruction();
|
||||
instdto.setInstruction_id(IdUtil.simpleUUID());
|
||||
instdto.setRoute_plan_code(route_plan_code);
|
||||
instdto.setRemark(taskdto.getRemark());
|
||||
instdto.setMaterial(taskdto.getMaterial());
|
||||
instdto.setQuantity(taskdto.getQuantity());
|
||||
instdto.setTask_id(taskid);
|
||||
instdto.setTask_code(taskcode);
|
||||
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);
|
||||
log.error("=================================,{}",instdto.getCreate_by());
|
||||
try {
|
||||
instructionService.create(instdto);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("指令创建失败!", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
taskdto.setTask_status("1");
|
||||
taskserver.update(taskdto);
|
||||
requireSucess = true;
|
||||
Map map = new HashMap();
|
||||
String next_addr = nextdevice.getExtraValue().get("address").toString();
|
||||
map.put("to_target", next_addr);
|
||||
map.put("to_task", instdto.getInstruction_code());
|
||||
map.put("to_command", "1");
|
||||
map.put("to_container_type", "1");
|
||||
map.put("to_container_no", "1");
|
||||
this.writing(map);
|
||||
led_message = getLedMessage(instdto);
|
||||
requireSucess = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeData(String next_addr, Instruction instdto, Map map) {
|
||||
|
||||
}
|
||||
|
||||
public String getToParam() {
|
||||
return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + ".";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void writing(String key, String param) {
|
||||
|
||||
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||
+ "." + param;
|
||||
//String opcservcerid = this.getDevice().getOpc_server_id();
|
||||
//Server server = ReadUtil.getServer(opcservcerid);
|
||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
|
||||
itemMap.put(to_param, Integer.parseInt(param));
|
||||
//itemMap.put(to_param, Integer.parseInt(value));
|
||||
this.control(itemMap);
|
||||
logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + param);
|
||||
}
|
||||
|
||||
public synchronized boolean finish_instruction() throws Exception {
|
||||
instructionService.finish(inst);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getDeviceStatusName() {
|
||||
JSONObject jo = new JSONObject();
|
||||
String mode = "";
|
||||
|
||||
if (this.getMode() == 0) {
|
||||
mode = "未联机";
|
||||
} else if (this.getMode() == 1) {
|
||||
mode = "单机";
|
||||
} else if (this.getMode() == 2) {
|
||||
mode = "联机";
|
||||
} else if (this.getMode() == 3) {
|
||||
mode = "入库中";
|
||||
} else if (this.getMode() == 4) {
|
||||
mode = "出库中";
|
||||
}
|
||||
jo.put("device_name", this.getDevice().getDevice_name());
|
||||
jo.put("mode", mode);
|
||||
//jo.put("error", ErrorUtil.getDictDetail("ssx_error_type", String.valueOf(this.getError())));
|
||||
jo.put("inventory_qty", inventory_qty);
|
||||
jo.put("out_finish", out_finish);
|
||||
jo.put("material", material);
|
||||
jo.put("isOnline", this.getIsonline());
|
||||
|
||||
return jo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务信息
|
||||
*/
|
||||
public JSONObject getLedMessage(Instruction instdto){
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("task_code", instdto.getTask_code());
|
||||
json.put("inst_code", instdto.getInstruction_code());
|
||||
json.put("start_device_code", instdto.getStart_device_code());
|
||||
json.put("next_device_code", instdto.getNext_device_code());
|
||||
json.put("material_type", instdto.getMaterial());
|
||||
json.put("quantity", instdto.getQuantity());
|
||||
json.put("vehicle_code", instdto.getVehicle_code());
|
||||
json.put("instruction_status",instdto.getInstruction_status());
|
||||
json.put("entry_time", instdto.getCreate_time());
|
||||
json.put("ip", localhost);
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 更新指令状态
|
||||
*/
|
||||
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;
|
||||
inst = checkInst();
|
||||
if (inst != null) {
|
||||
//a点到b点,给状态说允许取货
|
||||
if (StrUtil.equals(inst.getInstruction_status(), InstructionStatusEnum.READY.getIndex()) && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) {
|
||||
inst.setInstruction_status(InstructionStatusEnum.BUSY.getIndex());
|
||||
inst.setExecute_device_code(this.device_code);
|
||||
instructionService.update(inst);
|
||||
logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setDeviceStatus(JSONObject data) {
|
||||
|
||||
}
|
||||
|
||||
public static boolean arrayEquals(int[] a, int[] b) {
|
||||
// 判断两个数组长度是否相等
|
||||
if (a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
// 判断两个数组对应位置上的元素是否相同
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
if (a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package org.nl.acs.device_driver.basedriver.double_belt_conveyor;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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_mode = "mode";
|
||||
//光电信号
|
||||
public static String item_move = "move";
|
||||
//动作信号
|
||||
public static String item_action = "action";
|
||||
//报警
|
||||
public static String item_error = "error";
|
||||
//托盘方向
|
||||
public static String item_container_direction = "container_direction";
|
||||
//托盘类型
|
||||
public static String item_container_type = "container_type";
|
||||
//任务号
|
||||
public static String item_task = "task";
|
||||
//出数字托盘号
|
||||
public static String item_container_no = "container_no";
|
||||
|
||||
//下发命令
|
||||
public static String item_to_command = "to_command";
|
||||
//下发托盘类型
|
||||
public static String item_to_container_type = "to_container_type";
|
||||
//下发接纯数字托盘号
|
||||
public static String item_to_container_no = "to_container_no";
|
||||
//下发任务号
|
||||
public static String item_to_task = "to_task";
|
||||
//下发目标站
|
||||
public static String item_to_target = "to_target";
|
||||
|
||||
|
||||
|
||||
private DoubleBeltConveyorDeviceDriver driver;
|
||||
|
||||
public ItemProtocol(DoubleBeltConveyorDeviceDriver driver) {
|
||||
this.driver = driver;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getHeartbeat() {
|
||||
return this.getOpcIntegerValue(item_heartbeat);
|
||||
}
|
||||
|
||||
public int getMode() {
|
||||
return this.getOpcIntegerValue(item_mode);
|
||||
}
|
||||
|
||||
public int getMove() {
|
||||
return this.getOpcIntegerValue(item_move);
|
||||
}
|
||||
|
||||
public int getContainer_direction() {
|
||||
return this.getOpcIntegerValue(item_container_direction);
|
||||
}
|
||||
|
||||
public int getContainer_type() {
|
||||
return this.getOpcIntegerValue(item_container_type);
|
||||
}
|
||||
|
||||
public int getAction() {
|
||||
return this.getOpcIntegerValue(item_action);
|
||||
}
|
||||
|
||||
public int getContainer_no() {
|
||||
return this.getOpcIntegerValue(item_container_no);
|
||||
}
|
||||
|
||||
public int getError() {
|
||||
return this.getOpcIntegerValue(item_error);
|
||||
}
|
||||
|
||||
public int getTask() {
|
||||
return this.getOpcIntegerValue(item_task);
|
||||
}
|
||||
|
||||
public int getTo_task() {
|
||||
return this.getOpcIntegerValue(item_to_task);
|
||||
}
|
||||
|
||||
|
||||
public int getTotarget() {
|
||||
return this.getOpcIntegerValue(item_to_target);
|
||||
}
|
||||
|
||||
public int getTo_command() {
|
||||
return this.getOpcIntegerValue(item_to_command);
|
||||
}
|
||||
|
||||
public int getTo_container_type() {
|
||||
return this.getOpcIntegerValue(item_to_container_type);
|
||||
}
|
||||
|
||||
public int getTo_container_no() {
|
||||
return this.getOpcIntegerValue(item_to_container_no);
|
||||
}
|
||||
|
||||
Boolean isonline;
|
||||
|
||||
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 (StrUtil.isBlank(value)) {
|
||||
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
public int[] getOpcArrayValue(String protocol) {
|
||||
int[] arrayValue = this.driver.getIntegeregerArrayValue(protocol);
|
||||
if (ObjectUtil.isNull(arrayValue)) {
|
||||
|
||||
} else {
|
||||
return arrayValue;
|
||||
}
|
||||
return new int[3];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static List<ItemDto> getReadableItemDtos() {
|
||||
ArrayList list = new ArrayList();
|
||||
list.add(new ItemDto(item_heartbeat, "心跳", "DB101.B0"));
|
||||
list.add(new ItemDto(item_mode, "工作模式", "DB101.B2"));
|
||||
list.add(new ItemDto(item_move, "光电信号", "DB101.B3"));
|
||||
list.add(new ItemDto(item_container_direction, "托盘方向", "DB101.B4"));
|
||||
list.add(new ItemDto(item_container_type, "托盘类型", "DB101.B5"));
|
||||
list.add(new ItemDto(item_container_no, "纯数字托盘号", "DB101.D7"));
|
||||
list.add(new ItemDto(item_action, "动作类型", "DB101.B6"));
|
||||
list.add(new ItemDto(item_error, "报警", "DB101.B58"));
|
||||
list.add(new ItemDto(item_task, "任务号", "DB101.D68"));
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<ItemDto> getWriteableItemDtos() {
|
||||
ArrayList list = new ArrayList();
|
||||
list.add(new ItemDto(item_to_target , "下发仓位号", "DB102.W2"));
|
||||
list.add(new ItemDto(item_to_command, "下发命令", "DB102.W4"));
|
||||
list.add(new ItemDto(item_to_task, "下发任务号", "DB102.D1"));
|
||||
list.add(new ItemDto(item_to_container_no, "下发接纯数字托盘号", "DB102.D3"));
|
||||
list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB102.B5"));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.nl.acs.device_driver.basedriver.double_belt_conveyor;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Paper implements Serializable {
|
||||
//设备号
|
||||
private String device_code;
|
||||
//
|
||||
private String material_code;
|
||||
private String qty;
|
||||
|
||||
}
|
||||
@@ -645,7 +645,6 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
|
||||
instructionMapper.updateById(entity);
|
||||
removeByCodeFromCache(dto.getInstruction_code());
|
||||
instructions.add(dto);
|
||||
// this.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -101,7 +101,7 @@ import agv_ndc_two from '@/views/acs/device/driver/agv/agv_ndc_two'
|
||||
import xg_agv from '@/views/acs/device/driver/agv/xg_agv'
|
||||
import led_screen from './driver/led_screen'
|
||||
import standard_station from '@/views/acs/device/driver/standard_station'
|
||||
|
||||
import double_belt_conveyor from '@/views/acs/device/driver/double_belt_conveyor.vue'
|
||||
export default {
|
||||
name: 'DeviceConfig',
|
||||
components: {
|
||||
@@ -132,7 +132,8 @@ export default {
|
||||
standard_station,
|
||||
oven_manipulator,
|
||||
plug_pull_device_site,
|
||||
slit_two_manipulator
|
||||
slit_two_manipulator,
|
||||
double_belt_conveyor
|
||||
|
||||
},
|
||||
dicts: ['device_type'],
|
||||
|
||||
@@ -0,0 +1,668 @@
|
||||
<template>
|
||||
<!--标准版-输送机-控制点-->
|
||||
<div>
|
||||
<el-card class="box-card" shadow="never">
|
||||
<div slot="header" class="clearfix">
|
||||
<span class="role-span">设备协议:</span>
|
||||
</div>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
OpcServer:
|
||||
<el-select
|
||||
v-model="opc_id"
|
||||
placeholder="无"
|
||||
clearable
|
||||
filterable
|
||||
@change="changeOpc"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in dataOpcservers"
|
||||
:key="item.opc_id"
|
||||
:label="item.opc_name"
|
||||
:value="item.opc_id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
PLC:
|
||||
<el-select
|
||||
v-model="plc_id"
|
||||
placeholder="无"
|
||||
clearable
|
||||
@change="changePlc"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in dataOpcPlcs"
|
||||
:key="item.plc_id"
|
||||
:label="item.plc_name"
|
||||
:value="item.plc_id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
</el-card>
|
||||
|
||||
<el-card class="box-card" shadow="never">
|
||||
<div slot="header" class="clearfix">
|
||||
<span class="role-span">输送系统:</span>
|
||||
</div>
|
||||
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px">
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="电气调度号" label-width="150px">
|
||||
<el-input v-model="form.address" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card class="box-card" shadow="never">
|
||||
<div slot="header" class="clearfix">
|
||||
<span class="role-span">指令相关:</span>
|
||||
</div>
|
||||
<!-- <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px">
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="检验有货">
|
||||
<el-switch v-model="form.inspect_in_stocck" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="忽视取货校验" label-width="150px">
|
||||
<el-switch v-model="form.ignore_pickup_check" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="忽视放货校验" label-width="150px">
|
||||
<el-switch v-model="form.ignore_release_check" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="呼叫">
|
||||
<el-switch v-model="form.apply_task" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="响应" label-width="150px">
|
||||
<el-switch v-model="form.manual_create_task" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="关联设备" prop="device_code">
|
||||
<el-select
|
||||
v-model="form.link_device_code"
|
||||
filterable
|
||||
multiple
|
||||
placeholder="请选择"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in deviceList"
|
||||
:key="item.device_code"
|
||||
:label="item.device_name"
|
||||
:value="item.device_code"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="关联三色灯" prop="device_code" label-width="100px">
|
||||
<el-select
|
||||
v-model="form.link_three_lamp"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="请选择"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in deviceList"
|
||||
:key="item.device_code"
|
||||
:label="item.device_name"
|
||||
:value="item.device_code"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="是否输入物料" label-width="150px">
|
||||
<el-switch v-model="form.input_material" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="是否需要反馈光电" label-width="150px">
|
||||
<el-switch v-model="form.ship_device_update" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form> -->
|
||||
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px">
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="排:" label-width="150px" prop="x">
|
||||
<el-input v-model.number="form.x" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="列:" label-width="150px" prop="z">
|
||||
<el-input v-model.number="form.z" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="层:" label-width="150px" prop="yY">
|
||||
<el-input v-model.number="form.y" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="等待时间:" label-width="150px" prop="apply_time">
|
||||
<el-input v-model.number="form.apply_time" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="关联设备" prop="device_code">
|
||||
<el-select
|
||||
v-model="form.link_device_code"
|
||||
clearable
|
||||
filterable
|
||||
placeholder="请选择"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in deviceList"
|
||||
:key="item.device_code"
|
||||
:label="item.device_name"
|
||||
:value="item.device_code"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card class="box-card" shadow="never">
|
||||
<div slot="header" class="clearfix">
|
||||
<span class="role-span">AGV相关:</span>
|
||||
</div>
|
||||
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px">
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="取货">
|
||||
<el-switch v-model="form.is_pickup" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="放货">
|
||||
<el-switch v-model="form.is_release" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card class="box-card" shadow="never">
|
||||
<div slot="header" class="clearfix">
|
||||
<span class="role-span">PLC读取字段:</span>
|
||||
</div>
|
||||
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px">
|
||||
<el-table
|
||||
v-loading="false"
|
||||
:data="data1"
|
||||
:max-height="550"
|
||||
size="small"
|
||||
style="width: 100%;margin-bottom: 15px"
|
||||
>
|
||||
|
||||
<el-table-column prop="name" label="用途" />
|
||||
<el-table-column prop="code" label="别名要求" />
|
||||
<el-table-column prop="db" label="DB块">
|
||||
<template slot-scope="scope">
|
||||
<el-input
|
||||
v-model="data1[scope.$index].db"
|
||||
size="mini"
|
||||
class="edit-input"
|
||||
@input="finishReadEdit(data1[scope.$index])"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="dbr_value">
|
||||
<template slot="header">
|
||||
<el-link type="primary" :underline="false" @click.native="test_read1()">测试读</el-link>
|
||||
</template>
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="data1[scope.$index].dbr_value" size="mini" class="edit-input" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card class="box-card" shadow="never">
|
||||
<div slot="header" class="clearfix">
|
||||
<span class="role-span">PLC写入字段:</span>
|
||||
</div>
|
||||
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px">
|
||||
<el-table
|
||||
v-loading="false"
|
||||
:data="data2"
|
||||
:max-height="550"
|
||||
size="small"
|
||||
style="width: 100%;margin-bottom: 15px"
|
||||
>
|
||||
|
||||
<el-table-column prop="name" label="用途" />
|
||||
<el-table-column prop="code" label="别名要求" />
|
||||
<el-table-column prop="db" label="DB块">
|
||||
<template slot-scope="scope">
|
||||
<el-input
|
||||
v-model="data2[scope.$index].db"
|
||||
size="mini"
|
||||
class="edit-input"
|
||||
@input="finishWriteEdit(data2[scope.$index])"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="dbr_value2">
|
||||
<template slot="header">
|
||||
<el-link type="primary" :underline="false" @click.native="test_read2()">测试读</el-link>
|
||||
</template>
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="data2[scope.$index].dbr_value" size="mini" class="edit-input" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="dbw_value">
|
||||
<template slot="header">
|
||||
<el-link type="primary" :underline="false" @click.native="test_write1()">测试写</el-link>
|
||||
</template>
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="data2[scope.$index].dbw_value" size="mini" class="edit-input" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card class="box-card" shadow="never">
|
||||
<div slot="header" class="clearfix">
|
||||
<span class="role-span" />
|
||||
<el-button
|
||||
:loading="false"
|
||||
icon="el-icon-check"
|
||||
size="mini"
|
||||
style="float: right; padding: 6px 9px"
|
||||
type="primary"
|
||||
@click="doSubmit"
|
||||
>保存
|
||||
</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
queryDriverConfig,
|
||||
updateConfig,
|
||||
testRead,
|
||||
testwrite
|
||||
} from '@/api/acs/device/driverConfig'
|
||||
import { selectOpcList } from '@/api/acs/device/opc'
|
||||
import { selectPlcList } from '@/api/acs/device/opcPlc'
|
||||
import { selectListByOpcID } from '@/api/acs/device/opcPlc'
|
||||
|
||||
import crud from '@/mixins/crud'
|
||||
import deviceCrud from '@/api/acs/device/device'
|
||||
|
||||
export default {
|
||||
name: 'DoubleStandardConveyorControl',
|
||||
mixins: [crud],
|
||||
props: {
|
||||
parentForm: {
|
||||
type: Object,
|
||||
require: true
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
device_code: '',
|
||||
device_id: '',
|
||||
plc_id: '',
|
||||
plc_code: '',
|
||||
address: '',
|
||||
opc_id: '',
|
||||
opc_code: '',
|
||||
configLoading: false,
|
||||
dataOpcservers: [],
|
||||
dataOpcPlcs: [],
|
||||
deviceList: [],
|
||||
data1: [],
|
||||
data2: [],
|
||||
form: {
|
||||
inspect_in_stocck: true,
|
||||
ignore_pickup_check: true,
|
||||
ignore_release_check: true,
|
||||
apply_task: true,
|
||||
link_three_lamp: '',
|
||||
manual_create_task: true,
|
||||
is_pickup: true,
|
||||
is_release: true,
|
||||
link_device_code: [],
|
||||
ship_device_update: true,
|
||||
apply_time: ''
|
||||
},
|
||||
rules: {}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.$nextTick(() => {
|
||||
// 从父表单获取设备编码
|
||||
this.device_id = this.$props.parentForm.device_id
|
||||
this.device_code = this.$props.parentForm.device_code
|
||||
queryDriverConfig(
|
||||
this.device_id,
|
||||
this.$props.parentForm.driver_code
|
||||
).then((data) => {
|
||||
// 给表单赋值,并且属性不能为空
|
||||
if (data.form) {
|
||||
const arr = Object.keys(data.form)
|
||||
// 不为空
|
||||
if (arr.length > 0) {
|
||||
this.form = data.form
|
||||
}
|
||||
}
|
||||
|
||||
// 给表单赋值,并且属性不能为空
|
||||
if (data.parentForm) {
|
||||
const arr = Object.keys(data.parentForm)
|
||||
// 不为空
|
||||
if (arr.length > 0) {
|
||||
this.opc_code = data.parentForm.opc_code
|
||||
this.plc_code = data.parentForm.plc_code
|
||||
}
|
||||
}
|
||||
this.data1 = data.rs
|
||||
this.data2 = data.ws
|
||||
this.sliceItem()
|
||||
})
|
||||
selectPlcList().then((data) => {
|
||||
this.dataOpcPlcs = data
|
||||
this.plc_id = this.$props.parentForm.opc_plc_id
|
||||
})
|
||||
selectOpcList().then((data) => {
|
||||
this.dataOpcservers = data
|
||||
this.opc_id = this.$props.parentForm.opc_server_id
|
||||
})
|
||||
deviceCrud.selectDeviceList().then((data) => {
|
||||
this.deviceList = data
|
||||
})
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
finishReadEdit(data) {
|
||||
// 编辑的是code列,并且值包含mode
|
||||
if (data.code.indexOf('mode') !== -1) {
|
||||
const dbValue = data.db
|
||||
// .之前的字符串
|
||||
const beforeStr = dbValue.match(/(\S*)\./)[1]
|
||||
// .之后的字符串
|
||||
const afterStr = dbValue.match(/\.(\S*)/)[1]
|
||||
// 取最后数字
|
||||
const endNumber = afterStr.substring(1)
|
||||
// 最后为非数字
|
||||
if (isNaN(parseInt(endNumber))) {
|
||||
return
|
||||
}
|
||||
for (const val in this.data1) {
|
||||
if (this.data1[val].code.indexOf('mode') !== -1) {
|
||||
this.data1[val].db =
|
||||
beforeStr +
|
||||
'.' +
|
||||
afterStr.substring(0, 1) +
|
||||
(parseInt(endNumber) + 0)
|
||||
}
|
||||
if (this.data1[val].code.indexOf('move') !== -1) {
|
||||
this.data1[val].db =
|
||||
beforeStr +
|
||||
'.' +
|
||||
afterStr.substring(0, 1) +
|
||||
(parseInt(endNumber) + 1)
|
||||
}
|
||||
if (this.data1[val].code.indexOf('carrier_direction') !== -1) {
|
||||
this.data1[val].db =
|
||||
beforeStr +
|
||||
'.' +
|
||||
afterStr.substring(0, 1) +
|
||||
(parseInt(endNumber) + 2)
|
||||
}
|
||||
if (this.data1[val].code.indexOf('error') !== -1) {
|
||||
this.data1[val].db =
|
||||
beforeStr +
|
||||
'.' +
|
||||
afterStr.substring(0, 1) +
|
||||
(parseInt(endNumber) + 4)
|
||||
}
|
||||
if (this.data1[val].code.indexOf('task') !== -1) {
|
||||
this.data1[val].db =
|
||||
beforeStr + '.' + 'D' + (parseInt(endNumber) + 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
finishWriteEdit(data) {
|
||||
// 编辑的是code列,并且值包含mode
|
||||
if (data.code.indexOf('to_command') !== -1) {
|
||||
const dbValue = data.db
|
||||
// .之前的字符串
|
||||
const beforeStr = dbValue.match(/(\S*)\./)[1]
|
||||
// .之后的字符串
|
||||
const afterStr = dbValue.match(/\.(\S*)/)[1]
|
||||
// 取最后数字
|
||||
const endNumber = afterStr.substring(1)
|
||||
// 最后为非数字
|
||||
if (isNaN(parseInt(endNumber))) {
|
||||
return
|
||||
}
|
||||
console.log(endNumber)
|
||||
for (const val in this.data2) {
|
||||
if (this.data2[val].code.indexOf('to_command') !== -1) {
|
||||
this.data2[val].db =
|
||||
beforeStr +
|
||||
'.' +
|
||||
afterStr.substring(0, 1) +
|
||||
(parseInt(endNumber) + 0)
|
||||
}
|
||||
if (this.data2[val].code.indexOf('to_target') !== -1) {
|
||||
this.data2[val].db =
|
||||
beforeStr +
|
||||
'.' +
|
||||
afterStr.substring(0, 1) +
|
||||
(parseInt(endNumber) + 2)
|
||||
}
|
||||
if (this.data2[val].code.indexOf('to_container_type') !== -1) {
|
||||
this.data2[val].db =
|
||||
beforeStr +
|
||||
'.' +
|
||||
afterStr.substring(0, 1) +
|
||||
(parseInt(endNumber) + 4)
|
||||
}
|
||||
if (this.data2[val].code.indexOf('to_task') !== -1) {
|
||||
this.data2[val].db =
|
||||
beforeStr + '.' + 'D' + (parseInt(endNumber) + 6)
|
||||
}
|
||||
if (this.data2[val].code.indexOf('to_strap_times') !== -1) {
|
||||
this.data2[val].db =
|
||||
beforeStr +
|
||||
'.' +
|
||||
afterStr.substring(0, 1) +
|
||||
(parseInt(endNumber) + 10)
|
||||
}
|
||||
if (this.data2[val].code.indexOf('to_length') !== -1) {
|
||||
this.data2[val].db =
|
||||
beforeStr +
|
||||
'.' +
|
||||
afterStr.substring(0, 1) +
|
||||
(parseInt(endNumber) + 12)
|
||||
}
|
||||
if (this.data2[val].code.indexOf('to_weight') !== -1) {
|
||||
this.data2[val].db =
|
||||
beforeStr +
|
||||
'.' +
|
||||
afterStr.substring(0, 1) +
|
||||
(parseInt(endNumber) + 14)
|
||||
}
|
||||
if (this.data2[val].code.indexOf('to_height') !== -1) {
|
||||
this.data2[val].db =
|
||||
beforeStr +
|
||||
'.' +
|
||||
afterStr.substring(0, 1) +
|
||||
(parseInt(endNumber) + 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
changeOpc(val) {
|
||||
this.dataOpcservers.forEach((item) => {
|
||||
if (item.opc_id === val) {
|
||||
this.opc_code = item.opc_code
|
||||
}
|
||||
})
|
||||
|
||||
selectListByOpcID(val).then((data) => {
|
||||
this.dataOpcPlcs = data
|
||||
this.plc_id = ''
|
||||
this.plc_code = ''
|
||||
if (this.dataOpcPlcs && this.dataOpcPlcs.length > 0) {
|
||||
this.plc_id = this.dataOpcPlcs[0].plc_id
|
||||
this.plc_code = this.dataOpcPlcs[0].plc_code
|
||||
}
|
||||
this.sliceItem()
|
||||
})
|
||||
},
|
||||
changePlc(val) {
|
||||
this.dataOpcPlcs.forEach((item) => {
|
||||
if (item.plc_id === val) {
|
||||
this.plc_code = item.plc_code
|
||||
this.sliceItem()
|
||||
return
|
||||
}
|
||||
})
|
||||
},
|
||||
test_read1() {
|
||||
testRead(this.data1, this.opc_id)
|
||||
.then((data) => {
|
||||
this.data1 = data
|
||||
console.log(this.data1)
|
||||
this.notify('操作成功!', 'success')
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.response.data.message)
|
||||
})
|
||||
},
|
||||
test_write1() {
|
||||
testwrite(this.data2, this.opc_id)
|
||||
.then((data) => {
|
||||
this.notify('操作成功!', 'success')
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.response.data.message)
|
||||
})
|
||||
},
|
||||
test_read2() {
|
||||
testRead(this.data2, this.opc_id)
|
||||
.then((data) => {
|
||||
this.data2 = data
|
||||
console.log(this.data2)
|
||||
this.notify('操作成功!', 'success')
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.response.data.message)
|
||||
})
|
||||
},
|
||||
doSubmit() {
|
||||
this.$refs['form'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.configLoading = true
|
||||
// 根据驱动类型判断是否为路由设备
|
||||
const parentForm = this.parentForm
|
||||
parentForm.is_route = true
|
||||
parentForm.plc_id = this.plc_id
|
||||
parentForm.opc_id = this.opc_id
|
||||
updateConfig(parentForm, this.form, this.data1, this.data2)
|
||||
.then((res) => {
|
||||
this.notify('保存成功', 'success')
|
||||
this.configLoading = false
|
||||
})
|
||||
.catch((err) => {
|
||||
this.configLoading = false
|
||||
console.log(err.response.data.message)
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
sliceItem() {
|
||||
// 拼接DB的Item值
|
||||
this.data1.forEach((item) => {
|
||||
const str = item.code
|
||||
// 是否包含.
|
||||
if (str.search('.') !== -1) {
|
||||
// 截取最后一位
|
||||
item.code =
|
||||
this.opc_code +
|
||||
'.' +
|
||||
this.plc_code +
|
||||
'.' +
|
||||
this.device_code +
|
||||
'.' +
|
||||
str.slice(str.lastIndexOf('.') + 1)
|
||||
} else {
|
||||
item.code =
|
||||
this.opc_code +
|
||||
'.' +
|
||||
this.plc_code +
|
||||
'.' +
|
||||
this.device_code +
|
||||
'.' +
|
||||
item.code
|
||||
}
|
||||
})
|
||||
this.data2.forEach((item) => {
|
||||
const str = item.code
|
||||
// 是否包含.
|
||||
if (str.search('.') !== -1) {
|
||||
// 截取最后一位
|
||||
item.code =
|
||||
this.opc_code +
|
||||
'.' +
|
||||
this.plc_code +
|
||||
'.' +
|
||||
this.device_code +
|
||||
'.' +
|
||||
str.slice(str.lastIndexOf('.') + 1)
|
||||
} else {
|
||||
item.code =
|
||||
this.opc_code +
|
||||
'.' +
|
||||
this.plc_code +
|
||||
'.' +
|
||||
this.device_code +
|
||||
'.' +
|
||||
item.code
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
||||
@@ -96,6 +96,7 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="5">
|
||||
<el-form-item label="货位排序:" prop="sort" label-width="100px">
|
||||
<el-select
|
||||
|
||||
Reference in New Issue
Block a user