|
@@ -8,6 +8,8 @@ import com.mes.util.HttpUtils;
|
|
|
import com.mes.util.JdbcUtils;
|
|
import com.mes.util.JdbcUtils;
|
|
|
import com.mes.util.Op310PlcPoint;
|
|
import com.mes.util.Op310PlcPoint;
|
|
|
import com.mes.util.PlcService;
|
|
import com.mes.util.PlcService;
|
|
|
|
|
+import com.mes.util.Ut5310ScpiService;
|
|
|
|
|
+import com.mes.util.Ut5310TestResult;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import javax.swing.*;
|
|
import javax.swing.*;
|
|
@@ -37,6 +39,7 @@ public class MesClient extends JFrame {
|
|
|
public static String mes_gw_des = ""; // 工位名称
|
|
public static String mes_gw_des = ""; // 工位名称
|
|
|
public static String mes_server_ip = ""; // 服务器IP地址
|
|
public static String mes_server_ip = ""; // 服务器IP地址
|
|
|
public static int mes_heart_icon_cycle = 1;
|
|
public static int mes_heart_icon_cycle = 1;
|
|
|
|
|
+ public static boolean mes_ut5310_enable = false;
|
|
|
public static String mes_line_sn = ""; // 产线编号
|
|
public static String mes_line_sn = ""; // 产线编号
|
|
|
public static String mes_plc_ip = "192.168.0.3"; // PLC IP地址
|
|
public static String mes_plc_ip = "192.168.0.3"; // PLC IP地址
|
|
|
|
|
|
|
@@ -45,6 +48,7 @@ public class MesClient extends JFrame {
|
|
|
public static final int PLC_PHASE_WAIT_REQUEST = 2;
|
|
public static final int PLC_PHASE_WAIT_REQUEST = 2;
|
|
|
public static final int PLC_PHASE_WAIT_OPERATOR = 3;
|
|
public static final int PLC_PHASE_WAIT_OPERATOR = 3;
|
|
|
public static final int PLC_PHASE_WAIT_READY = 4;
|
|
public static final int PLC_PHASE_WAIT_READY = 4;
|
|
|
|
|
+ public static final int PLC_PHASE_WAIT_UT5310 = 5;
|
|
|
|
|
|
|
|
//session
|
|
//session
|
|
|
public static String sessionid = "";
|
|
public static String sessionid = "";
|
|
@@ -109,6 +113,7 @@ public class MesClient extends JFrame {
|
|
|
private static boolean lastReady = false;
|
|
private static boolean lastReady = false;
|
|
|
private static boolean lastError = false;
|
|
private static boolean lastError = false;
|
|
|
private static int mesBitlifeCounter = 0;
|
|
private static int mesBitlifeCounter = 0;
|
|
|
|
|
+ private static final ExecutorService ut5310Executor = Executors.newSingleThreadExecutor();
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
@@ -157,6 +162,16 @@ public class MesClient extends JFrame {
|
|
|
mes_gw = pro.getProperty("mes.gw");
|
|
mes_gw = pro.getProperty("mes.gw");
|
|
|
mes_line_sn = pro.getProperty("mes.line_sn");
|
|
mes_line_sn = pro.getProperty("mes.line_sn");
|
|
|
String plcIp = pro.getProperty("mes.plc_ip");
|
|
String plcIp = pro.getProperty("mes.plc_ip");
|
|
|
|
|
+ mes_ut5310_enable = Boolean.parseBoolean(pro.getProperty("mes.ut5310_enable", "false"));
|
|
|
|
|
+ Ut5310ScpiService.configure(
|
|
|
|
|
+ pro.getProperty("mes.ut5310_port", "COM1"),
|
|
|
|
|
+ getIntProperty(pro, "mes.ut5310_baud_rate", 9600),
|
|
|
|
|
+ getIntProperty(pro, "mes.ut5310_data_bits", 8),
|
|
|
|
|
+ getIntProperty(pro, "mes.ut5310_stop_bits", 1),
|
|
|
|
|
+ pro.getProperty("mes.ut5310_parity", "NONE"),
|
|
|
|
|
+ getIntProperty(pro, "mes.ut5310_read_timeout_ms", 1000),
|
|
|
|
|
+ getIntProperty(pro, "mes.ut5310_test_timeout_ms", 60000),
|
|
|
|
|
+ getIntProperty(pro, "mes.ut5310_fetch_interval_ms", 500));
|
|
|
|
|
|
|
|
if (mes_gw == null) {
|
|
if (mes_gw == null) {
|
|
|
mes_gw = "";
|
|
mes_gw = "";
|
|
@@ -185,6 +200,18 @@ public class MesClient extends JFrame {
|
|
|
log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";");
|
|
log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static int getIntProperty(Properties pro, String name, int defaultValue) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String value = pro.getProperty(name);
|
|
|
|
|
+ if (value == null || value.trim().isEmpty()) {
|
|
|
|
|
+ return defaultValue;
|
|
|
|
|
+ }
|
|
|
|
|
+ return Integer.parseInt(value.trim());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return defaultValue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static void applyOpConfig(String op, String opName, String ip) {
|
|
public static void applyOpConfig(String op, String opName, String ip) {
|
|
|
if (op != null) {
|
|
if (op != null) {
|
|
|
mes_gw = op.trim();
|
|
mes_gw = op.trim();
|
|
@@ -609,12 +636,23 @@ public class MesClient extends JFrame {
|
|
|
if (plcPhase == PLC_PHASE_WAIT_REQUEST) {
|
|
if (plcPhase == PLC_PHASE_WAIT_REQUEST) {
|
|
|
if (requestResult && !lastRequestResult) {
|
|
if (requestResult && !lastRequestResult) {
|
|
|
PlcService.setStart(false);
|
|
PlcService.setStart(false);
|
|
|
|
|
+ if (mes_ut5310_enable) {
|
|
|
|
|
+ plcPhase = PLC_PHASE_WAIT_UT5310;
|
|
|
|
|
+ String sn = product_sn == null ? "" : product_sn.getText().trim();
|
|
|
|
|
+ SwingUtilities.invokeLater(() -> {
|
|
|
|
|
+ finish_ok_bt.setEnabled(false);
|
|
|
|
|
+ finish_ng_bt.setEnabled(false);
|
|
|
|
|
+ setMenuStatus("工装到位,开始绝缘耐压测试", 0);
|
|
|
|
|
+ });
|
|
|
|
|
+ startUt5310TestAsync(sn);
|
|
|
|
|
+ } else {
|
|
|
plcPhase = PLC_PHASE_WAIT_OPERATOR;
|
|
plcPhase = PLC_PHASE_WAIT_OPERATOR;
|
|
|
SwingUtilities.invokeLater(() -> {
|
|
SwingUtilities.invokeLater(() -> {
|
|
|
finish_ok_bt.setEnabled(true);
|
|
finish_ok_bt.setEnabled(true);
|
|
|
finish_ng_bt.setEnabled(true);
|
|
finish_ng_bt.setEnabled(true);
|
|
|
setMenuStatus("设备加工完成,请确认OK/NG", 0);
|
|
setMenuStatus("设备加工完成,请确认OK/NG", 0);
|
|
|
});
|
|
});
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} else if (plcPhase == PLC_PHASE_WAIT_READY) {
|
|
} else if (plcPhase == PLC_PHASE_WAIT_READY) {
|
|
|
if (ready && !lastReady) {
|
|
if (ready && !lastReady) {
|
|
@@ -637,6 +675,82 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static void startUt5310TestAsync(String sn) {
|
|
|
|
|
+ ut5310Executor.submit(() -> {
|
|
|
|
|
+ if (sn == null || sn.trim().isEmpty()) {
|
|
|
|
|
+ submitUt5310Result("", new Ut5310TestResult(false, "ERROR", "empty sn"));
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ SwingUtilities.invokeLater(() -> setMenuStatus("绝缘耐压测试中...", 0));
|
|
|
|
|
+ Ut5310TestResult result = Ut5310ScpiService.startAndFetchResult();
|
|
|
|
|
+ submitUt5310Result(sn, result);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.info("UT5310测试异常: {}", e.getMessage());
|
|
|
|
|
+ submitUt5310Result(sn, new Ut5310TestResult(false, "ERROR", e.getMessage()));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean submitUt5310Result(String sn, Ut5310TestResult testResult) {
|
|
|
|
|
+ if (plcPhase != PLC_PHASE_WAIT_UT5310) {
|
|
|
|
|
+ SwingUtilities.invokeLater(() -> setMenuStatus("当前状态不允许提交绝缘耐压结果", -1));
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!PlcService.ensureConnected()) {
|
|
|
|
|
+ SwingUtilities.invokeLater(() -> {
|
|
|
|
|
+ setMenuStatus("PLC未连接,请检查网络", -1);
|
|
|
|
|
+ updatePlcStatus(false);
|
|
|
|
|
+ });
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ SwingUtilities.invokeLater(() -> updatePlcStatus(true));
|
|
|
|
|
+
|
|
|
|
|
+ boolean isOk = testResult != null && testResult.isOk();
|
|
|
|
|
+ String mesResult = isOk ? "OK" : "NG";
|
|
|
|
|
+ boolean plcWriteOk = isOk ? PlcService.setTestOk(true) : PlcService.setTestNg(true);
|
|
|
|
|
+ if (!plcWriteOk) {
|
|
|
|
|
+ SwingUtilities.invokeLater(() -> setMenuStatus("写入PLC绝缘耐压结果失败", -1));
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject retObj = DataUtil.sendQuality(sn, mesResult, user20,
|
|
|
|
|
+ testResult == null ? "" : testResult.getJudge(),
|
|
|
|
|
+ testResult == null ? "" : testResult.getRawResponse());
|
|
|
|
|
+ if (retObj == null) {
|
|
|
|
|
+ if (isOk) {
|
|
|
|
|
+ PlcService.setTestOk(false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ PlcService.setTestNg(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ SwingUtilities.invokeLater(() -> setMenuStatus("绝缘耐压结果上传失败,请重试", -1));
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
|
|
+ plcPhase = PLC_PHASE_WAIT_READY;
|
|
|
|
|
+ SwingUtilities.invokeLater(() -> {
|
|
|
|
|
+ finish_ok_bt.setEnabled(false);
|
|
|
|
|
+ finish_ng_bt.setEnabled(false);
|
|
|
|
|
+ setMenuStatus("绝缘耐压结果已提交,等待设备复位...", 0);
|
|
|
|
|
+ });
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (isOk) {
|
|
|
|
|
+ PlcService.setTestOk(false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ PlcService.setTestNg(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ SwingUtilities.invokeLater(() -> {
|
|
|
|
|
+ if (retObj.get("result") == null) {
|
|
|
|
|
+ setMenuStatus("绝缘耐压结果上传失败,请重试", -1);
|
|
|
|
|
+ } else if (retObj.get("result").toString().equalsIgnoreCase("false")) {
|
|
|
|
|
+ setMenuStatus(retObj.getString("message"), -1);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private static boolean submitPlcResult(String sn, String result, boolean isOk) {
|
|
private static boolean submitPlcResult(String sn, String result, boolean isOk) {
|
|
|
if (plcPhase != PLC_PHASE_WAIT_OPERATOR) {
|
|
if (plcPhase != PLC_PHASE_WAIT_OPERATOR) {
|
|
|
setMenuStatus("当前状态不允许提交结果", -1);
|
|
setMenuStatus("当前状态不允许提交结果", -1);
|