WorkTimer2.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package com.mes.util;
  2. import com.mes.ui.MesClient;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. import java.awt.*;
  6. import java.util.Timer;
  7. import java.util.TimerTask;
  8. /**
  9. * 右工位 ateq 轮询(对齐 qm-new-2)
  10. */
  11. public class WorkTimer2 {
  12. private static final Logger log = LoggerFactory.getLogger(WorkTimer2.class);
  13. private static Timer workTimer = null;
  14. private WorkTimer2() {
  15. }
  16. public static void start() {
  17. if (workTimer != null) {
  18. workTimer.cancel();
  19. workTimer = null;
  20. }
  21. workTimer = new Timer();
  22. workTimer.schedule(new WorkTimerTask(), 1000, 2000);
  23. }
  24. public static void ensureStarted() {
  25. if (workTimer == null) {
  26. start();
  27. }
  28. }
  29. public static void stop() {
  30. if (workTimer != null) {
  31. workTimer.cancel();
  32. workTimer = null;
  33. }
  34. }
  35. private static class WorkTimerTask extends TimerTask {
  36. @Override
  37. public void run() {
  38. try {
  39. if (MesClient.work_status2 != 1) {
  40. return;
  41. }
  42. ATEQ2.RealtimeResult realtimeResult = ATEQ2.readRealtimeResult();
  43. log.info(realtimeResult.toString());
  44. boolean isEnd = false;
  45. if (realtimeResult.stepCode == 65535) {
  46. if (MesClient.mesStartFlag2 == 1) {
  47. isEnd = true;
  48. }
  49. } else {
  50. MesClient.mesStartFlag2 = 1;
  51. MesClient.setMenuStatus("右工位当前步骤:[" + realtimeResult.stepCode + "]" + realtimeResult.step, 0);
  52. }
  53. MesClient.param3.setText(isEnd ? "" : realtimeResult.pressureValue + " " + realtimeResult.pressureUnit);
  54. MesClient.param4.setText(isEnd ? "" : realtimeResult.leakValue + " ml/min");
  55. if (!isEnd) {
  56. return;
  57. }
  58. log.info("右工位检测结束...");
  59. // 对齐 qm:立即结束工作态,避免轮询重复判定覆盖结果
  60. MesClient.work_status2 = 0;
  61. MesClient.mesStartFlag2 = 0;
  62. double realtimeLeak = realtimeResult.leakValue;
  63. ATEQ2.LastResult lastResult = ATEQ2.readLastResult();
  64. log.info(lastResult.toString());
  65. MesClient.param3.setText(lastResult.pressureValue + lastResult.pressureUnit);
  66. double leakValue;
  67. if (MesClient.leakCheckRunningR) {
  68. leakValue = realtimeLeak;
  69. if (leakValue == 0 && lastResult.leakValue != 0) {
  70. leakValue = lastResult.leakValue;
  71. }
  72. MesClient.param4.setText(leakValue + " ml/min");
  73. log.info("标漏采用泄漏率判定值={}, 实时={}, 最终={}", leakValue, realtimeLeak, lastResult.leakValue);
  74. } else {
  75. leakValue = lastResult.leakValue;
  76. if (leakValue == 0 && !lastResult.isPass) {
  77. MesClient.param4.setText("9999 ml/min");
  78. leakValue = 9999;
  79. } else {
  80. MesClient.param4.setText(lastResult.leakValue + " ml/min");
  81. }
  82. }
  83. // 必须用右侧 running 标志,不能用全局 leakCheckMode
  84. if (MesClient.leakCheckRunningR) {
  85. final double judgeVal = leakValue;
  86. String deviceType = MesClient.configParam.getDevice2() != null ? MesClient.configParam.getDevice2() : "ateq";
  87. javax.swing.SwingUtilities.invokeLater(() ->
  88. MesClient.finishLeakCheck(
  89. 1,
  90. lastResult.pressureValue + "",
  91. lastResult.pressureUnit,
  92. String.valueOf(judgeVal),
  93. "ml/min",
  94. deviceType));
  95. } else {
  96. handleQmEnd(lastResult, leakValue);
  97. }
  98. } catch (Exception e) {
  99. log.error("右工位轮询报错", e);
  100. }
  101. }
  102. private void handleQmEnd(ATEQ2.LastResult lastResult, double leakValue) {
  103. String lastRet = lastResult.isPass ? "OK" : "NG";
  104. if (leakValue == 9999) {
  105. lastRet = "NG";
  106. }
  107. if ("OK".equals(lastRet)) {
  108. MesClient.result2.setText("OK");
  109. MesClient.result2.setForeground(Color.GREEN);
  110. } else {
  111. MesClient.result2.setText("NG");
  112. MesClient.result2.setForeground(Color.RED);
  113. }
  114. String testDate = DateLocalUtils.getCurrentTime();
  115. TestParam testParam = new TestParam();
  116. testParam.setSn(MesClient.product_sn2.getText().trim());
  117. testParam.setUcode(MesClient.user_menu.getText().trim());
  118. testParam.setLineSn(MesClient.configParam.getLineSn());
  119. testParam.setOprno(MesClient.configParam.getOprno2());
  120. testParam.setOprnoTitle(MesClient.configParam.getOprnoTitle2());
  121. testParam.setPressure(String.valueOf(lastResult.pressureValue));
  122. testParam.setPressureUnit(lastResult.pressureUnit);
  123. testParam.setLeak(String.valueOf(lastResult.leakValue));
  124. testParam.setLeakUnit("ml/min");
  125. testParam.setProgramNo(LeakCheckUtil.qmProgramNoForSide(1));
  126. testParam.setResult(lastRet);
  127. testParam.setCreateTime(testDate);
  128. testParam.setDeviceType("ateq");
  129. testParam.setRemark("");
  130. if (QmUploadUtil.saveAndUpload(testParam, false)) {
  131. MesClient.resetScanB();
  132. MesClient.setMenuStatus("右工位测试结果已保存,请扫下一件", 0);
  133. }
  134. if ("是".equals(MesClient.configParam.getPrintLabel()) && "OK".equals(lastRet)) {
  135. TestParam testParamLeft = JdbcUtils.getTestBySn(testParam.getSn(), testParam.getCreateTime());
  136. if (testParamLeft != null && "OK".equals(testParamLeft.getResult())) {
  137. try {
  138. PrintUtil.printLabel(
  139. testParam.getSn(),
  140. testParamLeft.getLeak() + testParamLeft.getLeakUnit(),
  141. testParam.getLeak() + testParam.getLeakUnit(),
  142. testDate);
  143. } catch (Exception e) {
  144. log.error("打印报错", e);
  145. }
  146. }
  147. }
  148. }
  149. }
  150. }