lishuai
3 months ago
11 changed files with 532 additions and 10 deletions
@ -0,0 +1,216 @@ |
|||
package org.nl.acs.device_driver.basedriver.agv.agv_conveyor; |
|||
|
|||
import cn.hutool.core.collection.CollUtil; |
|||
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.Getter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.Setter; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.ObjectUtils; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.nl.acs.agv.server.AgvService; |
|||
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.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.service.InstructionService; |
|||
import org.nl.acs.instruction.service.dto.Instruction; |
|||
import org.nl.acs.log.service.DeviceExecuteLogService; |
|||
import org.nl.acs.monitor.DeviceStageMonitor; |
|||
import org.nl.acs.opc.Device; |
|||
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.modules.system.service.ParamService; |
|||
import org.nl.modules.wql.util.SpringContextHolder; |
|||
import org.openscada.opc.lib.da.Server; |
|||
|
|||
import java.util.*; |
|||
|
|||
/** |
|||
* 货梯对接线 |
|||
*/ |
|||
@Slf4j |
|||
@Getter |
|||
@Setter |
|||
@RequiredArgsConstructor |
|||
public class AgvConveyorConveyorDeviceDriver 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); |
|||
|
|||
ParamService paramService = SpringContextHolder.getBean(ParamService.class); |
|||
|
|||
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); |
|||
|
|||
AgvService agvService = SpringContextHolder.getBean(AgvService.class); |
|||
|
|||
private final DeviceExecuteLogService deviceExecuteLogService = SpringContextHolder.getBean(DeviceExecuteLogService.class); |
|||
|
|||
|
|||
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 error = 0; |
|||
int task = 0; |
|||
String on_off_site; |
|||
String tray_Information; |
|||
int down_request; |
|||
int up_request; |
|||
|
|||
Boolean isonline = true; |
|||
|
|||
Boolean iserror = false; |
|||
|
|||
|
|||
|
|||
int last_error = 0; |
|||
|
|||
String device_code; |
|||
|
|||
@Override |
|||
public Device getDevice() { |
|||
return this.device; |
|||
} |
|||
|
|||
//请求成功标记
|
|||
Boolean requireSucess = false; |
|||
|
|||
@Override |
|||
public void execute() throws Exception { |
|||
String message = null; |
|||
|
|||
device_code = this.getDeviceCode(); |
|||
heartbeat = this.itemProtocol.getItem_heartbeat(); |
|||
on_off_site = this.itemProtocol.getItem_on_off_site(); |
|||
tray_Information = this.itemProtocol.getItem_tray_Information(); |
|||
down_request = this.itemProtocol.getItem_down_request(); |
|||
up_request = this.itemProtocol.getItem_up_request(); |
|||
|
|||
|
|||
|
|||
|
|||
if (error != last_error) { |
|||
} |
|||
|
|||
|
|||
if (!this.itemProtocol.getIsonline()) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
//未联机
|
|||
} else { |
|||
this.setIsonline(true); |
|||
this.setIserror(false); |
|||
if ((down_request == 1 || up_request == 1) && StringUtils.isNoneEmpty(on_off_site)){ |
|||
task_apply(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
public synchronized boolean task_apply() 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_out); |
|||
return false; |
|||
} else { |
|||
this.instruction_require_time = date; |
|||
//请求下料
|
|||
if (down_request == 1){ |
|||
List<RouteLineDto> routeLineDtos = routeLineService.getPathLinesByCode(on_off_site,"normal"); |
|||
if (CollUtil.isEmpty(routeLineDtos) || routeLineDtos.size() < 1) { |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "没有"+ on_off_site + "的路由"); |
|||
} |
|||
RouteLineDto routeLineDto = routeLineDtos.get(0); |
|||
TaskDto taskDto = new TaskDto(); |
|||
taskDto.setStart_device_code(on_off_site); |
|||
taskDto.setNext_device_code(routeLineDto.getNext_device_code()); |
|||
taskDto.setStart_point_code(on_off_site); |
|||
taskDto.setNext_point_code(routeLineDto.getNext_device_code()); |
|||
taskDto.setExecute_code(this.device_code); |
|||
taskDto.setExecute_message("down"); |
|||
taskserver.create(taskDto); |
|||
} |
|||
//请求上料
|
|||
if (up_request == 1){ |
|||
List<RouteLineDto> routeLineDtos = routeLineService.getsByCode(on_off_site,"normal"); |
|||
if (CollUtil.isEmpty(routeLineDtos) || routeLineDtos.size() < 1) { |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "没有"+ on_off_site + "的路由"); |
|||
} |
|||
RouteLineDto routeLineDto = routeLineDtos.get(0); |
|||
TaskDto taskDto = new TaskDto(); |
|||
taskDto.setStart_device_code(routeLineDto.getDevice_code()); |
|||
taskDto.setNext_device_code(on_off_site); |
|||
taskDto.setStart_point_code(routeLineDto.getDevice_code()); |
|||
taskDto.setNext_point_code(on_off_site); |
|||
taskDto.setExecute_code(this.device_code); |
|||
taskDto.setExecute_message("up"); |
|||
taskserver.create(taskDto); |
|||
} |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
public void writing(String param, Object value) { |
|||
|
|||
String to_param = this.getDevice().getOpc_server_code() + "." + |
|||
this.getDevice().getOpc_plc_code() + "." + |
|||
this.getDevice().getDevice_code() + "." + |
|||
param; |
|||
|
|||
Map<String, Object> itemMap = new HashMap<>(); |
|||
itemMap.put(to_param, value); |
|||
this.control(itemMap); |
|||
|
|||
this.deviceExecuteLogService.deviceExecuteLog(device_code, "", "", param + " 写入 " + value); |
|||
} |
|||
@Override |
|||
public JSONObject getDeviceStatusName() { |
|||
JSONObject jo = new JSONObject(); |
|||
String mode = ""; |
|||
String action = ""; |
|||
String move = ""; |
|||
jo.put("device_name", this.getDevice().getDevice_name()); |
|||
jo.put("mode", mode); |
|||
jo.put("move", move); |
|||
jo.put("action", action); |
|||
jo.put("isOnline", this.getIsonline()); |
|||
jo.put("error", this.getError()); |
|||
jo.put("isError", this.getIserror()); |
|||
jo.put("task", this.getTask()); |
|||
return jo; |
|||
} |
|||
|
|||
@Override |
|||
public void setDeviceStatus(JSONObject data) { |
|||
|
|||
} |
|||
} |
@ -0,0 +1,60 @@ |
|||
package org.nl.acs.device_driver.basedriver.agv.agv_conveyor; |
|||
|
|||
import org.nl.acs.device.device_driver.standard_inspect.ItemDTO; |
|||
import org.nl.acs.device_driver.DeviceDriver; |
|||
import org.nl.acs.device_driver.definition.OpcDeviceDriverDefinition; |
|||
import org.nl.acs.opc.Device; |
|||
import org.nl.acs.opc.DeviceType; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.LinkedList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* AGV上料下料 |
|||
*/ |
|||
@Service |
|||
public class AgvConveyorDefinition implements OpcDeviceDriverDefinition { |
|||
@Override |
|||
public String getDriverCode() { |
|||
return "agv_conveyor"; |
|||
} |
|||
|
|||
@Override |
|||
public String getDriverName() { |
|||
return "AGV上料下料"; |
|||
} |
|||
|
|||
@Override |
|||
public String getDriverDescription() { |
|||
return "AGV上料下料"; |
|||
} |
|||
|
|||
@Override |
|||
public DeviceDriver getDriverInstance(Device device) { |
|||
return (new AgvConveyorConveyorDeviceDriver()).setDevice(device).setDriverDefinition(this); |
|||
} |
|||
|
|||
@Override |
|||
public Class<? extends DeviceDriver> getDeviceDriverType() { |
|||
return AgvConveyorConveyorDeviceDriver.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,96 @@ |
|||
package org.nl.acs.device_driver.basedriver.agv.agv_conveyor; |
|||
|
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.device.device_driver.standard_inspect.ItemDTO; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
@Slf4j |
|||
@Getter |
|||
@Setter |
|||
public class ItemProtocol { |
|||
|
|||
public static String item_heartbeat = "heartbeat"; |
|||
public static String item_on_off_site = "on_off_site"; |
|||
public static String item_tray_Information = "tray_Information"; |
|||
public static String item_down_request = "down_request"; |
|||
public static String item_up_request = "up_request"; |
|||
public static String item_to_up_finished = "to_up_finished "; |
|||
public static String item_to_down_finished = "to_down_finished"; |
|||
|
|||
|
|||
|
|||
private AgvConveyorConveyorDeviceDriver driver; |
|||
|
|||
public ItemProtocol(AgvConveyorConveyorDeviceDriver driver) { |
|||
this.driver = driver; |
|||
} |
|||
|
|||
public int getItem_heartbeat() { |
|||
return this.getOpcIntegerValue(item_heartbeat); |
|||
} |
|||
|
|||
public String getItem_on_off_site() { |
|||
return this.getOpcStringValue(item_on_off_site); |
|||
} |
|||
|
|||
public String getItem_tray_Information() { |
|||
return this.getOpcStringValue(item_tray_Information); |
|||
} |
|||
|
|||
public int getItem_down_request() { |
|||
return this.getOpcIntegerValue(item_down_request); |
|||
} |
|||
public int getItem_up_request() { |
|||
return this.getOpcIntegerValue(item_up_request); |
|||
} |
|||
|
|||
|
|||
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 (value == null) { |
|||
// log.error("读取错误!");
|
|||
} else { |
|||
return value; |
|||
} |
|||
return ""; |
|||
} |
|||
|
|||
public static List<ItemDTO> getReadableItemDtos() { |
|||
ArrayList list = new ArrayList(); |
|||
list.add(new ItemDTO(item_heartbeat, "心跳", "VW0")); |
|||
list.add(new ItemDTO(item_on_off_site, "上下站点", "VW2")); |
|||
list.add(new ItemDTO(item_tray_Information, "料盘信息", "VW4")); |
|||
list.add(new ItemDTO(item_down_request, "下料请求", "VW6")); |
|||
list.add(new ItemDTO(item_up_request, "上料请求", "VW8")); |
|||
|
|||
return list; |
|||
} |
|||
|
|||
public static List<ItemDTO> getWriteableItemDtos() { |
|||
ArrayList list = new ArrayList(); |
|||
list.add(new ItemDTO(item_to_up_finished, "上料完成", "VW102")); |
|||
list.add(new ItemDTO(item_to_down_finished, "下料完成", "VW104")); |
|||
return list; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
@ -0,0 +1,102 @@ |
|||
<template> |
|||
<!--AGV上料下料--> |
|||
<div> |
|||
<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" size="small" label-width="95px"> |
|||
<el-row> |
|||
<el-col :span="8"> |
|||
<el-form-item label="ip地址" prop="ip_address"> |
|||
<el-input |
|||
v-model="form.ip_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" /> |
|||
<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 |
|||
} from '@/api/acs/device/driverConfig' |
|||
import crud from '@/mixins/crud' |
|||
|
|||
export default { |
|||
name: 'StandardConveyorControl', |
|||
mixins: [crud], |
|||
props: { |
|||
parentForm: { |
|||
type: Object, |
|||
require: true |
|||
} |
|||
}, |
|||
data() { |
|||
return { |
|||
form: { |
|||
ip_address: '' |
|||
} |
|||
} |
|||
}, |
|||
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 |
|||
} |
|||
} |
|||
this.sliceItem() |
|||
}) |
|||
}) |
|||
}, |
|||
methods: { |
|||
doSubmit() { |
|||
this.$refs['form'].validate((valid) => { |
|||
if (valid) { |
|||
this.configLoading = true |
|||
// 根据驱动类型判断是否为路由设备 |
|||
const parentForm = this.parentForm |
|||
parentForm.is_route = true |
|||
updateConfig(parentForm, this.form, this.modeform, this.data1, this.data2).then(res => { |
|||
this.notify('保存成功', 'success') |
|||
this.configLoading = false |
|||
}).catch(err => { |
|||
this.configLoading = false |
|||
console.log(err.response.data.message) |
|||
}) |
|||
} |
|||
}) |
|||
} |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
|
|||
</style> |
Loading…
Reference in new issue