|
|
@@ -26,9 +26,9 @@ import java.util.TimerTask;
|
|
|
* 点位 DB700X:0.0 请求上料 / 0.1 请求下料 / 0.2 运行中 / 0.3 设备状态 / 0.4 MES允许上料
|
|
|
* 0.5 MES允许下料 / 0.6 心跳 / 0.7 上料到设备;1.0、1.1、2、4 为预留,不读不写
|
|
|
*
|
|
|
- * 上料:请求上料时从 sourceSlot 取码(正面=本 PLC 扫码码,反面=反面待上料码),校验通过写 0.4
|
|
|
+ * 上料:OP130 从本 PLC 扫码槽取码,校验通过写 0.4;OP135 请求上料后直接写 0.4,扫码码由独立扫码握手回填
|
|
|
* 进设备:0.7 上升沿或 0.2 运行中,码从「上料」移到「加工」
|
|
|
- * 下料:请求下料时上传结果;OP130A-F 要等反面待上料码为空,上传成功后存码给反面,再写 0.5
|
|
|
+ * 下料:请求下料时上传结果,接口成功后才写 0.5;无码时直接写 0.5
|
|
|
*/
|
|
|
public class WorkJPanelCnc extends JPanel {
|
|
|
|
|
|
@@ -37,6 +37,9 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
public static final String PLC_92 = "192.168.90.92";
|
|
|
public static final String PLC_93 = "192.168.90.93";
|
|
|
|
|
|
+ // 旧的 130 -> 135 共享码流转入口保留但关闭,避免现场误用。
|
|
|
+ private static final boolean LEGACY_SHARED_FLOW_ENABLED = false;
|
|
|
+
|
|
|
private static final String[] CN_NO = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十"};
|
|
|
|
|
|
public String oprno; // OP130 / OP135
|
|
|
@@ -47,7 +50,7 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
public String deviceName;
|
|
|
|
|
|
public SnSlot sourceSlot; // 上料取码来源
|
|
|
- public SnSlot targetSlot; // 下料存码目标:OP130A-F=反面待上料码,反面为 null
|
|
|
+ public SnSlot targetSlot; // 旧共享流转目标,当前仅保留以隐藏旧实现
|
|
|
|
|
|
public S7PLC s7PLC;
|
|
|
|
|
|
@@ -61,7 +64,12 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
|
|
|
private boolean feedingReleased = true; // 请求上料复位过,才处理下一次上料
|
|
|
private boolean lastToDevice = false; // 上一轮 0.7,用于取上升沿
|
|
|
+ private volatile boolean atDevice = false;
|
|
|
+ private volatile boolean running = false;
|
|
|
private boolean plcHeart = false;
|
|
|
+ private boolean op135ScanOwnerRegistered = false;
|
|
|
+ private String completionSubmittedSn = "";
|
|
|
+ private DirectScanHandshake scanHandshake;
|
|
|
|
|
|
public JButton status_menu;
|
|
|
public JTextField productSnFeeding; // 上料码
|
|
|
@@ -116,7 +124,8 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
s7PLC.setReceiveTimeout(1000);
|
|
|
s7PLC.setConnectTimeout(1000);
|
|
|
|
|
|
- cacheName = "cache_" + oprno + pos;
|
|
|
+ // OP135 改用新缓存,旧 cache_OP135X 中的共享码不再恢复显示。
|
|
|
+ cacheName = front ? "cache_" + oprno + pos : "cache_" + oprno + pos + "_independent";
|
|
|
cacheData = JdbcUtils.getCache(cacheName);
|
|
|
if (cacheData == null) {
|
|
|
cacheData = new CacheData();
|
|
|
@@ -165,7 +174,7 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
productSnFeeding = createSnField(50);
|
|
|
resetFeedingBtn = createResetBtn(50, () -> {
|
|
|
String sn = productSnFeeding.getText().trim();
|
|
|
- if (confirm("确定刷新上料工件" + sn + "吗?\n刷新后该码不会退回待上料码")) {
|
|
|
+ if (confirm("确定刷新上料工件" + sn + "吗?")) {
|
|
|
resetFeeding();
|
|
|
}
|
|
|
});
|
|
|
@@ -174,8 +183,7 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
productSn = createSnField(100);
|
|
|
resetBtn = createResetBtn(100, () -> {
|
|
|
String sn = productSn.getText().trim();
|
|
|
- String tip = front ? "\n刷新后不上传该件结果,也不会存入反面待上料码" : "\n刷新后不上传该件结果";
|
|
|
- if (confirm("确定刷新加工工件" + sn + "吗?" + tip)) {
|
|
|
+ if (confirm("确定刷新加工工件" + sn + "吗?\n刷新后不上传该件结果")) {
|
|
|
resetBlanking("已手动清除加工工件");
|
|
|
}
|
|
|
});
|
|
|
@@ -335,6 +343,8 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
oprnoTimer.cancel();
|
|
|
}
|
|
|
oprnoTimer = new Timer();
|
|
|
+ // OP135 的上料请求可能在写入 0.4 后很快撤销,缩短采样周期以捕获短脉冲。
|
|
|
+ long pollInterval = front ? 3000L : 1000L;
|
|
|
oprnoTimer.schedule(new TimerTask() {
|
|
|
public void run() {
|
|
|
try {
|
|
|
@@ -345,7 +355,7 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
log.error("<{}{}>轮询异常", oprno, pos, e);
|
|
|
}
|
|
|
}
|
|
|
- }, 100, 3000);
|
|
|
+ }, 100, pollInterval);
|
|
|
}
|
|
|
|
|
|
private void cycle() {
|
|
|
@@ -357,6 +367,8 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
boolean retToDevice = readBoolean(plcDb + ".0.7");
|
|
|
boolean toDeviceRise = retToDevice && !lastToDevice;
|
|
|
lastToDevice = retToDevice;
|
|
|
+ running = retRunning;
|
|
|
+ atDevice = retToDevice;
|
|
|
|
|
|
feedinglabel.setIcon(light(retFeeding));
|
|
|
feedingmeslabel.setIcon(light(retAllowFeeding));
|
|
|
@@ -365,6 +377,19 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
blankingmeslabel.setIcon(light(retAllowBlanking));
|
|
|
feedingtodevicelabel.setIcon(light(retToDevice));
|
|
|
|
|
|
+ if (!front) {
|
|
|
+ cycleOp135(retFeeding, retBlanking, retRunning, retAllowFeeding,
|
|
|
+ retAllowBlanking, toDeviceRise);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ cycleOp130(retFeeding, retBlanking, retRunning, retAllowFeeding,
|
|
|
+ retAllowBlanking, toDeviceRise);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void cycleOp130(boolean retFeeding, boolean retBlanking, boolean retRunning,
|
|
|
+ boolean retAllowFeeding, boolean retAllowBlanking,
|
|
|
+ boolean toDeviceRise) {
|
|
|
// 请求上料撤销后复位 MES允许上料
|
|
|
if (!retFeeding && retAllowFeeding) {
|
|
|
writeAllowFeeding(false);
|
|
|
@@ -391,23 +416,70 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
setMenuStatus("工件已上料到设备", 0);
|
|
|
}
|
|
|
|
|
|
- // ---------- 下料 ----------
|
|
|
- // 加工码为空时直接放行下料(无码件或已上传完成)
|
|
|
- if (retBlanking && productSn.getText().isEmpty() && !retAllowBlanking) {
|
|
|
- writeAllowBlanking(true);
|
|
|
- }
|
|
|
- if (tjFlag == 0 && !retBlanking && retAllowBlanking) {
|
|
|
+ if (tjFlag == 1 && retRunning) {
|
|
|
+ tjFlag = 2;
|
|
|
+ writeAllowFeeding(false);
|
|
|
writeAllowBlanking(false);
|
|
|
+ setMenuStatus("工件加工中", 0);
|
|
|
}
|
|
|
|
|
|
+ if (LEGACY_SHARED_FLOW_ENABLED && tjFlag == 2 && retBlanking) {
|
|
|
+ finishWorkLegacy();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ handleBlankingRequest(retBlanking, retAllowBlanking);
|
|
|
+ }
|
|
|
+
|
|
|
+ private synchronized void cycleOp135(boolean retFeeding, boolean retBlanking,
|
|
|
+ boolean retRunning, boolean retAllowFeeding,
|
|
|
+ boolean retAllowBlanking, boolean toDeviceRise) {
|
|
|
+ // OP135 上料请求不等待扫码,直接允许。
|
|
|
+ if (retFeeding) {
|
|
|
+ if (!retAllowFeeding) {
|
|
|
+ writeAllowFeeding(true);
|
|
|
+ }
|
|
|
+ if (!op135ScanOwnerRegistered) {
|
|
|
+ if (scanHandshake == null) {
|
|
|
+ log.error("<{}{}>独立扫码未初始化,无法登记扫码归属", oprno, pos);
|
|
|
+ setMenuStatus("独立扫码未初始化", -1);
|
|
|
+ } else {
|
|
|
+ op135ScanOwnerRegistered = scanHandshake.registerScanOwner(this);
|
|
|
+ if (op135ScanOwnerRegistered) {
|
|
|
+ setMenuStatus("收到上料请求,等待独立扫码", 0);
|
|
|
+ } else {
|
|
|
+ setMenuStatus("已有其他OP135工位等待扫码,本工位暂不绑定", -1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (retAllowFeeding) {
|
|
|
+ writeAllowFeeding(false);
|
|
|
+ }
|
|
|
+ // 0.0 可能先于 64 的扫码请求撤销,归属必须锁存到扫码流程结束。
|
|
|
+ op135ScanOwnerRegistered = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 扫码可能晚于设备进料,收到码后立即移动到加工码,避免丢失归属。
|
|
|
+ if (tjFeedingFlag == 1 && (toDeviceRise || retRunning || atDevice)) {
|
|
|
+ tjFlag = Math.max(tjFlag, 1);
|
|
|
+ tjFeedingFlag = 0;
|
|
|
+ productSn.setText(productSnFeeding.getText());
|
|
|
+ productSnFeeding.setText("");
|
|
|
+ setMenuStatus("工件已上料到设备", 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tjFlag == 0 && retRunning) {
|
|
|
+ tjFlag = 1;
|
|
|
+ }
|
|
|
if (tjFlag == 1 && retRunning) {
|
|
|
tjFlag = 2;
|
|
|
writeAllowFeeding(false);
|
|
|
writeAllowBlanking(false);
|
|
|
setMenuStatus("工件加工中", 0);
|
|
|
- } else if (tjFlag == 2 && retBlanking) {
|
|
|
- finishWork();
|
|
|
}
|
|
|
+
|
|
|
+ handleBlankingRequest(retBlanking, retAllowBlanking);
|
|
|
}
|
|
|
|
|
|
// 取码并校验:通过后清掉码槽里的码,写 MES允许上料
|
|
|
@@ -423,7 +495,7 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
try {
|
|
|
String sn = sourceSlot.getSn();
|
|
|
if (sn.isEmpty()) {
|
|
|
- setMenuStatus(front ? "暂无扫码结果,等待扫码" : "反面待上料码为空,等待正面下料", -1);
|
|
|
+ setMenuStatus("暂无扫码结果,等待扫码", -1);
|
|
|
return;
|
|
|
}
|
|
|
productSnFeeding.setText(sn);
|
|
|
@@ -443,8 +515,49 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 请求下料:上传结果,有存码目标时成功后存码
|
|
|
- private void finishWork() {
|
|
|
+ /**
|
|
|
+ * 下料必须等待 pcresult 成功后再允许。失败时保留加工码,下一轮自动重试。
|
|
|
+ */
|
|
|
+ private void handleBlankingRequest(boolean retBlanking, boolean retAllowBlanking) {
|
|
|
+ String sn = productSn.getText().trim();
|
|
|
+ if (!retBlanking) {
|
|
|
+ if (retAllowBlanking) {
|
|
|
+ writeAllowBlanking(false);
|
|
|
+ }
|
|
|
+ completionSubmittedSn = "";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sn.isEmpty()) {
|
|
|
+ completionSubmittedSn = "";
|
|
|
+ if (!retAllowBlanking) {
|
|
|
+ writeAllowBlanking(true);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 防止上一次遗留的允许信号绕过本次工件完成接口。
|
|
|
+ if (retAllowBlanking && !sn.equals(completionSubmittedSn)) {
|
|
|
+ if (!writeAllowBlanking(false)) {
|
|
|
+ setMenuStatus("清除旧下料允许失败,暂不上传", -1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!sn.equals(completionSubmittedSn)) {
|
|
|
+ if (!upload(sn)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ completionSubmittedSn = sn;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (writeAllowBlanking(true)) {
|
|
|
+ resetBlanking("工件结果已提交,允许下料");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 旧 130 -> 135 共享码流转实现,默认关闭但保留以便回退。
|
|
|
+ private void finishWorkLegacy() {
|
|
|
String sn = productSn.getText().trim();
|
|
|
if (targetSlot == null) {
|
|
|
if (upload(sn)) {
|
|
|
@@ -454,7 +567,7 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
return;
|
|
|
}
|
|
|
if (!targetSlot.tryLock()) {
|
|
|
- return; // 反面正在取码或其他正面机正在存码,下一轮再试
|
|
|
+ return;
|
|
|
}
|
|
|
try {
|
|
|
if (!targetSlot.isEmpty()) {
|
|
|
@@ -471,14 +584,15 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 上传加工结果,失败停在 tjFlag=3 等人工刷新(与原逻辑一致)
|
|
|
+ // 上传加工结果,失败保留加工码并在下一轮重试。
|
|
|
private boolean upload(String sn) {
|
|
|
tjFlag = 3;
|
|
|
- tjStatus = 1;
|
|
|
+ tjStatus = 0;
|
|
|
setMenuStatus("工件加工结束,结果上传中", 0);
|
|
|
log.info("<{}{}>上传加工结果 sn={}", oprno, pos, sn);
|
|
|
JSONObject retObj = DataUtil.sendQuality(sn, oprno + pos, "OK", MesClient.user_menu.getText());
|
|
|
if (isOk(retObj)) {
|
|
|
+ tjStatus = 1;
|
|
|
return true;
|
|
|
}
|
|
|
setMenuStatus(failMsg(retObj), -1);
|
|
|
@@ -488,17 +602,54 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
public void resetBlanking(String msg) {
|
|
|
tjFlag = 0;
|
|
|
tjStatus = 0;
|
|
|
+ completionSubmittedSn = "";
|
|
|
productSn.setText("");
|
|
|
setMenuStatus(msg, 0);
|
|
|
}
|
|
|
|
|
|
public void resetFeeding() {
|
|
|
tjFeedingFlag = 0;
|
|
|
+ op135ScanOwnerRegistered = false;
|
|
|
productSnFeeding.setText("");
|
|
|
writeAllowFeeding(false);
|
|
|
setMenuStatus("等待请求上料", 0);
|
|
|
}
|
|
|
|
|
|
+ /** 绑定 OP135 独立扫码握手,用于登记扫码归属。 */
|
|
|
+ public void setScanHandshake(DirectScanHandshake scanHandshake) {
|
|
|
+ this.scanHandshake = scanHandshake;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 接收独立扫码结果。扫码、MES 校验和 PLC 写码均已在握手线程完成。
|
|
|
+ */
|
|
|
+ public synchronized boolean acceptScannedSn(String sn) {
|
|
|
+ String value = nvl(sn).trim();
|
|
|
+ if (value.isEmpty()) {
|
|
|
+ setMenuStatus("独立扫码结果为空,未接收", -1);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!productSn.getText().trim().isEmpty() && !productSn.getText().trim().equals(value)) {
|
|
|
+ setMenuStatus("当前加工码" + productSn.getText().trim() + "尚未下料,不能接收新码", -1);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ lastSn = value;
|
|
|
+ if (running || atDevice || tjFlag >= 1) {
|
|
|
+ productSn.setText(value);
|
|
|
+ productSnFeeding.setText("");
|
|
|
+ tjFeedingFlag = 0;
|
|
|
+ tjFlag = Math.max(tjFlag, 1);
|
|
|
+ setMenuStatus("独立扫码码已写入加工:" + value, 0);
|
|
|
+ } else {
|
|
|
+ productSnFeeding.setText(value);
|
|
|
+ tjFeedingFlag = 1;
|
|
|
+ setMenuStatus("独立扫码码已写入上料:" + value, 0);
|
|
|
+ }
|
|
|
+ log.info("<{}{}>接收独立扫码码 {}", oprno, pos, value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
private static boolean isOk(JSONObject retObj) {
|
|
|
return retObj != null && "true".equalsIgnoreCase(String.valueOf(retObj.get("result")));
|
|
|
}
|
|
|
@@ -521,12 +672,12 @@ public class WorkJPanelCnc extends JPanel {
|
|
|
|
|
|
// 与设备交互 -----------------------------------------------------------------------------------------
|
|
|
|
|
|
- public void writeAllowFeeding(boolean b) {
|
|
|
- writeBoolean(plcDb + ".0.4", b);
|
|
|
+ public boolean writeAllowFeeding(boolean b) {
|
|
|
+ return writeBoolean(plcDb + ".0.4", b);
|
|
|
}
|
|
|
|
|
|
- public void writeAllowBlanking(boolean b) {
|
|
|
- writeBoolean(plcDb + ".0.5", b);
|
|
|
+ public boolean writeAllowBlanking(boolean b) {
|
|
|
+ return writeBoolean(plcDb + ".0.5", b);
|
|
|
}
|
|
|
|
|
|
public boolean readBoolean(String addr) {
|