feat: 解包机、输送线驱动开发v1.0

This commit is contained in:
2025-08-11 16:08:33 +08:00
parent 7ba2d12e1d
commit e629ad5534
11 changed files with 758 additions and 4 deletions

View File

@@ -19,7 +19,9 @@ public enum DeviceType {
plcDb("plcDb块", 13),
shadow("影子设备", 15),
button("按钮",14),
other("其他设备", 16);
other("其他设备", 16),
unpacking("解包机", 17),
unpacking_converyor("解包机输送线", 18);
private String code;

View File

@@ -227,7 +227,7 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
return true;
} else {
throw new RuntimeException("下发 无内容");
throw new RuntimeException("下发无内容");
}
}

View File

@@ -10,8 +10,7 @@ import java.util.List;
@Slf4j
@Data
public class
ItemProtocol {
public class ItemProtocol {
//心跳
public static String item_heartbeat = "heartbeat";

View File

@@ -0,0 +1,132 @@
package org.nl.acs.device_driver.zz_driver.unpacking_conveyor;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import java.util.ArrayList;
import java.util.List;
/**
* 解包机输送线驱动
* @Author: lyd
* @Date: 2025/8/11
*/
@Data
@Slf4j
public class ItemProtocol {
/**
* 心跳
*/
public static String item_heartbeat = "heartbeat";
/**
* 工作模式
*/
public static String item_mode = "mode";
/**
* 光电信号
*/
public static String item_move = "move";
/**
* 动作信号
*/
public static String item_action = "action";
/**
* 错误
*/
public static String item_error = "error";
/**
* 1-到达取货点取货申请2-取货完成3-到达放货点放货申请4-放货完成5-复位99-失败
*/
public static String item_to_command = "to_command";
private UnpackingConveyorDeviceDriver driver;
public ItemProtocol(UnpackingConveyorDeviceDriver driver) {
this.driver = driver;
}
/** =============== 从kep获取plc的值 ================ */
public int getHeartbeat() {
return getOpcIntegerValue(item_heartbeat);
}
public int getMode() {
return getOpcIntegerValue(item_mode);
}
public int getMove() {
return getOpcIntegerValue(item_move);
}
public int getAction() {
return getOpcIntegerValue(item_action);
}
public int getError() {
return getOpcIntegerValue(item_error);
}
public int getTo_command() {
return getOpcIntegerValue(item_to_command);
}
Boolean isonline;
/**
* 获取int值
* @param protocol
* @return
*/
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;
}
/**
* 获取string值
* @param protocol
* @return
*/
public String getOpcStringValue(String protocol) {
String value = this.driver.getStringValue(protocol);
if (StrUtil.isBlank(value)) {
} else {
return value;
}
return "0";
}
/**
* 获取读取的模块信息
* @return
*/
public static List<ItemDto> getReadableItemDtos() {
ArrayList<ItemDto> list = new ArrayList<>();
list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0"));
list.add(new ItemDto(item_mode, "工作模式", "DB1.B1"));
list.add(new ItemDto(item_action, "动作信号", "DB1.B3"));
list.add(new ItemDto(item_mode, "光电", "DB1.B4"));
list.add(new ItemDto(item_error, "报警", "DB1.B5"));
return list;
}
/**
* 获取写入的模块信息
* @return
*/
public static List<ItemDto> getWriteableItemDtos() {
ArrayList<ItemDto> list = new ArrayList<>();
list.add(new ItemDto(item_to_command, "下发命令", "DB2.W0"));
return list;
}
}

View File

@@ -0,0 +1,60 @@
package org.nl.acs.device_driver.zz_driver.unpacking_conveyor;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device.domain.Device;
import org.nl.acs.device.enums.DeviceType;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination;
import org.springframework.stereotype.Service;
import java.util.LinkedList;
import java.util.List;
/**
* @Author: lyd
* @Date: 2025/8/11
*/
@Service
public class UnpackingConveyorDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "unpacking_conveyor";
}
@Override
public String getDriverName() {
return "解包机输送线驱动";
}
@Override
public String getDriverDescription() {
return "解包机输送线驱动";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new UnpackingConveyorDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return UnpackingConveyorDeviceDriver.class;
}
@Override
public List<DeviceType> getFitDeviceTypes() {
List<DeviceType> types = new LinkedList();
types.add(DeviceType.unpacking_converyor);
return types;
}
@Override
public List<ItemDto> getReadableItemDtos() {
return ItemProtocol.getReadableItemDtos();
}
@Override
public List<ItemDto> getWriteableItemDtos() {
return ItemProtocol.getWriteableItemDtos();
}
}

View File

@@ -0,0 +1,171 @@
package org.nl.acs.device_driver.zz_driver.unpacking_conveyor;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.domain.Device;
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.history.ErrorUtil;
import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.config.language.LangProcess;
import org.nl.config.lucene.service.LuceneExecuteLogService;
import org.nl.config.lucene.service.dto.LuceneLogDto;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @Author: lyd
* @Date: 2025/8/11
*/
@Slf4j
@Data
public class UnpackingConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
/** 协议 */
protected ItemProtocol itemProtocol = new ItemProtocol(this);
@Resource
private DeviceExecuteLogService logServer;
@Resource
private LuceneExecuteLogService luceneExecuteLogService;
private Date instruction_require_time = new Date();
private Date instruction_finished_time = new Date();
private Date instruction_apply_time = new Date();
private int instruction_require_time_out = 3000;
/** 心跳 */
int heartbeat = 0;
int last_heartbeat = 0;
/** 工作模式 */
int mode = 0;
int last_mode = 0;
/** 工作模式 */
int move = 0;
int last_move = 0;
/** 动作信号: 0-不允许取放1-允许取放 */
int action = 0;
int last_action = 0;
/** 错误 */
int error = 0;
int last_error = 0;
/** 下发命令: 1-到达取货点取货申请2-取货完成3-到达放货点放货申请4-放货完成5-复位99-失败 */
int to_command = 0;
int last_to_command = 0;
Boolean isonline = true;
int hasGoods = 0;
String message = null;
Boolean iserror = false;
String device_code;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() throws Exception {
// 具体业务
try {
device_code = this.getDeviceCode();
heartbeat = itemProtocol.getHeartbeat();
mode = itemProtocol.getMode();
action = itemProtocol.getAction();
move = itemProtocol.getMove();
error = itemProtocol.getError();
if (move == 1 && mode == 5 && mode != last_mode) {
// 1、todo: 请求LMS横移
// 2、复位
this.writing("to_command", 5);
}
} catch (Exception e) {
return;
}
last_mode = mode;
last_action = action;
last_move = move;
last_error =error;
last_to_command = to_command;
}
public void writing(Map<String, Object> map) throws Exception {
Map<String, Object> itemMap = new LinkedHashMap<>();
map.forEach((key, value) -> {
if (ObjectUtil.isNotEmpty(value)) {
itemMap.put(getToParam(key), value);
}
});
if (ObjectUtil.isNotEmpty(itemMap)) {
this.checkcontrol(itemMap);
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code(device_code)
.content("下发多个电气信号" + itemMap)
.build();
logDto.setLog_level(3);
luceneExecuteLogService.deviceExecuteLog(logDto);
}
}
public void writing(String commandKey, int command) {
Map<String, Object> itemMap = new HashMap<>();
itemMap.put(getToParam(commandKey), command);
this.control(itemMap);
}
public String getToParam(String key) {
return this.getDevice().getOpc_server_code()
+ "." + this.getDevice().getOpc_plc_code()
+ "." + this.getDevice().getDevice_code()
+ "." + key;
}
@Override
public JSONObject getDeviceStatusName() throws Exception {
JSONObject jo = new JSONObject();
String mode = "";
String move = "";
if (this.getMode() == 0) {
mode = LangProcess.msg("universal_off-line");
} else if (this.getMode() == 1) {
mode = LangProcess.msg("universal_stand-alone");
} else if (this.getMode() == 2) {
mode = LangProcess.msg("universal_standby");
} else if (this.getMode() == 3) {
mode = LangProcess.msg("universal_operation");
}
if (this.getMove() == 0) {
move = LangProcess.msg("universal_no");
jo.put("hasGoods", false);
} else if (this.getMove() == 1) {
move = LangProcess.msg("universal_yes");
jo.put("hasGoods", true);
} else if (this.getMove() == 2) {
move = LangProcess.msg("universal_two_yes");
jo.put("hasGoods", true);
}
String action = "";
jo.put("device_name", this.getDevice().getDevice_name());
jo.put("mode", mode);
jo.put("move", move);jo.put("action", action);
jo.put("isOnline", true);
// jo.put("error", ErrorUtil.getDictDetail("gxhj_error_type", String.valueOf(this.getError())));
// jo.put("isError", this.getIserror());
return jo;
}
@Override
public void setDeviceStatus(JSONObject data) {
}
}

View File

@@ -0,0 +1,6 @@
/**
* 解包机输送线驱动
* @Author: lyd
* @Date: 2025/8/11
*/
package org.nl.acs.device_driver.zz_driver.unpacking_conveyor;

View File

@@ -0,0 +1,142 @@
package org.nl.acs.device_driver.zz_driver.unpacking_machine;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import java.util.ArrayList;
import java.util.List;
/**
* 拆包机协议
*
* @Author: lyd
* @Date: 2025/8/11
*/
@Slf4j
@Data
public class ItemProtocol {
/**
* 心跳
*/
public static String item_heartbeat = "heartbeat";
/**
* 工作模式
*/
public static String item_mode = "mode";
/**
* 动作信号
*/
public static String item_action = "action";
/**
* 毛重
*/
public static String item_gross_weight = "gross_weight";
/**
* 净重
*/
public static String item_net_weight = "net_weight";
/**
* 1-到达取货点取货申请2-取货完成3-到达放货点放货申请4-放货完成
*/
public static String item_to_command = "to_command";
/**
* 1-去皮2-清皮4-清零;
*/
public static String item_to_operate = "to_operate";
private UnpackingMachineDeviceDriver driver;
public ItemProtocol(UnpackingMachineDeviceDriver driver) {
this.driver = driver;
}
/** =============== 从kep获取plc的值 ================ */
public int getHeartbeat() {
return this.getOpcIntegerValue(item_heartbeat);
}
public int getMode() {
return this.getOpcIntegerValue(item_mode);
}
public int getAction() {
return this.getOpcIntegerValue(item_action);
}
public String getGross_weight() {
return this.getOpcStringValue(item_gross_weight);
}
public String getNet_weight() {
return getOpcStringValue(item_net_weight);
}
public int getTo_command() {
return getOpcIntegerValue(item_to_command);
}
public int getTo_operate() {
return getOpcIntegerValue(item_to_operate);
}
Boolean isonline;
/**
* 获取int值
* @param protocol
* @return
*/
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;
}
/**
* 获取string值
* @param protocol
* @return
*/
public String getOpcStringValue(String protocol) {
String value = this.driver.getStringValue(protocol);
if (StrUtil.isBlank(value)) {
} else {
return value;
}
return "0";
}
/**
* 获取读取的模块信息
* @return
*/
public static List<ItemDto> getReadableItemDtos() {
ArrayList<ItemDto> list = new ArrayList<>();
list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0"));
list.add(new ItemDto(item_mode, "工作模式", "DB1.B1"));
list.add(new ItemDto(item_action, "动作信号", "DB1.B3"));
list.add(new ItemDto(item_gross_weight, "毛重", "DB1.B4"));
list.add(new ItemDto(item_net_weight, "净重", "DB1.B5"));
return list;
}
/**
* 获取写入的模块信息
* @return
*/
public static List<ItemDto> getWriteableItemDtos() {
ArrayList<ItemDto> list = new ArrayList<>();
list.add(new ItemDto(item_to_command, "下发命令", "DB2.W0"));
list.add(new ItemDto(item_to_operate, "下发操作", "DB2.W2"));
return list;
}
}

View File

@@ -0,0 +1,61 @@
package org.nl.acs.device_driver.zz_driver.unpacking_machine;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device.domain.Device;
import org.nl.acs.device.enums.DeviceType;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination;
import org.springframework.stereotype.Service;
import java.util.LinkedList;
import java.util.List;
/**
* 解包机驱动定义
* @Author: lyd
* @Date: 2025/8/11
*/
@Service
public class UnpackingMachineDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "unpacking_machine";
}
@Override
public String getDriverName() {
return "解包机设备驱动";
}
@Override
public String getDriverDescription() {
return "解包机设备驱动";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new UnpackingMachineDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return UnpackingMachineDeviceDriver.class;
}
@Override
public List<DeviceType> getFitDeviceTypes() {
List<DeviceType> types = new LinkedList();
types.add(DeviceType.unpacking);
return types;
}
@Override
public List<ItemDto> getReadableItemDtos() {
return ItemProtocol.getReadableItemDtos();
}
@Override
public List<ItemDto> getWriteableItemDtos() {
return ItemProtocol.getWriteableItemDtos();
}
}

View File

@@ -0,0 +1,175 @@
package org.nl.acs.device_driver.zz_driver.unpacking_machine;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.domain.Device;
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.log.service.DeviceExecuteLogService;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.config.language.LangProcess;
import org.nl.config.lucene.service.LuceneExecuteLogService;
import org.nl.config.lucene.service.dto.LuceneLogDto;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 解包机驱动类
* @Author: lyd
* @Date: 2025/8/11
*/
@Slf4j
@Data
public class UnpackingMachineDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
/** 协议 */
protected ItemProtocol itemProtocol = new ItemProtocol(this);
@Resource
private DeviceExecuteLogService logServer;
@Resource
private LuceneExecuteLogService luceneExecuteLogService;
private Date instruction_require_time = new Date();
private Date instruction_finished_time = new Date();
private Date instruction_apply_time = new Date();
private int instruction_require_time_out = 3000;
/** 心跳 */
int heartbeat = 0;
int last_heartbeat = 0;
/** 工作模式 */
int mode = 0;
int last_mode = 0;
/** 动作信号: 0-不允许取放1-允许取放 */
int action = 0;
int last_action = 0;
/** 毛重 */
String gross_weight = "0";
String last_gross_weight = "0";
/** 净重 */
String net_weight = "0";
String last_net_weight = "0";
/** 下发命令: 1-到达取货点取货申请2-取货完成3-到达放货点放货申请4-放货完成 */
int to_command = 0;
int last_to_command = 0;
/** 下发操作: 1-去皮2-清皮4-清零; */
int to_operate = 0;
int last_to_operate = 0;
Boolean isonline = true;
int hasGoods = 0;
String message = null;
Boolean iserror = false;
String device_code;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() throws Exception {
// 具体业务
try {
device_code = this.getDeviceCode();
heartbeat = itemProtocol.getHeartbeat();
mode = itemProtocol.getMode();
action = itemProtocol.getAction();
gross_weight = itemProtocol.getGross_weight();
net_weight = itemProtocol.getNet_weight();
} catch (Exception e) {
return;
}
if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
//未联机
} else if (mode == 0) {
this.setIsonline(false);
this.setIserror(true);
//有报警
} else {
this.setIsonline(true);
this.setIserror(false);
}
last_mode = mode;
last_action = action;
last_heartbeat = heartbeat;
last_gross_weight = gross_weight;
last_net_weight = net_weight;
last_to_command = to_command;
last_to_operate = to_operate;
}
public void writing(Map<String, Object> map) throws Exception {
Map<String, Object> itemMap = new LinkedHashMap<>();
map.forEach((key, value) -> {
if (ObjectUtil.isNotEmpty(value)) {
itemMap.put(getToParam(key), value);
}
});
if (ObjectUtil.isNotEmpty(itemMap)) {
this.checkcontrol(itemMap);
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code(device_code)
.content("下发多个电气信号" + itemMap)
.build();
logDto.setLog_level(3);
luceneExecuteLogService.deviceExecuteLog(logDto);
}
}
public void writing(String commandKey, int command) {
Map<String, Object> itemMap = new HashMap<>();
itemMap.put(getToParam(commandKey), command);
this.control(itemMap);
}
public String getToParam(String key) {
return this.getDevice().getOpc_server_code()
+ "." + this.getDevice().getOpc_plc_code()
+ "." + this.getDevice().getDevice_code()
+ "." + key;
}
@Override
public JSONObject getDeviceStatusName() throws Exception {
JSONObject jo = new JSONObject();
String mode = "";
String move = "";
if (this.getMode() == 0) {
mode = LangProcess.msg("universal_off-line");
} else if (this.getMode() == 1) {
mode = LangProcess.msg("universal_stand-alone");
} else if (this.getMode() == 2) {
mode = LangProcess.msg("universal_standby");
} else if (this.getMode() == 3) {
mode = LangProcess.msg("universal_operation");
}
String action = "";
jo.put("device_name", this.getDevice().getDevice_name());
jo.put("mode", mode);
jo.put("move", move);
jo.put("action", action);
jo.put("isOnline", true);
jo.put("isError", this.getIserror());
return jo;
}
@Override
public void setDeviceStatus(JSONObject data) {
}
}

View File

@@ -0,0 +1,6 @@
/**
* 拆包机驱动 - 解包下料工位(解包机)
* @Author: lyd
* @Date: 2025/8/11
*/
package org.nl.acs.device_driver.zz_driver.unpacking_machine;