|
@@ -40,13 +40,19 @@ public class PressPanel extends JPanel {
|
|
|
private final int uploadMax;
|
|
private final int uploadMax;
|
|
|
private final DcPressPlcClient plc;
|
|
private final DcPressPlcClient plc;
|
|
|
|
|
|
|
|
- /** 本批冲次起点;中途复位后按已产重定 */
|
|
|
|
|
|
|
+ /** 本批冲次起点(PLC 累计值);中途复位后按已产重定 */
|
|
|
private volatile long baseStrokeCount;
|
|
private volatile long baseStrokeCount;
|
|
|
|
|
+ /** 上一拍冲次累计,用于检测复位 */
|
|
|
private volatile long lastStrokeCount;
|
|
private volatile long lastStrokeCount;
|
|
|
|
|
+ /** 本批已产冲次差(当前批次数量,非 PLC 总冲次) */
|
|
|
private volatile int producedQty;
|
|
private volatile int producedQty;
|
|
|
|
|
+ /** 本批冲次起点是否已标定;未标定前不算本批进度,避免把总冲次当本批 */
|
|
|
|
|
+ private volatile boolean baseStrokeReady;
|
|
|
/** 当前已绑定的共享批次码;变化时重定冲次起点 */
|
|
/** 当前已绑定的共享批次码;变化时重定冲次起点 */
|
|
|
private volatile String boundBatchCode = "";
|
|
private volatile String boundBatchCode = "";
|
|
|
|
|
+ /** 上次采样时刻 */
|
|
|
private volatile long lastSampleAtMs;
|
|
private volatile long lastSampleAtMs;
|
|
|
|
|
+ /** 最近一拍压机快照 */
|
|
|
private volatile DcPressSnapshot lastSnap = new DcPressSnapshot();
|
|
private volatile DcPressSnapshot lastSnap = new DcPressSnapshot();
|
|
|
/** 待落库采样点(内存缓冲,满则写入 SQLite;按节拍统一上传) */
|
|
/** 待落库采样点(内存缓冲,满则写入 SQLite;按节拍统一上传) */
|
|
|
private final List<Map<String, String>> sampleBuf = new ArrayList<Map<String, String>>();
|
|
private final List<Map<String, String>> sampleBuf = new ArrayList<Map<String, String>>();
|
|
@@ -148,7 +154,7 @@ public class PressPanel extends JPanel {
|
|
|
txtBatch = roField();
|
|
txtBatch = roField();
|
|
|
txtProduced = roField();
|
|
txtProduced = roField();
|
|
|
batchGrid.add(UiTheme.paramTile("批次码", txtBatch, UiTheme.STRIPE_SIDE));
|
|
batchGrid.add(UiTheme.paramTile("批次码", txtBatch, UiTheme.STRIPE_SIDE));
|
|
|
- batchGrid.add(UiTheme.paramTile("本机已产", txtProduced, UiTheme.STRIPE_SIDE));
|
|
|
|
|
|
|
+ batchGrid.add(UiTheme.paramTile("本批冲次", txtProduced, UiTheme.STRIPE_SIDE));
|
|
|
UiTheme.markTileValueBase(txtProduced, UiTheme.FONT_SN.getSize2D());
|
|
UiTheme.markTileValueBase(txtProduced, UiTheme.FONT_SN.getSize2D());
|
|
|
batchCard.add(batchGrid, BorderLayout.CENTER);
|
|
batchCard.add(batchGrid, BorderLayout.CENTER);
|
|
|
|
|
|
|
@@ -171,7 +177,8 @@ public class PressPanel extends JPanel {
|
|
|
txtAir = showAirCushion ? roField() : null;
|
|
txtAir = showAirCushion ? roField() : null;
|
|
|
txtEjector = showEjectorStroke ? roField() : null;
|
|
txtEjector = showEjectorStroke ? roField() : null;
|
|
|
txtEnergy = roField();
|
|
txtEnergy = roField();
|
|
|
- grid.add(UiTheme.paramTile("冲次数量", txtStroke, UiTheme.STRIPE_SIDE));
|
|
|
|
|
|
|
+ // PLC 累计冲次(示值);本批数量见上方「本机已产」
|
|
|
|
|
+ grid.add(UiTheme.paramTile("PLC累计冲次", txtStroke, UiTheme.STRIPE_SIDE));
|
|
|
grid.add(UiTheme.paramTile("生产高度", txtDieHeight, UiTheme.STRIPE_SIDE));
|
|
grid.add(UiTheme.paramTile("生产高度", txtDieHeight, UiTheme.STRIPE_SIDE));
|
|
|
grid.add(UiTheme.paramTile("顶缸压力", txtCylinder, UiTheme.STRIPE_SIDE));
|
|
grid.add(UiTheme.paramTile("顶缸压力", txtCylinder, UiTheme.STRIPE_SIDE));
|
|
|
grid.add(UiTheme.paramTile("生产吨位", txtTonnage, UiTheme.STRIPE_SIDE));
|
|
grid.add(UiTheme.paramTile("生产吨位", txtTonnage, UiTheme.STRIPE_SIDE));
|
|
@@ -250,9 +257,10 @@ public class PressPanel extends JPanel {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 批次变化:空→有=认领(保留冲次);有→有且不同=换批冲刷;其它重定起点
|
|
|
|
|
|
|
+ // 批次变化:已有本批进度的空→有=认领保留;其余(含开会话跟随)重定冲次起点
|
|
|
if (!batch.equalsIgnoreCase(boundBatchCode)) {
|
|
if (!batch.equalsIgnoreCase(boundBatchCode)) {
|
|
|
- boolean claimOnly = boundBatchCode.isEmpty() && !batch.isEmpty();
|
|
|
|
|
|
|
+ boolean claimOnly = boundBatchCode.isEmpty() && !batch.isEmpty()
|
|
|
|
|
+ && (baseStrokeReady || producedQty > 0);
|
|
|
boolean realSwitch = !boundBatchCode.isEmpty() && !batch.isEmpty();
|
|
boolean realSwitch = !boundBatchCode.isEmpty() && !batch.isEmpty();
|
|
|
if (realSwitch) {
|
|
if (realSwitch) {
|
|
|
// 短等刷旧批,降低能耗汇总点因异步失败被丢的概率
|
|
// 短等刷旧批,降低能耗汇总点因异步失败被丢的概率
|
|
@@ -267,26 +275,21 @@ public class PressPanel extends JPanel {
|
|
|
producedQty = 0;
|
|
producedQty = 0;
|
|
|
baseStrokeCount = 0L;
|
|
baseStrokeCount = 0L;
|
|
|
lastStrokeCount = 0L;
|
|
lastStrokeCount = 0L;
|
|
|
|
|
+ baseStrokeReady = false;
|
|
|
resetEnergyAccum();
|
|
resetEnergyAccum();
|
|
|
- if (plc.isConnected() && snap != null && !nvl(snap.strokeCountText).isEmpty()) {
|
|
|
|
|
- baseStrokeCount = snap.strokeCount;
|
|
|
|
|
- lastStrokeCount = snap.strokeCount;
|
|
|
|
|
- log.info("压机[{}] 跟随开会话 batch={} baseStroke={}",
|
|
|
|
|
- Integer.valueOf(cfg.getPressNo()), batch, Long.valueOf(baseStrokeCount));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ armBaseStrokeFromSnap(snap);
|
|
|
}
|
|
}
|
|
|
- } else if (baseStrokeCount == 0L && lastStrokeCount == 0L
|
|
|
|
|
- && plc.isConnected() && snap != null && !nvl(snap.strokeCountText).isEmpty()) {
|
|
|
|
|
- // 开会话时 PLC 未连上,稍后补记起点
|
|
|
|
|
- baseStrokeCount = snap.strokeCount;
|
|
|
|
|
- lastStrokeCount = snap.strokeCount;
|
|
|
|
|
|
|
+ } else if (!baseStrokeReady) {
|
|
|
|
|
+ // 开会话时 PLC 未连上 / 未读到冲次,稍后补记起点
|
|
|
|
|
+ armBaseStrokeFromSnap(snap);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 本批运行中:按设备运行 BOOL 累计时间并估算能耗
|
|
// 本批运行中:按设备运行 BOOL 累计时间并估算能耗
|
|
|
updateEnergyByRunState(snap, true);
|
|
updateEnergyByRunState(snap, true);
|
|
|
refreshSnapshotUi(snap);
|
|
refreshSnapshotUi(snap);
|
|
|
|
|
|
|
|
- if (plc.isConnected() && snap != null && !nvl(snap.strokeCountText).isEmpty()) {
|
|
|
|
|
|
|
+ if (baseStrokeReady && plc.isConnected() && snap != null
|
|
|
|
|
+ && !nvl(snap.strokeCountText).isEmpty()) {
|
|
|
updateProducedAgainstStroke(snap.strokeCount);
|
|
updateProducedAgainstStroke(snap.strokeCount);
|
|
|
}
|
|
}
|
|
|
DcLineBatchContext.setPressProduced(cfg.getPressNo(), producedQty);
|
|
DcLineBatchContext.setPressProduced(cfg.getPressNo(), producedQty);
|
|
@@ -362,12 +365,33 @@ public class PressPanel extends JPanel {
|
|
|
baseStrokeCount = 0L;
|
|
baseStrokeCount = 0L;
|
|
|
lastStrokeCount = 0L;
|
|
lastStrokeCount = 0L;
|
|
|
producedQty = 0;
|
|
producedQty = 0;
|
|
|
|
|
+ baseStrokeReady = false;
|
|
|
boundBatchCode = "";
|
|
boundBatchCode = "";
|
|
|
clearSampleBuf();
|
|
clearSampleBuf();
|
|
|
resetEnergyAccum();
|
|
resetEnergyAccum();
|
|
|
DcLineBatchContext.setPressProduced(cfg.getPressNo(), 0);
|
|
DcLineBatchContext.setPressProduced(cfg.getPressNo(), 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 用当前快照标定本批冲次起点;成功后才累计「本批数量」。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return 是否已标定
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean armBaseStrokeFromSnap(DcPressSnapshot snap) {
|
|
|
|
|
+ if (baseStrokeReady) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!plc.isConnected() || snap == null || nvl(snap.strokeCountText).isEmpty()) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ baseStrokeCount = snap.strokeCount;
|
|
|
|
|
+ lastStrokeCount = snap.strokeCount;
|
|
|
|
|
+ baseStrokeReady = true;
|
|
|
|
|
+ log.info("压机[{}] 标定本批冲次起点 batch={} baseStroke={}",
|
|
|
|
|
+ Integer.valueOf(cfg.getPressNo()), boundBatchCode, Long.valueOf(baseStrokeCount));
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/** 清空内存采样缓冲 */
|
|
/** 清空内存采样缓冲 */
|
|
|
private void clearSampleBuf() {
|
|
private void clearSampleBuf() {
|
|
|
synchronized (sampleBuf) {
|
|
synchronized (sampleBuf) {
|
|
@@ -634,8 +658,11 @@ public class PressPanel extends JPanel {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 按冲次累计本批已产;冲次变小则保留已产并重定起点 */
|
|
|
|
|
|
|
+ /** 按冲次累计本批已产(冲次差);未标定起点不累计;冲次变小则保留已产并重定起点 */
|
|
|
private void updateProducedAgainstStroke(long strokeCount) {
|
|
private void updateProducedAgainstStroke(long strokeCount) {
|
|
|
|
|
+ if (!baseStrokeReady) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
if (strokeCount < lastStrokeCount) {
|
|
if (strokeCount < lastStrokeCount) {
|
|
|
int kept = producedQty;
|
|
int kept = producedQty;
|
|
|
baseStrokeCount = strokeCount - kept;
|
|
baseStrokeCount = strokeCount - kept;
|