|
|
@@ -34,8 +34,10 @@ public class WorkJPanelScan extends JPanel {
|
|
|
|
|
|
public String lineSn = "CZ060";
|
|
|
|
|
|
- /** 工件码格式例如 CZ0600016A090001,共 16 位 */
|
|
|
- public static final int SN_LEN = 16;
|
|
|
+ /** 兼容现场短码、旧码和 24 位 EVE 长码 */
|
|
|
+ public static final int SN_LEN_SHORT = 16;
|
|
|
+ public static final int SN_LEN_LEGACY = 19;
|
|
|
+ public static final int SN_LEN_EVE = 24;
|
|
|
|
|
|
public JLabel feedinglabel;
|
|
|
|
|
|
@@ -97,6 +99,9 @@ public class WorkJPanelScan extends JPanel {
|
|
|
|
|
|
public CacheData cacheData = null;
|
|
|
public String cacheName = "";
|
|
|
+ private Boolean lastScanRequest = null;
|
|
|
+ private boolean scanCompletedForRequest = false;
|
|
|
+ private String manualPendingSn = "";
|
|
|
|
|
|
public WorkJPanelScan(String position){
|
|
|
this.setLayout(null);
|
|
|
@@ -256,8 +261,8 @@ public class WorkJPanelScan extends JPanel {
|
|
|
// String sn = cacheData.getSn();
|
|
|
// productSn.setText(sn);
|
|
|
|
|
|
- String feedingSn = cacheData.getFeedingSn();
|
|
|
- productSnFeeding.setText(feedingSn);
|
|
|
+ // 缓存的码只用于历史追踪,不能恢复为当前扫码结果,否则会被误认为本轮已完成
|
|
|
+ productSnFeeding.setText("");
|
|
|
|
|
|
tjFlag = cacheData.getTjFlag();
|
|
|
lastSn = cacheData.getLastSn();
|
|
|
@@ -306,15 +311,19 @@ public class WorkJPanelScan extends JPanel {
|
|
|
feedingmeslabel.setIcon(retFeedingAllow?imageGreen:imageGray);
|
|
|
|
|
|
if(retFeeding){
|
|
|
- String current = productSnFeeding.getText() == null ? "" : productSnFeeding.getText().trim();
|
|
|
- if(isValidSn(current)){
|
|
|
+ if(!Boolean.TRUE.equals(lastScanRequest)){
|
|
|
+ startScanRequest();
|
|
|
+ }
|
|
|
+ if(scanCompletedForRequest){
|
|
|
writeScanFinish(true);
|
|
|
}else{
|
|
|
barCode2();
|
|
|
}
|
|
|
}else{
|
|
|
+ scanCompletedForRequest = false;
|
|
|
writeScanFinish(false);
|
|
|
}
|
|
|
+ lastScanRequest = retFeeding;
|
|
|
}
|
|
|
}catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
@@ -323,6 +332,20 @@ public class WorkJPanelScan extends JPanel {
|
|
|
}, 100,1500);
|
|
|
}
|
|
|
|
|
|
+ private void startScanRequest(){
|
|
|
+ scanCompletedForRequest = false;
|
|
|
+ productSnFeeding.setText("");
|
|
|
+ MesClient.clearScanCode(isScan);
|
|
|
+
|
|
|
+ String pendingSn = manualPendingSn == null ? "" : manualPendingSn.trim();
|
|
|
+ manualPendingSn = "";
|
|
|
+ if(isValidSn(pendingSn)){
|
|
|
+ publishScanResult(pendingSn, "手动录入");
|
|
|
+ }else{
|
|
|
+ setMenuStatus("正在扫码", 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void barCode2(){
|
|
|
String sn = readQrcode();
|
|
|
if(sn == null){
|
|
|
@@ -333,14 +356,17 @@ public class WorkJPanelScan extends JPanel {
|
|
|
setMenuStatus("扫码结果为空或格式不符", -1);
|
|
|
return;
|
|
|
}
|
|
|
- if(pos.equals("A")){
|
|
|
- MesClient.scanSnA = sn;
|
|
|
- }else{
|
|
|
- MesClient.scanSnB = sn;
|
|
|
- }
|
|
|
- setMenuStatus("扫码成功", 0);
|
|
|
+ publishScanResult(sn, "扫码");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void publishScanResult(String sn, String source){
|
|
|
+ MesClient.publishScanCode(isScan, sn);
|
|
|
productSnFeeding.setText(sn);
|
|
|
- writeScanFinish(true);
|
|
|
+ scanCompletedForRequest = true;
|
|
|
+ setMenuStatus(source + "成功", 0);
|
|
|
+ if(readScanFeeding()){
|
|
|
+ writeScanFinish(true);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/** 手动输入工件码:回车确认,写入全局码并回写 PLC 扫码完成 */
|
|
|
@@ -351,27 +377,34 @@ public class WorkJPanelScan extends JPanel {
|
|
|
return;
|
|
|
}
|
|
|
if(!isValidSn(sn)){
|
|
|
- setMenuStatus("工件码应为16位(如 CZ0600016A090001),当前" + sn.length() + "位", -1);
|
|
|
+ setMenuStatus("工件码应为16、19或24位,当前" + sn.length() + "位", -1);
|
|
|
return;
|
|
|
}
|
|
|
- if(pos.equals("A")){
|
|
|
- MesClient.scanSnA = sn;
|
|
|
+ manualPendingSn = sn;
|
|
|
+ productSnFeeding.setText(sn);
|
|
|
+ if(Boolean.TRUE.equals(lastScanRequest)){
|
|
|
+ publishScanResult(sn, "手动录入");
|
|
|
+ manualPendingSn = "";
|
|
|
}else{
|
|
|
- MesClient.scanSnB = sn;
|
|
|
+ setMenuStatus("手动录入成功,等待请求扫码", 0);
|
|
|
}
|
|
|
- productSnFeeding.setText(sn);
|
|
|
- writeScanFinish(true);
|
|
|
- setMenuStatus("手动录入成功", 0);
|
|
|
log.info("[{}]手动录入工件码: {}", oprno + pos, sn);
|
|
|
}
|
|
|
|
|
|
public static boolean isValidSn(String sn){
|
|
|
- return sn != null && sn.length() == SN_LEN;
|
|
|
+ if(sn == null){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ int length = sn.trim().length();
|
|
|
+ return length == SN_LEN_SHORT || length == SN_LEN_LEGACY || length == SN_LEN_EVE;
|
|
|
}
|
|
|
|
|
|
public void resetFeeding() {
|
|
|
productSnFeeding.setText("");
|
|
|
tjFeedingFlag = 0;
|
|
|
+ manualPendingSn = "";
|
|
|
+ scanCompletedForRequest = false;
|
|
|
+ MesClient.clearScanCode(isScan);
|
|
|
setMenuStatus("等待请求扫码",0);
|
|
|
resetFeedingBtn.setEnabled(true);
|
|
|
// writeAllowFeeding(false);
|
|
|
@@ -383,6 +416,9 @@ public class WorkJPanelScan extends JPanel {
|
|
|
tjStatus = 0;
|
|
|
// productSnFeeding.setText("5001040043561100050");
|
|
|
productSnFeeding.setText("");
|
|
|
+ manualPendingSn = "";
|
|
|
+ scanCompletedForRequest = false;
|
|
|
+ MesClient.clearScanCode(isScan);
|
|
|
// setMenuStatus("等待请求扫码",0);
|
|
|
|
|
|
if(isLocal == 0){
|