刘先源
1 month ago
14 changed files with 375 additions and 812 deletions
Binary file not shown.
@ -1,485 +1,154 @@ |
|||
package org.nl.acs.device_driver.basedriver.standard_conveyor_control; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
import cn.hutool.core.util.IdUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.Setter; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
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.DeviceDriverBaseReader; |
|||
import org.nl.acs.device_driver.RouteableDeviceDriver; |
|||
import org.nl.acs.device_driver.StandardRequestMethod; |
|||
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.opc.WcsConfig; |
|||
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.system.util.CodeUtil; |
|||
import org.nl.modules.wql.core.bean.WQLObject; |
|||
import org.nl.modules.lucene.service.LuceneExecuteLogService; |
|||
import org.nl.modules.lucene.service.dto.LuceneLogDto; |
|||
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; |
|||
|
|||
/** |
|||
* 输送机-控制点驱动 |
|||
*/ |
|||
@Slf4j |
|||
@Getter |
|||
@Setter |
|||
@RequiredArgsConstructor |
|||
public class StandardCoveyorControlDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { |
|||
protected ItemProtocol itemProtocol = new ItemProtocol(this); |
|||
|
|||
DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); |
|||
|
|||
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); |
|||
|
|||
DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); |
|||
|
|||
RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); |
|||
|
|||
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); |
|||
|
|||
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); |
|||
|
|||
AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); |
|||
|
|||
ParamService paramService = SpringContextHolder.getBean(ParamService.class); |
|||
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); |
|||
|
|||
|
|||
String container; |
|||
String container_type_desc; |
|||
String last_container_type_desc; |
|||
String last_container; |
|||
//放货准备锁
|
|||
String putReadyLock = null; |
|||
//有货标记
|
|||
protected boolean has_goods_tag = false; |
|||
public class StandardCoveyorControlDeviceDriver extends AbstractOpcDeviceDriver implements |
|||
DeviceDriver, |
|||
ExecutableDeviceDriver, |
|||
RouteableDeviceDriver, |
|||
DeviceStageMonitor, |
|||
StandardRequestMethod, |
|||
DeviceDriverBaseReader { |
|||
|
|||
int mode = 0; |
|||
int error = 0; |
|||
int move = 0; |
|||
int action = 0; |
|||
String barcode = null; |
|||
int task = 0; |
|||
//出入库模式
|
|||
int operation_type = 0; |
|||
int last_mode = 0; |
|||
int last_error = 0; |
|||
int last_move = 0; |
|||
int last_task = 0; |
|||
private final LuceneExecuteLogService logService = SpringContextHolder.getBean(LuceneExecuteLogService.class); |
|||
|
|||
Boolean isonline = true; |
|||
int hasGoods = 0; |
|||
String message = null; |
|||
Boolean iserror = false; |
|||
|
|||
|
|||
boolean hasVehicle = false; |
|||
boolean isReady = false; |
|||
protected int instruction_num = 0; |
|||
protected int instruction_num_truth = 0; |
|||
boolean isFold = false; |
|||
private String assemble_check_tag; |
|||
|
|||
protected String current_stage_instruction_message; |
|||
protected String last_stage_instruction_message; |
|||
Integer heartbeat_tag; |
|||
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; |
|||
//请求成功标记
|
|||
Boolean requireSucess = false; |
|||
//申请指令成功标记
|
|||
Boolean applySucess = false; |
|||
String inst_message; |
|||
|
|||
private int instruction_finished_time_out; |
|||
/** |
|||
* 心跳 |
|||
*/ |
|||
private int heartbeat = 0; |
|||
private int lastHeartbeat = 0; |
|||
/** |
|||
* 工作模式 |
|||
*/ |
|||
private int mode = 0; |
|||
private int lastMode = 0; |
|||
/** |
|||
* 光电信号 |
|||
*/ |
|||
private int move = 0; |
|||
private int lastMove = 0; |
|||
/** |
|||
* 取放信号 |
|||
*/ |
|||
private int action = 0; |
|||
private int lastAction = 0; |
|||
/** |
|||
* 报警信号 |
|||
*/ |
|||
private int error = 0; |
|||
private int lastError = 0; |
|||
/** |
|||
* 托盘号 |
|||
*/ |
|||
private String barcode; |
|||
private String lastBarcode; |
|||
/** |
|||
* 下发命令 |
|||
*/ |
|||
private int toCommand = 0; |
|||
private int lastToCommand = 0; |
|||
/** |
|||
* 当前设备编号 |
|||
*/ |
|||
private String currentDeviceCode; |
|||
|
|||
int branchProtocol = 0; |
|||
//备注
|
|||
String remark; |
|||
//数量
|
|||
String qty; |
|||
//物料
|
|||
String material; |
|||
//当前指令
|
|||
Instruction inst = null; |
|||
//上次指令
|
|||
Instruction last_inst = null; |
|||
/** |
|||
* 消息 |
|||
*/ |
|||
private String message; |
|||
|
|||
//触摸屏手动触发任务
|
|||
private Boolean is_has_task = false; |
|||
/** |
|||
* 请求标记 |
|||
*/ |
|||
boolean requireSuccess = false; |
|||
|
|||
//申请搬运任务
|
|||
private Boolean apply_handling = false; |
|||
//申请物料
|
|||
private Boolean apply_material = false; |
|||
/** |
|||
* 请求时间 |
|||
*/ |
|||
private long requireTime = System.currentTimeMillis(); |
|||
|
|||
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
|
|||
int flag = 0; |
|||
/** |
|||
* 请求间隔时间 |
|||
*/ |
|||
private long requireTimeOut = 3000L; |
|||
|
|||
String device_code; |
|||
/** |
|||
* 设备异常标记 |
|||
*/ |
|||
private boolean isError = false; |
|||
|
|||
@Override |
|||
public Device getDevice() { |
|||
return this.device; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public void execute() throws Exception { |
|||
String message = null; |
|||
try { |
|||
device_code = this.getDeviceCode(); |
|||
mode = this.itemProtocol.getMode(); |
|||
error = this.itemProtocol.getError(); |
|||
move = this.itemProtocol.getMove(); |
|||
task = this.itemProtocol.getTask(); |
|||
action = this.itemProtocol.getAction(); |
|||
barcode = this.itemProtocol.getBarcode(); |
|||
hasGoods = this.itemProtocol.getMove(); |
|||
operation_type = this.itemProtocol.getOperation_type(); |
|||
if (mode != last_mode) { |
|||
} |
|||
if (move != last_move) { |
|||
if (move == 0) { |
|||
thingToNothing(); |
|||
} |
|||
this.setRequireSucess(false); |
|||
|
|||
} |
|||
if (error != last_error) { |
|||
} |
|||
|
|||
/* if (mode == 2 && move != 0 && task > 0) { |
|||
//inst_message
|
|||
inst = instructionService.findByCodeFromCache(String.valueOf(task)); |
|||
if (inst != null) { |
|||
inst_message = "指令号:" + inst.getInstruction_code() + " " + inst.getStart_point_code() + " -> " + inst.getNext_point_code() + " 载具号:" + inst.getVehicle_code(); |
|||
if (StrUtil.equals(inst.getInstruction_status(), "1") && StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { |
|||
finish_instruction(); |
|||
} |
|||
if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { |
|||
inst.setInstruction_status("1"); |
|||
instructionService.update(inst); |
|||
} |
|||
} |
|||
}*/ |
|||
} catch (Exception var17) { |
|||
return; |
|||
} |
|||
|
|||
if (!this.itemProtocol.getIsonline()) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
message = "信号量同步异常"; |
|||
//未联机
|
|||
} else if (mode == 0) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
message = "未联机"; |
|||
//有报警
|
|||
} else if (error != 0) { |
|||
this.setIsonline(false); |
|||
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: |
|||
//申请任务
|
|||
break; |
|||
case 3: |
|||
|
|||
break; |
|||
case 4: |
|||
//叫料
|
|||
|
|||
break; |
|||
case 5: |
|||
//申请空盘
|
|||
break; |
|||
case 6: |
|||
//申请入库
|
|||
break; |
|||
} |
|||
|
|||
|
|||
switch (flag) { |
|||
//取货完成
|
|||
case 1: |
|||
writing(2); |
|||
break; |
|||
//放货完成
|
|||
case 2: |
|||
writing(3); |
|||
break; |
|||
|
|||
} |
|||
|
|||
} |
|||
last_mode = mode; |
|||
last_error = error; |
|||
last_move = move; |
|||
last_task = task; |
|||
} |
|||
|
|||
public boolean exe_error() { |
|||
if (this.error == 0) { |
|||
return true; |
|||
} else { |
|||
log.debug("设备报警"); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
protected void thingToNothing() { |
|||
log.debug("从有货到无货 清理数据"); |
|||
this.setRequireSucess(false); |
|||
this.setApplySucess(false); |
|||
this.set_last_container(container, container_type_desc); |
|||
} |
|||
|
|||
public void set_last_container(String barcode, String type_desc) { |
|||
this.setInst_message(null); |
|||
this.setContainer(null); |
|||
this.set_last_container(barcode); |
|||
this.set_last_container_type_desc(type_desc); |
|||
} |
|||
|
|||
public void set_last_container(String barcode) { |
|||
} |
|||
|
|||
public void set_last_container_type_desc(String type) { |
|||
} |
|||
|
|||
|
|||
public boolean exe_business() { |
|||
return true; |
|||
} |
|||
|
|||
protected void executing(Instruction instruction) { |
|||
this.executing(1, instruction, ""); |
|||
} |
|||
|
|||
public void executing(int command, Instruction instruction, String appendMessage) { |
|||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_command; |
|||
String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_target; |
|||
String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_task; |
|||
if (appendMessage == null) { |
|||
appendMessage = ""; |
|||
} |
|||
if (instruction != null) { |
|||
instruction_num = Integer.parseInt(instruction.getInstruction_code()); |
|||
} |
|||
String opcservcerid = this.getDevice().getOpc_server_id(); |
|||
Server server = ReadUtil.getServer(opcservcerid); |
|||
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|||
itemMap.put(to_command, 1); |
|||
itemMap.put(to_task, instruction_num); |
|||
ReadUtil.write(itemMap, server); |
|||
server.disconnect(); |
|||
|
|||
public <E extends Enum<E> & KeyProvider, T> T getOpcValue(E item, Class<T> fieldClassType) { |
|||
return (T) this.getValue(item.getKey()); |
|||
} |
|||
|
|||
public void executing(Server server, Map<String, Object> itemMap) { |
|||
ReadUtil.write(itemMap, server); |
|||
server.disconnect(); |
|||
} |
|||
|
|||
public void writing(int command) { |
|||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_command; |
|||
|
|||
String opcservcerid = this.getDevice().getOpc_server_id(); |
|||
Server server = ReadUtil.getServer(opcservcerid); |
|||
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|||
itemMap.put(to_command, command); |
|||
ReadUtil.write(itemMap, server); |
|||
ReadUtil.write(itemMap, server); |
|||
server.disconnect(); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "to_command 写入 " + command); |
|||
} |
|||
|
|||
public void writing(int command, int target, int task) { |
|||
|
|||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_command; |
|||
String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_target; |
|||
String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_task; |
|||
String opcservcerid = this.getDevice().getOpc_server_id(); |
|||
Server server = ReadUtil.getServer(opcservcerid); |
|||
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|||
itemMap.put(to_command, command); |
|||
itemMap.put(to_target, target); |
|||
itemMap.put(to_task, task); |
|||
ReadUtil.write(itemMap, server); |
|||
server.disconnect(); |
|||
} |
|||
|
|||
public void writing(int type, int command) { |
|||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_command; |
|||
String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_target; |
|||
String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_task; |
|||
String opcservcerid = this.getDevice().getOpc_server_id(); |
|||
Server server = ReadUtil.getServer(opcservcerid); |
|||
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|||
if (type == 1) { |
|||
itemMap.put(to_command, command); |
|||
} else if (type == 2) { |
|||
itemMap.put(to_target, command); |
|||
|
|||
} else if (type == 3) { |
|||
itemMap.put(to_task, command); |
|||
} |
|||
ReadUtil.write(itemMap, server); |
|||
server.disconnect(); |
|||
|
|||
} |
|||
|
|||
public boolean instruction_apply() throws Exception { |
|||
return false; |
|||
} |
|||
|
|||
public boolean instruction_require(String container_code) { |
|||
return instruction_require(container_code, WcsConfig.task_container_type_default_desc); |
|||
} |
|||
|
|||
/** |
|||
* 请求指令 |
|||
* |
|||
* @param container_code |
|||
* @param container_type |
|||
*/ |
|||
public synchronized boolean instruction_require(String container_code, String container_type) { |
|||
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; |
|||
TaskDto dto = new TaskDto(); |
|||
String now = DateUtil.now(); |
|||
dto.setTask_id(IdUtil.simpleUUID()); |
|||
dto.setCreate_by(this.getDevice().getDevice_code()); |
|||
dto.setUpdate_by(this.getDevice().getDevice_code()); |
|||
dto.setStart_point_code(this.getDevice().getDevice_code()); |
|||
dto.setVehicle_code(container_code); |
|||
dto.setVehicle_type(container_type); |
|||
|
|||
String taskcode = CodeUtil.getNewCode("TASK_NO"); |
|||
dto.setTask_code("-" + taskcode); |
|||
dto.setTask_status("0"); |
|||
dto.setPriority("101"); |
|||
RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); |
|||
String next_device_codecode = jo.getNext_device_code(); |
|||
if (StrUtil.isBlank(next_device_codecode)) { |
|||
throw new RuntimeException("该设备未找到对应路由"); |
|||
} |
|||
dto.setNext_point_code(next_device_codecode); |
|||
dto.setUpdate_time(now); |
|||
dto.setCreate_time(now); |
|||
|
|||
WQLObject wo = WQLObject.getWQLObject("acs_task"); |
|||
JSONObject json = (JSONObject) JSONObject.toJSON(dto); |
|||
|
|||
wo.insert(json); |
|||
requireSucess = false; |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
|
|||
public synchronized boolean finish_instruction() throws Exception { |
|||
instructionService.finish(inst); |
|||
return true; |
|||
@Override |
|||
public void setLog(String key, Object newValue, Object oldValue) { |
|||
logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "自动线程读取信号:" + key + ",由" + oldValue + "->" + newValue)); |
|||
} |
|||
|
|||
public void apply_OutEmpty() { |
|||
|
|||
@Override |
|||
public void execute() { |
|||
this.currentDeviceCode = this.getDevice().getDevice_code(); |
|||
this.loadAssignData(currentDeviceCode, ItemProtocol.class); |
|||
} |
|||
|
|||
public synchronized boolean apply_InEmpty() throws Exception { |
|||
return false; |
|||
@Override |
|||
public void executeLogic() { |
|||
if (!this.online) { |
|||
this.message = "设备离线"; |
|||
} else if (this.mode == 0) { |
|||
this.message = "设备未联机"; |
|||
} else if (this.error != 0) { |
|||
this.message = "设备报警"; |
|||
this.isError = true; |
|||
} else { |
|||
this.isError = false; |
|||
this.message = ""; |
|||
//编写业务逻辑方法
|
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public JSONObject getDeviceStatusName() { |
|||
JSONObject jo = new JSONObject(); |
|||
String mode = ""; |
|||
String action = ""; |
|||
String move = ""; |
|||
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", this.getIsonline()); |
|||
jo.put("error", this.getError()); |
|||
jo.put("isError", this.getIserror()); |
|||
jo.put("task", this.getTask()); |
|||
return jo; |
|||
public JSONObject getDeviceStatusName() throws Exception { |
|||
JSONObject jo = new JSONObject(); |
|||
jo.put("device_code", this.currentDeviceCode); |
|||
jo.put("device_name", this.getDevice().getDevice_name()); |
|||
jo.put("driver_type", "standard_conveyor_control"); |
|||
jo.put("is_click", false); |
|||
jo.put("message", this.message); |
|||
jo.put("isOnline", this.online); |
|||
jo.put("isError", this.isError); |
|||
return jo; |
|||
} |
|||
|
|||
@Override |
|||
public void setDeviceStatus(JSONObject data) { |
|||
|
|||
|
|||
} |
|||
|
|||
} |
|||
|
Loading…
Reference in new issue