add 新驱动

This commit is contained in:
USER-20220102CG\noblelift
2023-07-28 15:11:34 +08:00
parent 1b65bd962e
commit 0486f40aca
11 changed files with 3254 additions and 3 deletions

View File

@@ -81,7 +81,12 @@ public enum DriverTypeEnum {
AGV_NDC_ONE(55, "agv_ndc_one", "NDC1楼AGV", "agv"),
AGV_NDC_TWO(56, "agv_ndc_two", "NDC2楼AGV", "agv");
AGV_NDC_TWO(56, "agv_ndc_two", "NDC2楼AGV", "agv"),
CONVEYOR_SSX_BARCODE(54, "conveyor_ssx_barcode", "标准版-下发条码输送线", "station"),
CONVEYOR_PRESS_STATION(54, "conveyor_press_station", "标准版-压制对接位", "station");
//驱动索引
private int index;

View File

@@ -40,7 +40,10 @@ public enum RequestMethodEnum {
feedback_task_status(15, "feedback_task_status", "反馈任务状态","1"),
feedback_device_status(16, "feedback_device_status", "反馈设备状态","1");
feedback_device_status(16, "feedback_device_status", "反馈设备状态","1"),
apply_feedback_weight(16, "apply_feedback_weight", "反馈压机残留重量","0");
//驱动索引
private int index;

View File

@@ -0,0 +1,62 @@
package org.nl.acs.device_driver.lnsh.converor_barcode;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination;
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;
/**
* 下发条码输送线工位
*
*/
@Service
public class ConveyorBarcodeDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "conveyor_ssx_barcode";
}
@Override
public String getDriverName() {
return "标准版-下发条码输送线";
}
@Override
public String getDriverDescription() {
return "标准版-下发条码输送线";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new LnshStationDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return LnshStationDeviceDriver.class;
}
@Override
public List<DeviceType> getFitDeviceTypes() {
List<DeviceType> types = new LinkedList();
types.add(DeviceType.station);
return types;
}
@Override
public List<ItemDto> getReadableItemDtos() {
return ItemProtocol.getReadableItemDtos();
}
@Override
public List<ItemDto> getWriteableItemDtos() {
return ItemProtocol.getWriteableItemDtos();
}
}

View File

@@ -0,0 +1,141 @@
package org.nl.acs.device_driver.lnsh.converor_barcode;
import cn.hutool.core.util.StrUtil;
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_mode = "mode";
public static String item_move = "move";
public static String item_action = "action";
public static String item_ioaction = "ioaction";
public static String item_error = "error";
public static String item_task = "task";
public static String item_weight = "weight";
public static String item_material = "material";
public static String item_barcode = "barcode";
public static String item_to_command = "to_command";
public static String item_to_target = "to_target";
public static String item_to_task = "to_task";
public static String item_to_barcode = "to_barcode";
Boolean isonline;
private LnshStationDeviceDriver driver;
public ItemProtocol(LnshStationDeviceDriver 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 getAction() {
return this.getOpcIntegerValue(item_action);
}
public int getIoAction() {
return this.getOpcIntegerValue(item_ioaction);
}
public int getError() {
return this.getOpcIntegerValue(item_error);
}
public int getTask() {
return this.getOpcIntegerValue(item_task);
}
public int getWeight() {
return this.getOpcIntegerValue(item_weight);
}
public String getMaterial() {
return this.getOpcStringValue(item_material);
}
public int getBarcode() {
return this.getOpcIntegerValue(item_barcode);
}
public int getToCommand() {
return this.getOpcIntegerValue(item_to_command);
}
public int getToTarget() {
return this.getOpcIntegerValue(item_to_target);
}
public int getToTask() {
return this.getOpcIntegerValue(item_to_task);
}
//是否有货
public int hasGoods(int move) {
return move;
}
public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) {
// log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return 0;
}
public String getOpcStringValue(String protocol) {
String value = this.driver.getStringValue(protocol);
if (StrUtil.isBlank(value)) {
// log.error("读取错误!");
} else {
return value;
}
return "0";
}
public static List<ItemDto> getReadableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_heartbeat, "心跳", "DB51.B0"));
list.add(new ItemDto(item_mode, "工作模式", "DB51.B1", Boolean.valueOf(true)));
list.add(new ItemDto(item_move, "光电开关信号", "DB51.B2"));
list.add(new ItemDto(item_error, "报警信号", "DB51.B3"));
list.add(new ItemDto(item_task, "任务号", "DB51.D4"));
list.add(new ItemDto(item_barcode, "条码", "DB51.W8"));
return list;
}
public static List<ItemDto> getWriteableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_to_command, "作业命令", "DB50.W0", Boolean.valueOf(true)));
list.add(new ItemDto(item_to_target, "目标站", "DB50.W2"));
list.add(new ItemDto(item_to_task, "任务号", "DB50.D4"));
list.add(new ItemDto(item_to_barcode, "条码", "DB50.W8"));
return list;
}
}

View File

@@ -0,0 +1,791 @@
package org.nl.acs.device_driver.lnsh.converor_barcode;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
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.RequestMethodEnum;
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.data.AcsToWmsData.applyTask.ApplyTaskRequest;
import org.nl.acs.ext.wms.data.Resp;
import org.nl.acs.ext.wms.service.AcsToWmsService;
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.route.service.RouteLineService;
import org.nl.acs.task.service.TaskService;
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 java.lang.reflect.Method;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 晟华-工位(交互模板)
*/
@Slf4j
@Getter
@Setter
@RequiredArgsConstructor
public class LnshStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, StandardRequestMethod {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
LuceneExecuteLogService lucene = SpringContextHolder.getBean("luceneExecuteLogServiceImpl");
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl");
RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl");
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl");
String device_code;
int mode = 0;
int error = 0;
int move = 0;
int action;
int io_action;
int task = 0;
int last_mode = 0;
int last_error = 0;
int last_move = 0;
int last_task = 0;
int last_action = 0;
int last_ioaction = 0;
Boolean isonline = true;
int hasGoods = 0;
Boolean iserror = false;
protected int instruction_num = 0;
protected int instruction_num_truth = 0;
Integer heartbeat_tag;
private Date instruction_require_time = new Date();
private Date instruction_finished_time = new Date();
private int instruction_require_time_out = 3000;
boolean requireSucess = false;
private int instruction_finished_time_out;
int heartbeat;
int last_heartbeat;
private Date checkHeartbeattime = new Date();
private Date last_checkHeartbeattime = new Date();
int branchProtocol = 0;
//当前指令
Instruction inst = null;
//上次指令
Instruction last_inst = null;
//触摸屏手动触发任务
private Boolean is_has_task = false;
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
int flag;
String message;
int weight = 0;
int last_weight = 0;
String material;
String last_material;
int barcode;
int last_barcode;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() {
message = null;
try {
device_code = this.getDeviceCode();
mode = this.itemProtocol.getMode();
error = this.itemProtocol.getError();
move = this.itemProtocol.getMove();
task = this.itemProtocol.getTask();
hasGoods = this.itemProtocol.getMove();
io_action = this.itemProtocol.getIoAction();
action = this.itemProtocol.getAction();
weight = this.itemProtocol.getWeight();
material = this.itemProtocol.getMaterial();
barcode = this.itemProtocol.getBarcode();
if (mode != last_mode) {
this.setRequireSucess(false);
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode));
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 (error != last_error) {
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 (action != last_action) {
logServer.deviceItemValue(this.device_code, "action", String.valueOf(action));
logServer.deviceExecuteLog(this.device_code, "", "", "信号action" + last_action + " -> " + action);
}
if (io_action != last_ioaction) {
logServer.deviceItemValue(this.device_code, "io_action", String.valueOf(io_action));
logServer.deviceExecuteLog(this.device_code, "", "", "信号io_action: " + last_ioaction + " -> " + io_action);
}
if (weight != last_weight) {
logServer.deviceItemValue(this.device_code, "weight", String.valueOf(weight));
logServer.deviceExecuteLog(this.device_code, "", "", "信号weight: " + last_weight + " -> " + weight);
}
if (!StrUtil.equals(material, last_material)) {
logServer.deviceItemValue(this.device_code, "material", material);
logServer.deviceExecuteLog(this.device_code, "", "", "信号material" + last_material + " -> " + material);
}
if (barcode != last_barcode) {
logServer.deviceItemValue(this.device_code, "barcode", String.valueOf(barcode));
logServer.deviceExecuteLog(this.device_code, "", "", "信号barcode" + last_barcode + " -> " + barcode);
}
} catch (Exception var17) {
return;
}
//急停
if (this.isStop()) {
//未联机
} 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;
if (mode > 2) {
if (ObjectUtil.isNotEmpty(this.device.getExtraValue().get(String.valueOf(mode)))) {
String modethod = this.device.getExtraValue().get(String.valueOf(mode)).toString();
try {
applyRequest(modethod);
} catch (Exception e) {
message = "错误:" + e.getMessage();
this.setIserror(true);
}
} else {
message = "无效模式请求,驱动未配置此请求方法";
}
} else {
message = "无请求";
}
Object ignore_pickup_check = this.getExtraValue().get("ignore_pickup_check");
}
last_mode = mode;
last_error = error;
last_move = move;
last_task = task;
last_action = action;
last_ioaction = io_action;
last_weight = weight;
last_material = material;
last_barcode = barcode;
}
public boolean exe_error() {
if (this.error == 0) {
return true;
} else {
log.debug("设备报警");
return false;
}
}
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 void executing(Server server, Map<String, Object> itemMap) {
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);
logServer.deviceExecuteLog(this.device_code, "", "", "to_command 写入 " + command);
} else if (type == 2) {
itemMap.put(to_target, command);
logServer.deviceExecuteLog(this.device_code, "", "", "to_target 写入 " + command);
} else if (type == 3) {
itemMap.put(to_task, command);
logServer.deviceExecuteLog(this.device_code, "", "", "to_task 写入 " + command);
}
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 synchronized void OpenOrClose(String type) {
//进入区域
if ("1".equals(type)) {
writing(5);
} else {
//离开区域
writing(6);
}
}
public String toString() {
return "";
}
@Override
public JSONObject getDeviceStatusName() throws Exception {
String mode;
String move;
String action;
String io_action;
boolean hasGoods;
switch (this.mode) {
case 0:
mode = "脱机";
break;
case 2:
mode = "待机";
break;
case 4:
mode = "叫料";
break;
case 5:
mode = "申请空盘";
break;
case 6:
mode = "申请入库";
break;
case 11:
mode = "半托缓存强制去包装";
break;
case 15:
mode = "送空托盘";
break;
default:
mode = String.valueOf(this.mode);
}
if (this.move == 0) {
move = "无货";
hasGoods = false;
} else {
move = "有货";
hasGoods = true;
}
switch (this.action) {
case 1:
action = "允许取货";
break;
case 2:
action = "允许放货";
break;
case 3:
action = "允许取放";
break;
default:
action = "禁止取放";
}
switch (this.io_action) {
case 1:
io_action = "允许进入";
break;
case 2:
io_action = "允许离开";
break;
case 3:
io_action = "允许进入离开";
break;
default:
io_action = "禁止进入离开";
}
String error;
switch (this.error) {
case 1:
error = "急停中";
break;
case 2:
error = "光幕报警";
break;
case 3:
error = "本体报警";
break;
case 4:
error = "未排产报警";
break;
case 5:
error = "扫码故障";
break;
default:
error = String.valueOf(this.error);
}
JSONObject jo = new JSONObject();
jo.put("device_name", this.getDevice().getDevice_name());
jo.put("mode", mode);
jo.put("move", move);
jo.put("action", action);
jo.put("io_action", io_action);
jo.put("error", error);
jo.put("task", task);
jo.put("weight", weight);
jo.put("barcode", barcode);
jo.put("isError", iserror);
jo.put("isOnline", isonline);
jo.put("hasGoods", hasGoods);
jo.put("message", message);
return jo;
}
@Override
public void setDeviceStatus(JSONObject data) {
}
/**
* 请求
*
* @param
*/
public synchronized boolean applyRequest(String modethod) throws Exception {
Object obj1 = this;
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;
Object obj = this.getClass().getDeclaredConstructor().newInstance();
Method method1 = this.getClass().getMethod(modethod, null);
method1.invoke(this, null);
return true;
}
}
/**
* 申请补满料盅托盘
*
* @param
*/
public synchronized boolean apply_put_full_vehicle() {
if(move == 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(Thread.currentThread().getStackTrace()[1].getMethodName());
request.setRequest_medthod_name(RequestMethodEnum.getName(Thread.currentThread().getStackTrace()[1].getMethodName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
message = RequestMethodEnum.getName("apply_put_full_vehicle") + "apply_put_full_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
Resp resp = acsToWmsService.applyTask(request);
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_put_full_vehicle") + "apply_put_full_vehicle 接口请求失败" + resp.getComment();;
}
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return true;
} else {
message = RequestMethodEnum.getName("apply_put_full_vehicle") + "apply_put_full_vehicle 设备有货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请补空料盅托盘
*
* @param
*/
public synchronized boolean apply_put_empty_vehicle() {
if(move == 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 设备有货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请取走空料盅托盘
*
* @param
*/
public synchronized boolean apply_take_empty_vehicle() {
if(move == 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_take_empty_vehicle") + "apply_take_empty_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_take_empty_vehicle") + "apply_take_empty_vehicle 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_take_empty_vehicle") + "apply_take_empty_vehicle 设备有货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请取走满料盅托盘
*
* @param
*/
public synchronized boolean apply_take_full_vehicle() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_take_full_vehicle") + "apply_take_full_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_take_full_vehicle") + "apply_take_full_vehicle 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_take_full_vehicle") + "apply_take_full_vehicle 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请强制取走满料盅托盘
*
* @param
*/
public synchronized boolean apply_force_take_full_vehicle() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_force_take_full_vehicle") + "apply_force_take_full_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_force_take_full_vehicle") + "apply_force_take_full_vehicle 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_force_take_full_vehicle") + "apply_force_take_full_vehicle 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请强制满托入缓存
*
* @param
*/
public synchronized boolean apply_force_take_full_vehicle_in_storage() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_force_take_full_vehicle_in_storage") + "apply_force_take_full_vehicle_in_storage 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_force_take_full_vehicle_in_storage") + "apply_force_take_full_vehicle_in_storage 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_force_take_full_vehicle_in_storage") + "apply_force_take_full_vehicle_in_storage 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 扫码成功申请
*
* @param
*/
public synchronized boolean barcode_sucess_apply() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("barcode_sucess_apply") + "barcode_sucess_apply 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("barcode_sucess_apply") + "barcode_sucess_apply 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("barcode_sucess_apply") + "barcode_sucess_apply 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 获取组盘信息
*
* @param
*/
public synchronized boolean get_vehicle_info() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("get_vehicle_info") + "get_vehicle_info 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("get_vehicle_info") + "get_vehicle_info 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("get_vehicle_info") + "get_vehicle_info 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 强制去包装-不包装
*/
public synchronized boolean force_no_package() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("force_no_package") + "force_no_package 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("force_no_package") + "force_no_package 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("force_no_package") + "force_no_package 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请贴标
*/
public synchronized boolean apply_labelling() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_labelling") + "apply_labelling 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_labelling") + "apply_labelling 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_labelling") + "apply_labelling 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
}

View File

@@ -0,0 +1,62 @@
package org.nl.acs.device_driver.lnsh.conveyor_press_station;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination;
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;
/**
* 晟华-工位(交互模板)
*
*/
@Service
public class ConveyorPressStationDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "conveyor_press_station";
}
@Override
public String getDriverName() {
return "标准版-压制对接位";
}
@Override
public String getDriverDescription() {
return "标准版-压制对接位";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new ConveyorPressStationDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return ConveyorPressStationDeviceDriver.class;
}
@Override
public List<DeviceType> getFitDeviceTypes() {
List<DeviceType> types = new LinkedList();
types.add(DeviceType.station);
return types;
}
@Override
public List<ItemDto> getReadableItemDtos() {
return ItemProtocol.getReadableItemDtos();
}
@Override
public List<ItemDto> getWriteableItemDtos() {
return ItemProtocol.getWriteableItemDtos();
}
}

View File

@@ -0,0 +1,791 @@
package org.nl.acs.device_driver.lnsh.conveyor_press_station;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
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.RequestMethodEnum;
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.data.AcsToWmsData.applyTask.ApplyTaskRequest;
import org.nl.acs.ext.wms.data.Resp;
import org.nl.acs.ext.wms.service.AcsToWmsService;
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.route.service.RouteLineService;
import org.nl.acs.task.service.TaskService;
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 java.lang.reflect.Method;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 晟华-工位(交互模板)
*/
@Slf4j
@Getter
@Setter
@RequiredArgsConstructor
public class ConveyorPressStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, StandardRequestMethod {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
LuceneExecuteLogService lucene = SpringContextHolder.getBean("luceneExecuteLogServiceImpl");
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl");
RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl");
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl");
String device_code;
int mode = 0;
int error = 0;
int move = 0;
int action;
int io_action;
int task = 0;
int last_mode = 0;
int last_error = 0;
int last_move = 0;
int last_task = 0;
int last_action = 0;
int last_ioaction = 0;
Boolean isonline = true;
int hasGoods = 0;
Boolean iserror = false;
protected int instruction_num = 0;
protected int instruction_num_truth = 0;
Integer heartbeat_tag;
private Date instruction_require_time = new Date();
private Date instruction_finished_time = new Date();
private int instruction_require_time_out = 3000;
boolean requireSucess = false;
private int instruction_finished_time_out;
int heartbeat;
int last_heartbeat;
private Date checkHeartbeattime = new Date();
private Date last_checkHeartbeattime = new Date();
int branchProtocol = 0;
//当前指令
Instruction inst = null;
//上次指令
Instruction last_inst = null;
//触摸屏手动触发任务
private Boolean is_has_task = false;
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
int flag;
String message;
int weight = 0;
int last_weight = 0;
String material;
String last_material;
int barcode;
int last_barcode;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() {
message = null;
try {
device_code = this.getDeviceCode();
mode = this.itemProtocol.getMode();
error = this.itemProtocol.getError();
move = this.itemProtocol.getMove();
task = this.itemProtocol.getTask();
hasGoods = this.itemProtocol.getMove();
io_action = this.itemProtocol.getIoAction();
action = this.itemProtocol.getAction();
weight = this.itemProtocol.getWeight();
material = this.itemProtocol.getMaterial();
barcode = this.itemProtocol.getBarcode();
if (mode != last_mode) {
this.setRequireSucess(false);
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode));
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 (error != last_error) {
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 (action != last_action) {
logServer.deviceItemValue(this.device_code, "action", String.valueOf(action));
logServer.deviceExecuteLog(this.device_code, "", "", "信号action" + last_action + " -> " + action);
}
if (io_action != last_ioaction) {
logServer.deviceItemValue(this.device_code, "io_action", String.valueOf(io_action));
logServer.deviceExecuteLog(this.device_code, "", "", "信号io_action: " + last_ioaction + " -> " + io_action);
}
if (weight != last_weight) {
logServer.deviceItemValue(this.device_code, "weight", String.valueOf(weight));
logServer.deviceExecuteLog(this.device_code, "", "", "信号weight: " + last_weight + " -> " + weight);
}
if (!StrUtil.equals(material, last_material)) {
logServer.deviceItemValue(this.device_code, "material", material);
logServer.deviceExecuteLog(this.device_code, "", "", "信号material" + last_material + " -> " + material);
}
if (barcode != last_barcode) {
logServer.deviceItemValue(this.device_code, "barcode", String.valueOf(barcode));
logServer.deviceExecuteLog(this.device_code, "", "", "信号barcode" + last_barcode + " -> " + barcode);
}
} catch (Exception var17) {
return;
}
//急停
if (this.isStop()) {
//未联机
} 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;
if (mode > 2) {
if (ObjectUtil.isNotEmpty(this.device.getExtraValue().get(String.valueOf(mode)))) {
String modethod = this.device.getExtraValue().get(String.valueOf(mode)).toString();
try {
applyRequest(modethod);
} catch (Exception e) {
message = "错误:" + e.getMessage();
this.setIserror(true);
}
} else {
message = "无效模式请求,驱动未配置此请求方法";
}
} else {
message = "无请求";
}
Object ignore_pickup_check = this.getExtraValue().get("ignore_pickup_check");
}
last_mode = mode;
last_error = error;
last_move = move;
last_task = task;
last_action = action;
last_ioaction = io_action;
last_weight = weight;
last_material = material;
last_barcode = barcode;
}
public boolean exe_error() {
if (this.error == 0) {
return true;
} else {
log.debug("设备报警");
return false;
}
}
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 void executing(Server server, Map<String, Object> itemMap) {
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);
logServer.deviceExecuteLog(this.device_code, "", "", "to_command 写入 " + command);
} else if (type == 2) {
itemMap.put(to_target, command);
logServer.deviceExecuteLog(this.device_code, "", "", "to_target 写入 " + command);
} else if (type == 3) {
itemMap.put(to_task, command);
logServer.deviceExecuteLog(this.device_code, "", "", "to_task 写入 " + command);
}
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 synchronized void OpenOrClose(String type) {
//进入区域
if ("1".equals(type)) {
writing(5);
} else {
//离开区域
writing(6);
}
}
public String toString() {
return "";
}
@Override
public JSONObject getDeviceStatusName() throws Exception {
String mode;
String move;
String action;
String io_action;
boolean hasGoods;
switch (this.mode) {
case 0:
mode = "脱机";
break;
case 2:
mode = "待机";
break;
case 4:
mode = "叫料";
break;
case 5:
mode = "申请空盘";
break;
case 6:
mode = "申请入库";
break;
case 11:
mode = "半托缓存强制去包装";
break;
case 15:
mode = "送空托盘";
break;
default:
mode = String.valueOf(this.mode);
}
if (this.move == 0) {
move = "无货";
hasGoods = false;
} else {
move = "有货";
hasGoods = true;
}
switch (this.action) {
case 1:
action = "允许取货";
break;
case 2:
action = "允许放货";
break;
case 3:
action = "允许取放";
break;
default:
action = "禁止取放";
}
switch (this.io_action) {
case 1:
io_action = "允许进入";
break;
case 2:
io_action = "允许离开";
break;
case 3:
io_action = "允许进入离开";
break;
default:
io_action = "禁止进入离开";
}
String error;
switch (this.error) {
case 1:
error = "急停中";
break;
case 2:
error = "光幕报警";
break;
case 3:
error = "本体报警";
break;
case 4:
error = "未排产报警";
break;
case 5:
error = "扫码故障";
break;
default:
error = String.valueOf(this.error);
}
JSONObject jo = new JSONObject();
jo.put("device_name", this.getDevice().getDevice_name());
jo.put("mode", mode);
jo.put("move", move);
jo.put("action", action);
jo.put("io_action", io_action);
jo.put("error", error);
jo.put("task", task);
jo.put("weight", weight);
jo.put("barcode", barcode);
jo.put("isError", iserror);
jo.put("isOnline", isonline);
jo.put("hasGoods", hasGoods);
jo.put("message", message);
return jo;
}
@Override
public void setDeviceStatus(JSONObject data) {
}
/**
* 请求
*
* @param
*/
public synchronized boolean applyRequest(String modethod) throws Exception {
Object obj1 = this;
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;
Object obj = this.getClass().getDeclaredConstructor().newInstance();
Method method1 = this.getClass().getMethod(modethod, null);
method1.invoke(this, null);
return true;
}
}
/**
* 申请补满料盅托盘
*
* @param
*/
public synchronized boolean apply_put_full_vehicle() {
if(move == 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(Thread.currentThread().getStackTrace()[1].getMethodName());
request.setRequest_medthod_name(RequestMethodEnum.getName(Thread.currentThread().getStackTrace()[1].getMethodName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
message = RequestMethodEnum.getName("apply_put_full_vehicle") + "apply_put_full_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
Resp resp = acsToWmsService.applyTask(request);
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_put_full_vehicle") + "apply_put_full_vehicle 接口请求失败" + resp.getComment();;
}
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return true;
} else {
message = RequestMethodEnum.getName("apply_put_full_vehicle") + "apply_put_full_vehicle 设备有货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请补空料盅托盘
*
* @param
*/
public synchronized boolean apply_put_empty_vehicle() {
if(move == 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 设备有货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请取走空料盅托盘
*
* @param
*/
public synchronized boolean apply_take_empty_vehicle() {
if(move == 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_take_empty_vehicle") + "apply_take_empty_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_take_empty_vehicle") + "apply_take_empty_vehicle 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_take_empty_vehicle") + "apply_take_empty_vehicle 设备有货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请取走满料盅托盘
*
* @param
*/
public synchronized boolean apply_take_full_vehicle() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_take_full_vehicle") + "apply_take_full_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_take_full_vehicle") + "apply_take_full_vehicle 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_take_full_vehicle") + "apply_take_full_vehicle 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请强制取走满料盅托盘
*
* @param
*/
public synchronized boolean apply_force_take_full_vehicle() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_force_take_full_vehicle") + "apply_force_take_full_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_force_take_full_vehicle") + "apply_force_take_full_vehicle 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_force_take_full_vehicle") + "apply_force_take_full_vehicle 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请强制满托入缓存
*
* @param
*/
public synchronized boolean apply_force_take_full_vehicle_in_storage() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_force_take_full_vehicle_in_storage") + "apply_force_take_full_vehicle_in_storage 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_force_take_full_vehicle_in_storage") + "apply_force_take_full_vehicle_in_storage 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_force_take_full_vehicle_in_storage") + "apply_force_take_full_vehicle_in_storage 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 扫码成功申请
*
* @param
*/
public synchronized boolean barcode_sucess_apply() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("barcode_sucess_apply") + "barcode_sucess_apply 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("barcode_sucess_apply") + "barcode_sucess_apply 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("barcode_sucess_apply") + "barcode_sucess_apply 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 获取组盘信息
*
* @param
*/
public synchronized boolean get_vehicle_info() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("get_vehicle_info") + "get_vehicle_info 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("get_vehicle_info") + "get_vehicle_info 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("get_vehicle_info") + "get_vehicle_info 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 强制去包装-不包装
*/
public synchronized boolean force_no_package() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("force_no_package") + "force_no_package 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("force_no_package") + "force_no_package 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("force_no_package") + "force_no_package 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
/**
* 申请贴标
*/
public synchronized boolean apply_labelling() {
if(move > 0) {
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(this.getClass().getName());
request.setRequest_medthod_name(RequestMethodEnum.getName(this.getClass().getName()));
request.setWeight(String.valueOf(weight));
request.setVehicle_code(String.valueOf(barcode));
Resp resp = acsToWmsService.applyTask(request);
message = RequestMethodEnum.getName("apply_labelling") + "apply_labelling 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (StrUtil.equals(resp.result, "true")) {
this.writing(this.mode);
this.setRequireSucess(true);
} else {
this.writing(400);
message = RequestMethodEnum.getName("apply_labelling") + "apply_labelling 接口请求失败" + resp.getComment();;
}
return true;
} else {
message = RequestMethodEnum.getName("apply_labelling") + "apply_labelling 设备无货未请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
return false;
}
}
}

View File

@@ -0,0 +1,147 @@
package org.nl.acs.device_driver.lnsh.conveyor_press_station;
import cn.hutool.core.util.StrUtil;
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_mode = "mode";
public static String item_move = "move";
public static String item_action = "action";
public static String item_ioaction = "ioaction";
public static String item_error = "error";
public static String item_task = "task";
public static String item_weight = "weight";
public static String item_material = "material";
public static String item_barcode = "barcode";
public static String item_to_command = "to_command";
public static String item_to_target = "to_target";
public static String item_to_task = "to_task";
public static String item_to_barcode = "to_barcode";
public static String item_to_mix_num = "to_mix_num";
Boolean isonline;
private ConveyorPressStationDeviceDriver driver;
public ItemProtocol(ConveyorPressStationDeviceDriver 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 getAction() {
return this.getOpcIntegerValue(item_action);
}
public int getIoAction() {
return this.getOpcIntegerValue(item_ioaction);
}
public int getError() {
return this.getOpcIntegerValue(item_error);
}
public int getTask() {
return this.getOpcIntegerValue(item_task);
}
public int getWeight() {
return this.getOpcIntegerValue(item_weight);
}
public String getMaterial() {
return this.getOpcStringValue(item_material);
}
public int getBarcode() {
return this.getOpcIntegerValue(item_barcode);
}
public int getToCommand() {
return this.getOpcIntegerValue(item_to_command);
}
public int getToTarget() {
return this.getOpcIntegerValue(item_to_target);
}
public int getToTask() {
return this.getOpcIntegerValue(item_to_task);
}
//是否有货
public int hasGoods(int move) {
return move;
}
public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) {
// log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return 0;
}
public String getOpcStringValue(String protocol) {
String value = this.driver.getStringValue(protocol);
if (StrUtil.isBlank(value)) {
// log.error("读取错误!");
} else {
return value;
}
return "0";
}
public static List<ItemDto> getReadableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_heartbeat, "心跳", "DB8.B0"));
list.add(new ItemDto(item_mode, "工作模式", "DB8.B1", Boolean.valueOf(true)));
list.add(new ItemDto(item_move, "光电开关信号", "DB8.B2"));
list.add(new ItemDto(item_action, "取放信号", "DB8.B3"));
list.add(new ItemDto(item_ioaction, "进出信号", "DB8.B4"));
list.add(new ItemDto(item_error, "报警信号", "DB8.B5"));
list.add(new ItemDto(item_task, "任务号", "DB8.D6"));
list.add(new ItemDto(item_weight, "重量", "DB8.D10"));
list.add(new ItemDto(item_material, "物料", "DB8.STRING14.50"));
list.add(new ItemDto(item_barcode, "条码", "DB8.W66"));
return list;
}
public static List<ItemDto> getWriteableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_to_command, "作业命令", "DB9.W0", Boolean.valueOf(true)));
list.add(new ItemDto(item_to_target, "目标站", "DB9.W2"));
list.add(new ItemDto(item_to_task, "任务号", "DB9.D4"));
list.add(new ItemDto(item_to_barcode, "条码", "DB9.W8"));
list.add(new ItemDto(item_to_mix_num, "碾次", "DB9.W10"));
return list;
}
}