Commit 904fe89d authored by junshizhonglangjiang's avatar junshizhonglangjiang

1 上电断电调整

2 查询设备信息调整
parent 0158886c
......@@ -24,7 +24,7 @@ spring:
maxActive: 50 # 最大连接数增加到50,考虑72个Job并发 + 业务连接
# 2. 连接获取优化(解决Quartz获取连接超时问题)
maxWait: 5000 # 获取连接最大等待时间5秒,避免Quartz线程阻塞
maxWait: 30000 # 获取连接最大等待时间5秒,避免Quartz线程阻塞
# 3. 连接保活核心配置(解决"discard long time none received connection"警告)
timeBetweenEvictionRunsMillis: 30000 # 检测间隔30秒,更频繁检查连接有效性
......
......@@ -47,7 +47,7 @@ token:
# 令牌密钥
secret: abcdefghijklmnopqrstuvwxyz
# 令牌有效期(默认30分钟)
expireTime: 30
expireTime: 3000000
# MyBatis配置
mybatis:
......
......@@ -21,7 +21,6 @@ import java.util.concurrent.ConcurrentHashMap;
* @date 2025/9/25
* @description TODO
*/
@Component
public class ModbusMasterPool {
private static final Logger log = LoggerFactory.getLogger(ModbusMasterPool.class);
......@@ -213,7 +212,6 @@ public class ModbusMasterPool {
/**
* 容器关闭时销毁所有连接池(避免资源泄漏)
*/
@PostConstruct
public void init() {
log.info("ModbusMasterPool初始化成功");
// JVM关闭钩子:确保容器关闭时销毁所有池
......
......@@ -132,11 +132,13 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
TEquipmentInfo tEquipmentInfo = equipmentInfoMapper.selectTEquipmentInfoByCode(split[0]);
int layer = Integer.parseInt(split[0]);
int layer = Integer.parseInt(split[1]);
int registerOffsetInt = layer - 1;
try {
ModbusMaster master = Modbus4jUtils.getMaster(tEquipmentInfo.getfPowerOutageIp(), tEquipmentInfo.getfPowerOutagePort());
Modbus4jUtils.writeCoil(master, 1, layer, false);
Modbus4jUtils.writeCoil(master, 1, registerOffsetInt, false);
log.info("已发送断电指令 - 设备:{} 层:{}", tEquipmentInfo.getfEquipmentCode(), layer);
master.destroy();
} catch (ModbusTransportException | ModbusInitException e) {
......@@ -356,9 +358,10 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
throw new RuntimeException("托盘不存在");
}
if(!"0".equals(tTrayInfo.getfStatus())) {
throw new RuntimeException("托盘未解绑,请联系管理员");
}
// 20251104 上料 不需要看托盘状态了
// if(!"0".equals(tTrayInfo.getfStatus())) {
// throw new RuntimeException("托盘未解绑,请联系管理员");
// }
TStoreyInfo tStoreyInfo = storeyInfoMapper.selectNearestFreeStorey();
if(tStoreyInfo != null) {
......
......@@ -63,9 +63,6 @@ public abstract class BaseDeviceCommJob implements Job {
@Resource
protected ModbusResultHandler resultHandler;
@Resource
private ModbusMasterPool modbusMasterPool;
@Resource
private Scheduler scheduler;
......@@ -89,7 +86,6 @@ public abstract class BaseDeviceCommJob implements Job {
// 新增:校验依赖是否为null
log.info("=== 依赖注入校验 ===");
log.info("modbusMasterPool: {}", modbusMasterPool == null ? "NULL" : "OK");
log.info("scheduler: {}", scheduler == null ? "NULL" : "OK");
log.info("palletDeviceBindingMapper: {}", palletDeviceBindingMapper == null ? "NULL" : "OK");
log.info("alarmDataService: {}", alarmDataService == null ? "NULL" : "OK");
......@@ -249,8 +245,8 @@ public abstract class BaseDeviceCommJob implements Job {
* Modbus读取(带重试,连接用完即时销毁)
*/
private int[] readModbusWithRetry(String ip, int port, int deviceId) throws Exception {
// 1. 从连接池借连接(超时3秒
ModbusMaster master = modbusMasterPool.borrowMaster(ip, port);
// 1. 从连接池借连接(超时3秒
ModbusMaster master = Modbus4jUtils.getMaster(ip, port);
for (int retry = 0; retry <= CUSTOM_RETRY_TIMES; retry++) {
try {
// 2. 读取寄存器
......@@ -269,9 +265,7 @@ public abstract class BaseDeviceCommJob implements Job {
log.info("Modbus读取异常,重试:retry={}, port={}, deviceId={}", retry, port, deviceId, e);
} finally {
// 3. 无论成功/失败,归还连接到池(关键:避免连接泄漏)
if (master != null) {
modbusMasterPool.returnMaster(ip, port, master);
}
master.destroy();
}
}
log.info("Modbus读取无有效结果:ip=" + ip + ", port=" + port + ", deviceId=" + deviceId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment