|
|
@@ -93,13 +93,14 @@ public class WorkJPanelOP10 extends JPanel {
|
|
|
public CacheData cacheData = null;
|
|
|
public String cacheName = "";
|
|
|
|
|
|
- // CZ060 产品PN号
|
|
|
- public static final String[] PN_LIST = {"195", "196", "198"};
|
|
|
- public JComboBox<String> pnCombo;
|
|
|
+ // 当前加工产品PN号,由服务端按生产计划下发
|
|
|
+ public String currentPn = "";
|
|
|
+ public JLabel pnLabel;
|
|
|
|
|
|
- public String getPn(){
|
|
|
- return pnCombo == null ? PN_LIST[0] : String.valueOf(pnCombo.getSelectedItem());
|
|
|
- }
|
|
|
+ // 计划已完成/无计划时停止自动取码,避免每秒重复请求
|
|
|
+ private boolean planStop = false;
|
|
|
+ // 取码失败后的下次重试时间
|
|
|
+ private long nextRetryTime = 0;
|
|
|
|
|
|
// 说明OP10A=西侧 OP10B=东侧
|
|
|
public WorkJPanelOP10(String position){
|
|
|
@@ -259,25 +260,17 @@ public class WorkJPanelOP10 extends JPanel {
|
|
|
});
|
|
|
this.add(blankingmeslabelOP10);
|
|
|
|
|
|
- // 产品PN号选择:决定镭雕码前缀 CZ060+PN,选择结果存缓存
|
|
|
- JLabel pnLabel = new JLabel("产品PN:");
|
|
|
+ // 产品PN号:由服务端按生产计划下发,界面只读显示
|
|
|
+ JLabel pnTitle = new JLabel("产品PN:");
|
|
|
+ pnTitle.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ pnTitle.setBounds(0, 272, 90, 36);
|
|
|
+ this.add(pnTitle);
|
|
|
+
|
|
|
+ pnLabel = new JLabel("-");
|
|
|
pnLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- pnLabel.setBounds(0, 272, 90, 36);
|
|
|
+ pnLabel.setBounds(90, 272, 120, 36);
|
|
|
this.add(pnLabel);
|
|
|
|
|
|
- pnCombo = new JComboBox<>(PN_LIST);
|
|
|
- pnCombo.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- pnCombo.setBounds(90, 272, 120, 36);
|
|
|
- pnCombo.getAccessibleContext().setAccessibleName("产品PN号");
|
|
|
- String cachePn = cacheData.getPn();
|
|
|
- pnCombo.setSelectedItem(cachePn == null || cachePn.isEmpty() ? PN_LIST[0] : cachePn);
|
|
|
- pnCombo.addActionListener(e -> {
|
|
|
- cacheData.setPn(getPn());
|
|
|
- JdbcUtils.setCache(cacheName, JSON.toJSONString(cacheData));
|
|
|
- log.info("<{}{}> 切换产品PN: {}", oprno, pos, getPn());
|
|
|
- });
|
|
|
- this.add(pnCombo);
|
|
|
-
|
|
|
startOprnoTimer();
|
|
|
startLightTimer();
|
|
|
heartData();
|
|
|
@@ -377,7 +370,8 @@ public class WorkJPanelOP10 extends JPanel {
|
|
|
}
|
|
|
|
|
|
if(tjFlag == 0){
|
|
|
- if(retFeeding){
|
|
|
+ // 计划已完成/无计划时不再自动取码;失败后按间隔重试
|
|
|
+ if(retFeeding && !planStop && System.currentTimeMillis() >= nextRetryTime){
|
|
|
barCode();
|
|
|
}
|
|
|
} else if (tjFlag == 1){
|
|
|
@@ -475,14 +469,15 @@ public class WorkJPanelOP10 extends JPanel {
|
|
|
public void barCode(){
|
|
|
String sn = readQrcode();
|
|
|
if(sn.isEmpty()){
|
|
|
- this.setMenuStatus("扫码结果为空", -1);
|
|
|
- }else{
|
|
|
- log.info("<{}{}> barCode() 获取到镭雕码: {}, tjFlag=0->1", oprno, pos, sn);
|
|
|
- productSn.setText(sn);
|
|
|
- lastSn = sn;
|
|
|
- tjFlag = 1;
|
|
|
- this.setMenuStatus("镭雕码获取成功,等待镭雕", 0);
|
|
|
+ // 失败原因已在 readQrcode 中显示,这里不再覆盖;10 秒内不重复请求
|
|
|
+ nextRetryTime = System.currentTimeMillis() + 10000;
|
|
|
+ return;
|
|
|
}
|
|
|
+ log.info("<{}{}> barCode() 获取到镭雕码: {}, tjFlag=0->1", oprno, pos, sn);
|
|
|
+ productSn.setText(sn);
|
|
|
+ lastSn = sn;
|
|
|
+ tjFlag = 1;
|
|
|
+ this.setMenuStatus("镭雕码获取成功,等待镭雕", 0);
|
|
|
}
|
|
|
// 与设备交互-----------------------------------------------------------------------------------------
|
|
|
// 请求扫码
|
|
|
@@ -664,26 +659,44 @@ public class WorkJPanelOP10 extends JPanel {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // 读取PLC二维码
|
|
|
+ // 读取PLC二维码:产品号由服务端按生产计划下发
|
|
|
public String readQrcode(){
|
|
|
String sn = "";
|
|
|
try {
|
|
|
- // 左物料不再读取,wsn1 传空;pn 取界面选择的产品PN号
|
|
|
- JSONObject retObj = DataUtil.createOrder(oprno+pos,"",getPn(),MesClient.user_menu.getText());
|
|
|
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ // 左物料不再读取,wsn1 传空;pn 不传,由服务端按计划决定
|
|
|
+ JSONObject retObj = DataUtil.createOrder(oprno+pos,"",MesClient.user_menu.getText());
|
|
|
+ if(retObj != null && retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
sn = retObj.getString("data");
|
|
|
+ if(sn == null || sn.isEmpty()){
|
|
|
+ this.setMenuStatus("扫码结果为空",-1);
|
|
|
+ writeAllowFeeding(false);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ // 显示服务端下发的产品号
|
|
|
+ String pn = retObj.getString("pn");
|
|
|
+ if(pn != null && !pn.isEmpty()){
|
|
|
+ currentPn = pn;
|
|
|
+ pnLabel.setText(pn);
|
|
|
+ }
|
|
|
+ planStop = false;
|
|
|
+ nextRetryTime = 0;
|
|
|
this.setMenuStatus("允许镭雕机加工",0);
|
|
|
writeSn(sn);
|
|
|
writeAllowFeeding(true);
|
|
|
}else{
|
|
|
writeAllowFeeding(false);
|
|
|
- if(retObj.get("result")==null){
|
|
|
+ sn = "";
|
|
|
+ if(retObj == null || retObj.get("result")==null){
|
|
|
this.setMenuStatus("请求失败,请重试",-1);
|
|
|
- }else{
|
|
|
- if(retObj.get("result").toString().equalsIgnoreCase("false")){
|
|
|
- this.setMenuStatus(retObj.getString("message"),-1);
|
|
|
- }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ String code = retObj.getString("code");
|
|
|
+ // 计划已完成或无可用计划:停止自动取码,等待人工刷新/换班
|
|
|
+ if("PLAN_FINISHED".equals(code) || "NO_PLAN".equals(code)){
|
|
|
+ planStop = true;
|
|
|
+ log.info("<{}{}> 停止自动取码,code={}", oprno, pos, code);
|
|
|
}
|
|
|
+ this.setMenuStatus(retObj.getString("message"),-1);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("<"+this.oprno+this.pos+">获取工件码-->失败", e);
|
|
|
@@ -695,6 +708,8 @@ public class WorkJPanelOP10 extends JPanel {
|
|
|
productSn.setText("");
|
|
|
tjFlag = 0;
|
|
|
tjStatus = 0;
|
|
|
+ planStop = false;
|
|
|
+ nextRetryTime = 0;
|
|
|
writeAllowFeeding(false);
|
|
|
setMenuStatus("等待请求镭雕码",0);
|
|
|
}
|