Commit 315e3959 authored by wanghao's avatar wanghao

1 老化过程中 如果读取不到数据 时 ,给 点位 赋值 通讯故障 状态调整。

parent 4f500f25
...@@ -139,29 +139,28 @@ public class AgingStageOneProcessJob implements Job { ...@@ -139,29 +139,28 @@ public class AgingStageOneProcessJob implements Job {
private CompletableFuture<Boolean> processDeviceWithWrite(String ip, int port, int deviceId, AtomicInteger errorCount) { private CompletableFuture<Boolean> processDeviceWithWrite(String ip, int port, int deviceId, AtomicInteger errorCount) {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
ModbusMaster master = null; ModbusMaster master = null;
PalletDeviceBinding binding = null; // 1. 查询设备绑定信息
PalletDeviceBinding binding = palletDeviceBindingMapper.selectByTrayIdAndIndex(ip, deviceId);
if (binding == null) {
log.warn("未找到设备绑定: ip={}, deviceId={}", ip, deviceId);
recordAlarm(null, "ip:" + ip + ",port:" + port + ",deviceId:" + deviceId, "未找到设备绑定");
errorCount.incrementAndGet();
return false;
}
try { try {
// 1. 读取设备数据 // 2. 读取设备数据
int[] result = Modbus4jUtils.readDeviceWithRetry(ip, port, deviceId); int[] result = Modbus4jUtils.readDeviceWithRetry(ip, port, deviceId);
// 2. 查询设备绑定信息
binding = palletDeviceBindingMapper.selectByTrayIdAndIndex(ip, deviceId);
if (binding == null) {
log.warn("未找到设备绑定: ip={}, deviceId={}", ip, deviceId);
recordAlarm(null, "ip:" + ip + ",port:" + port + ",deviceId:" + deviceId, "未找到设备绑定");
errorCount.incrementAndGet();
return false;
}
// 3. 更新设备状态 // 3. 更新设备状态
binding.setStatus(String.valueOf(result[1])); binding.setStatus(String.valueOf(result[1]));
// 3. 更新浓度值 // 4. 更新浓度值
binding.setConcentration(String.valueOf(result[0])); binding.setConcentration(String.valueOf(result[0]));
// 重用之前的master连接进行写操作 // 重用之前的master连接进行写操作
master = Modbus4jUtils.createModbusMaster(ip, port); master = Modbus4jUtils.createModbusMaster(ip, port);
// 4. 条件写入时间 // 5. 条件写入时间
if (result[1] == 1 || result[1] == 3 || result[1] == 4) { if (result[1] == 1 || result[1] == 3 || result[1] == 4) {
// writeCurrentTimeToDevice(master, deviceId, binding); // writeCurrentTimeToDevice(master, deviceId, binding);
WriteCurrentTimeVo writeCurrentTimeVo = WriteCurrentTimeUtil.generateWriteCurrentTimeVo(); WriteCurrentTimeVo writeCurrentTimeVo = WriteCurrentTimeUtil.generateWriteCurrentTimeVo();
...@@ -195,11 +194,9 @@ public class AgingStageOneProcessJob implements Job { ...@@ -195,11 +194,9 @@ public class AgingStageOneProcessJob implements Job {
} catch (Exception e) { } catch (Exception e) {
log.info("设备{}处理异常: ip={}, port={}", deviceId, ip, port, e); log.info("设备{}处理异常: ip={}, port={}", deviceId, ip, port, e);
if(binding != null) { binding.setStatus("5");
binding.setStatus("5"); binding.setWriteTimeStatus("0");
binding.setWriteTimeStatus("0"); palletDeviceBindingMapper.updatePalletDeviceBinding(binding);
palletDeviceBindingMapper.updatePalletDeviceBinding(binding);
}
errorCount.incrementAndGet(); errorCount.incrementAndGet();
return false; return false;
} finally { } finally {
......
...@@ -153,20 +153,18 @@ public class AgingStageThreeProcessJob implements Job { ...@@ -153,20 +153,18 @@ public class AgingStageThreeProcessJob implements Job {
private CompletableFuture<Boolean> processDeviceWithWrite(String ip, int port, int deviceId, AtomicInteger errorCount) { private CompletableFuture<Boolean> processDeviceWithWrite(String ip, int port, int deviceId, AtomicInteger errorCount) {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
ModbusMaster master = null; ModbusMaster master = null;
PalletDeviceBinding binding = null; // 1. 查询设备绑定信息
PalletDeviceBinding binding = palletDeviceBindingMapper.selectByTrayIdAndIndex(ip, deviceId);
if (binding == null) {
log.warn("未找到设备绑定: ip={}, deviceId={}", ip, deviceId);
recordAlarm(null, "ip:" + ip + ",port:" + port + ",deviceId:" + deviceId, "未找到设备绑定");
errorCount.incrementAndGet();
return false;
}
try { try {
// 1. 读取设备数据 // 2. 读取设备数据
int[] result = Modbus4jUtils.readDeviceWithRetry(ip, port, deviceId); int[] result = Modbus4jUtils.readDeviceWithRetry(ip, port, deviceId);
// 2. 查询设备绑定信息
binding = palletDeviceBindingMapper.selectByTrayIdAndIndex(ip, deviceId);
if (binding == null) {
log.warn("未找到设备绑定: ip={}, deviceId={}", ip, deviceId);
recordAlarm(null, "ip:" + ip + ",port:" + port + ",deviceId:" + deviceId, "未找到设备绑定");
errorCount.incrementAndGet();
return false;
}
// 3. 更新设备状态 // 3. 更新设备状态
binding.setStatus(String.valueOf(result[1])); binding.setStatus(String.valueOf(result[1]));
...@@ -219,9 +217,6 @@ public class AgingStageThreeProcessJob implements Job { ...@@ -219,9 +217,6 @@ public class AgingStageThreeProcessJob implements Job {
} catch (Exception e) { } catch (Exception e) {
log.error("设备{}处理异常: ip={}, port={}", deviceId, ip, port, e); log.error("设备{}处理异常: ip={}, port={}", deviceId, ip, port, e);
if(binding == null) {
binding = palletDeviceBindingMapper.selectByTrayIdAndIndex(ip, deviceId);
}
binding.setStatus("5"); binding.setStatus("5");
binding.setWriteTimeStatus("0"); binding.setWriteTimeStatus("0");
binding.setRunTimeStatus("0"); binding.setRunTimeStatus("0");
......
...@@ -177,20 +177,20 @@ public class AgingStageTwoProcessJob implements Job { ...@@ -177,20 +177,20 @@ public class AgingStageTwoProcessJob implements Job {
*/ */
private CompletableFuture<Boolean> processDeviceWithWrite(String ip, int port, int deviceId, AtomicInteger errorCount) { private CompletableFuture<Boolean> processDeviceWithWrite(String ip, int port, int deviceId, AtomicInteger errorCount) {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
PalletDeviceBinding binding;
// 1. 查询设备绑定信息
PalletDeviceBinding binding = palletDeviceBindingMapper.selectByTrayIdAndIndex(ip, deviceId);
if (binding == null) {
log.warn("未找到设备绑定: ip={}, deviceId={}", ip, deviceId);
recordAlarm(null, "ip:" + ip + ",port:" + port + ",deviceId:" + deviceId, "未找到设备绑定");
errorCount.incrementAndGet();
return false;
}
ModbusMaster master = null; ModbusMaster master = null;
try { try {
// 1. 读取设备数据 // 2. 读取设备数据
int[] result = Modbus4jUtils.readDeviceWithRetry(ip, port, deviceId); int[] result = Modbus4jUtils.readDeviceWithRetry(ip, port, deviceId);
// 2. 查询设备绑定信息
binding = palletDeviceBindingMapper.selectByTrayIdAndIndex(ip, deviceId);
if (binding == null) {
log.warn("未找到设备绑定: ip={}, deviceId={}", ip, deviceId);
recordAlarm(null, "ip:" + ip + ",port:" + port + ",deviceId:" + deviceId, "未找到设备绑定");
errorCount.incrementAndGet();
return false;
}
if(result[10] == 1) { if(result[10] == 1) {
binding.setRelayStatus(1); binding.setRelayStatus(1);
} else { } else {
...@@ -232,6 +232,8 @@ public class AgingStageTwoProcessJob implements Job { ...@@ -232,6 +232,8 @@ public class AgingStageTwoProcessJob implements Job {
} catch (Exception e) { } catch (Exception e) {
log.info("设备{}处理异常: ip={}, port={}", deviceId, ip, port, e); log.info("设备{}处理异常: ip={}, port={}", deviceId, ip, port, e);
binding.setStatus("5");
palletDeviceBindingMapper.updatePalletDeviceBinding(binding);
errorCount.incrementAndGet(); errorCount.incrementAndGet();
return false; return false;
}finally { }finally {
......
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