|
|
|
|
@ -101,7 +101,7 @@ public class S7MultiPlcService {
|
|
|
|
|
private final Map<String, PlcReadData> readDataCache = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
// 上一次读取的托盘码缓存: plcNumber -> 上次托盘码
|
|
|
|
|
private final Map<String, String> lastPalletCache = new ConcurrentHashMap<>();
|
|
|
|
|
private final Map<String, PlcReadData> lastPalletCache = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
// 连接池大小
|
|
|
|
|
private final int POOL_SIZE = 3;
|
|
|
|
|
@ -392,17 +392,24 @@ public class S7MultiPlcService {
|
|
|
|
|
plcNumber, data.getPalletNo(), data.getBatchNo(), data.getDate(), data.getSnapFlag());
|
|
|
|
|
|
|
|
|
|
// 检查托盘号是否需要处理
|
|
|
|
|
String lastPallet = lastPalletCache.get(plcNumber);
|
|
|
|
|
PlcReadData lastPlcData = lastPalletCache.get(plcNumber);
|
|
|
|
|
boolean needProcess = false;
|
|
|
|
|
if (data.getSnapFlag() == 0){
|
|
|
|
|
|
|
|
|
|
// 标记拍照修改
|
|
|
|
|
writePhotoResult(plcNumber, (byte) 0);
|
|
|
|
|
}else {
|
|
|
|
|
if (data.getSnapFlag() == 1 && (lastPallet == null || !lastPallet.equals(data.getPalletNo()))) {
|
|
|
|
|
if (data.getSnapFlag() == 1 && (lastPlcData == null || !lastPlcData.getPalletNo().equals(data.getPalletNo()))) {
|
|
|
|
|
|
|
|
|
|
// 托盘号变化或首次启动
|
|
|
|
|
needProcess = true;
|
|
|
|
|
}
|
|
|
|
|
if (lastPlcData != null && data.getSnapFlag() == 1 && (lastPlcData.getPalletNo().equals(data.getPalletNo()))&& lastPlcData.isValid()) {
|
|
|
|
|
|
|
|
|
|
// 标记拍照完成
|
|
|
|
|
log.info("PLC {} 拍照完成 再次标注", plcNumber);
|
|
|
|
|
writePhotoResult(plcNumber, (byte) 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (lastPallet == null) {
|
|
|
|
|
@ -419,13 +426,17 @@ public class S7MultiPlcService {
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (needProcess) {
|
|
|
|
|
lastPalletCache.put(plcNumber, data.getPalletNo());
|
|
|
|
|
lastPalletCache.put(plcNumber, data);
|
|
|
|
|
// 触发灯
|
|
|
|
|
if (config.getLightChannel() != null) {
|
|
|
|
|
lightService.pulse(config.getLightChannel(), lightConfig.getDuration(),
|
|
|
|
|
lightConfig.getRes(), lightConfig.getIp(), lightConfig.getPort());
|
|
|
|
|
}
|
|
|
|
|
log.info("PLC {} 托盘号变化: {} -> {}", plcNumber, lastPallet, data.getPalletNo());
|
|
|
|
|
if (lastPlcData != null) {
|
|
|
|
|
log.info("PLC {} 托盘号变化: {} -> {}", plcNumber, lastPlcData.getPalletNo(), data.getPalletNo());
|
|
|
|
|
}else {
|
|
|
|
|
log.info("PLC {} 首次启动,托盘号: {}", plcNumber, data.getPalletNo());
|
|
|
|
|
}
|
|
|
|
|
sleep(500);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -457,6 +468,8 @@ public class S7MultiPlcService {
|
|
|
|
|
cameraUrl.setPlc(plcNumber);
|
|
|
|
|
cameraUrlService.saveOrUpdate(cameraUrl);
|
|
|
|
|
|
|
|
|
|
readDataCache.get(plcNumber).setValid(true);
|
|
|
|
|
|
|
|
|
|
// 标记拍照完成
|
|
|
|
|
writePhotoResult(plcNumber, (byte) 1);
|
|
|
|
|
}
|
|
|
|
|
@ -833,6 +846,7 @@ public class S7MultiPlcService {
|
|
|
|
|
private byte snapFlag; // 允许拍照标志
|
|
|
|
|
private byte photoResult; // 拍照结果
|
|
|
|
|
private long updateTime; // 更新时间
|
|
|
|
|
private boolean isValid =false; // 是否有效
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
|