| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- package com.mes.util;
- import com.mes.ui.MesClient;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import java.awt.*;
- import java.util.Timer;
- import java.util.TimerTask;
- /**
- * 右工位 ateq 轮询(对齐 qm-new-2)
- */
- public class WorkTimer2 {
- private static final Logger log = LoggerFactory.getLogger(WorkTimer2.class);
- private static Timer workTimer = null;
- private WorkTimer2() {
- }
- public static void start() {
- if (workTimer != null) {
- workTimer.cancel();
- workTimer = null;
- }
- workTimer = new Timer();
- workTimer.schedule(new WorkTimerTask(), 1000, 2000);
- }
- public static void ensureStarted() {
- if (workTimer == null) {
- start();
- }
- }
- public static void stop() {
- if (workTimer != null) {
- workTimer.cancel();
- workTimer = null;
- }
- }
- private static class WorkTimerTask extends TimerTask {
- @Override
- public void run() {
- try {
- if (MesClient.work_status2 != 1) {
- return;
- }
- ATEQ2.RealtimeResult realtimeResult = ATEQ2.readRealtimeResult();
- log.info(realtimeResult.toString());
- boolean isEnd = false;
- if (realtimeResult.stepCode == 65535) {
- if (MesClient.mesStartFlag2 == 1) {
- isEnd = true;
- }
- } else {
- MesClient.mesStartFlag2 = 1;
- MesClient.setMenuStatus("右工位当前步骤:[" + realtimeResult.stepCode + "]" + realtimeResult.step, 0);
- }
- MesClient.param3.setText(isEnd ? "" : realtimeResult.pressureValue + " " + realtimeResult.pressureUnit);
- MesClient.param4.setText(isEnd ? "" : realtimeResult.leakValue + " ml/min");
- if (!isEnd) {
- return;
- }
- log.info("右工位检测结束...");
- // 对齐 qm:立即结束工作态,避免轮询重复判定覆盖结果
- MesClient.work_status2 = 0;
- MesClient.mesStartFlag2 = 0;
- double realtimeLeak = realtimeResult.leakValue;
- ATEQ2.LastResult lastResult = ATEQ2.readLastResult();
- log.info(lastResult.toString());
- MesClient.param3.setText(lastResult.pressureValue + lastResult.pressureUnit);
- double leakValue;
- if (MesClient.leakCheckRunningR) {
- leakValue = realtimeLeak;
- if (leakValue == 0 && lastResult.leakValue != 0) {
- leakValue = lastResult.leakValue;
- }
- MesClient.param4.setText(leakValue + " ml/min");
- log.info("标漏采用泄漏率判定值={}, 实时={}, 最终={}", leakValue, realtimeLeak, lastResult.leakValue);
- } else {
- leakValue = lastResult.leakValue;
- if (leakValue == 0 && !lastResult.isPass) {
- MesClient.param4.setText("9999 ml/min");
- leakValue = 9999;
- } else {
- MesClient.param4.setText(lastResult.leakValue + " ml/min");
- }
- }
- // 必须用右侧 running 标志,不能用全局 leakCheckMode
- if (MesClient.leakCheckRunningR) {
- final double judgeVal = leakValue;
- String deviceType = MesClient.configParam.getDevice2() != null ? MesClient.configParam.getDevice2() : "ateq";
- javax.swing.SwingUtilities.invokeLater(() ->
- MesClient.finishLeakCheck(
- 1,
- lastResult.pressureValue + "",
- lastResult.pressureUnit,
- String.valueOf(judgeVal),
- "ml/min",
- deviceType));
- } else {
- handleQmEnd(lastResult, leakValue);
- }
- } catch (Exception e) {
- log.error("右工位轮询报错", e);
- }
- }
- private void handleQmEnd(ATEQ2.LastResult lastResult, double leakValue) {
- String lastRet = lastResult.isPass ? "OK" : "NG";
- if (leakValue == 9999) {
- lastRet = "NG";
- }
- if ("OK".equals(lastRet)) {
- MesClient.result2.setText("OK");
- MesClient.result2.setForeground(Color.GREEN);
- } else {
- MesClient.result2.setText("NG");
- MesClient.result2.setForeground(Color.RED);
- }
- String testDate = DateLocalUtils.getCurrentTime();
- TestParam testParam = new TestParam();
- testParam.setSn(MesClient.product_sn2.getText().trim());
- testParam.setUcode(MesClient.user_menu.getText().trim());
- testParam.setLineSn(MesClient.configParam.getLineSn());
- testParam.setOprno(MesClient.configParam.getOprno2());
- testParam.setOprnoTitle(MesClient.configParam.getOprnoTitle2());
- testParam.setPressure(String.valueOf(lastResult.pressureValue));
- testParam.setPressureUnit(lastResult.pressureUnit);
- testParam.setLeak(String.valueOf(lastResult.leakValue));
- testParam.setLeakUnit("ml/min");
- testParam.setProgramNo(LeakCheckUtil.qmProgramNoForSide(1));
- testParam.setResult(lastRet);
- testParam.setCreateTime(testDate);
- testParam.setDeviceType("ateq");
- testParam.setRemark("");
- if (QmUploadUtil.saveAndUpload(testParam, false)) {
- MesClient.resetScanB();
- MesClient.setMenuStatus("右工位测试结果已保存,请扫下一件", 0);
- }
- if ("是".equals(MesClient.configParam.getPrintLabel()) && "OK".equals(lastRet)) {
- TestParam testParamLeft = JdbcUtils.getTestBySn(testParam.getSn(), testParam.getCreateTime());
- if (testParamLeft != null && "OK".equals(testParamLeft.getResult())) {
- try {
- PrintUtil.printLabel(
- testParam.getSn(),
- testParamLeft.getLeak() + testParamLeft.getLeakUnit(),
- testParam.getLeak() + testParam.getLeakUnit(),
- testDate);
- } catch (Exception e) {
- log.error("打印报错", e);
- }
- }
- }
- }
- }
- }
|