|
|
@@ -31,7 +31,6 @@ public class DirectScanHandshake {
|
|
|
private static final int SN_MAX_LENGTH = 24;
|
|
|
private static final long RETRY_SCAN_MS = 10000;
|
|
|
private static final long CLEAN_DELAY_MS = 33000;
|
|
|
- private static final long OWNER_TIMEOUT_MS = 60000;
|
|
|
private static final String OPRNO = "OP135";
|
|
|
|
|
|
private enum State {
|
|
|
@@ -59,7 +58,6 @@ public class DirectScanHandshake {
|
|
|
private volatile String lastScannedSn = "";
|
|
|
private volatile String lastPlcWrittenSn = "";
|
|
|
private volatile String lastDeliveredCnc = "";
|
|
|
- private volatile long ownerRegisteredAt = 0;
|
|
|
|
|
|
public DirectScanHandshake(String plcIp, TCPClient scanner) {
|
|
|
this.plc = new S7PLC(EPlcType.S1500, plcIp);
|
|
|
@@ -101,7 +99,6 @@ public class DirectScanHandshake {
|
|
|
}
|
|
|
WorkJPanelCnc current = pendingCnc.get();
|
|
|
if (current == panel) {
|
|
|
- ownerRegisteredAt = System.currentTimeMillis();
|
|
|
return true;
|
|
|
}
|
|
|
if (current != null) {
|
|
|
@@ -111,21 +108,22 @@ public class DirectScanHandshake {
|
|
|
}
|
|
|
if (pendingCnc.compareAndSet(current, panel)) {
|
|
|
cncDelivered = false;
|
|
|
- ownerRegisteredAt = System.currentTimeMillis();
|
|
|
log.info("OP135 登记扫码归属工位:{}{}", panel.oprno, panel.pos);
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- /** 上料请求撤销且当前没有进行中的扫码时,释放尚未使用的归属。 */
|
|
|
- public void releaseScanOwner(WorkJPanelCnc panel) {
|
|
|
- if (state == State.IDLE || state == State.WAIT_REQUEST_RISE) {
|
|
|
- if (pendingCnc.compareAndSet(panel, null)) {
|
|
|
- ownerRegisteredAt = 0;
|
|
|
- log.info("OP135 释放扫码归属工位:{}{}", panel.oprno, panel.pos);
|
|
|
- }
|
|
|
+ /** 人工释放当前扫码归属,返回被释放的工位号。 */
|
|
|
+ public String releasePendingOwnerManually() {
|
|
|
+ WorkJPanelCnc owner = pendingCnc.getAndSet(null);
|
|
|
+ if (owner == null) {
|
|
|
+ return "";
|
|
|
}
|
|
|
+ String station = owner.oprno + owner.pos;
|
|
|
+ showStatus("已手动释放扫码归属:" + station, 0);
|
|
|
+ log.info("OP135 已手动释放扫码归属工位:{}", station);
|
|
|
+ return station;
|
|
|
}
|
|
|
|
|
|
/** 只读监控数据,不参与握手判断。 */
|
|
|
@@ -217,7 +215,6 @@ public class DirectScanHandshake {
|
|
|
}
|
|
|
|
|
|
if (!request) {
|
|
|
- expirePendingOwnerIfNeeded();
|
|
|
handleRequestOff(previous);
|
|
|
return;
|
|
|
}
|
|
|
@@ -250,10 +247,6 @@ public class DirectScanHandshake {
|
|
|
if (previous && state != State.WAIT_CLEAR && state != State.WAIT_REQUEST_RISE) {
|
|
|
validatedSn = "";
|
|
|
nextScanAt = 0;
|
|
|
- if (!cncDelivered && pendingCnc.getAndSet(null) != null) {
|
|
|
- ownerRegisteredAt = 0;
|
|
|
- log.info("OP135 扫码请求结束,释放尚未交付的CNC归属");
|
|
|
- }
|
|
|
if (!plcOwnedSn.isEmpty()) {
|
|
|
scheduleDelayedCleanup();
|
|
|
} else {
|
|
|
@@ -270,23 +263,6 @@ public class DirectScanHandshake {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void expirePendingOwnerIfNeeded() {
|
|
|
- WorkJPanelCnc owner = pendingCnc.get();
|
|
|
- if (owner == null || ownerRegisteredAt == 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- boolean waitingForFirstScanRequest = state == State.IDLE
|
|
|
- || state == State.WAIT_REQUEST_RISE;
|
|
|
- if (waitingForFirstScanRequest
|
|
|
- && System.currentTimeMillis() - ownerRegisteredAt >= OWNER_TIMEOUT_MS) {
|
|
|
- if (pendingCnc.compareAndSet(owner, null)) {
|
|
|
- ownerRegisteredAt = 0;
|
|
|
- showStatus("OP135 等待扫码请求超时,已释放CNC归属", -1);
|
|
|
- log.warn("OP135 等待扫码请求超时,释放归属 {}{}", owner.oprno, owner.pos);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void scanAndValidate() {
|
|
|
showStatus("OP135 扫码中...", 0);
|
|
|
String sn = scanQrCode();
|
|
|
@@ -388,7 +364,6 @@ public class DirectScanHandshake {
|
|
|
}
|
|
|
cncDelivered = true;
|
|
|
pendingCnc.compareAndSet(owner, null);
|
|
|
- ownerRegisteredAt = 0;
|
|
|
lastDeliveredCnc = owner.oprno + owner.pos;
|
|
|
log.info("OP135 工件码 {} 已交付 {}{}", sn, owner.oprno, owner.pos);
|
|
|
}
|
|
|
@@ -432,7 +407,6 @@ public class DirectScanHandshake {
|
|
|
validatedSn = "";
|
|
|
cncDelivered = false;
|
|
|
pendingCnc.set(null);
|
|
|
- ownerRegisteredAt = 0;
|
|
|
clearAt = 0;
|
|
|
state = State.WAIT_REQUEST_RISE;
|
|
|
showStatus("OP135 33 秒清理完成,等待下一次请求", 0);
|