|
|
@@ -80,16 +80,99 @@ public class ATEQ {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 读取测试状态字 0x2204(1个字)
|
|
|
- * 高字节: 00=测试中, 21=OK, 其他=各类NG
|
|
|
- * 读法: 先 10 30 04 选程序,再 03 22 04
|
|
|
+ * 读取实时测试状态字 0x2204(完整 1 字)
|
|
|
+ * 手册: bit5=周期结束, bit0=pass(最终合格请用 Last Time 2303,勿单独用本寄存器定结果)
|
|
|
+ * 读法: 先 10 30 04 选程序,再 03 22 04 00 01
|
|
|
*/
|
|
|
public static int readTestStatusCode() {
|
|
|
byte[] read = selectThenReadHolding("22 04", 1);
|
|
|
- if (read == null || read.length < 7) {
|
|
|
+ if (read == null || read.length < 5) {
|
|
|
throw new RuntimeException("读取测试状态时, 返回的数据长度不够, hex=" + DataUtils.bytesToHex(read == null ? new byte[0] : read));
|
|
|
}
|
|
|
- return read[3] & 0xFF;
|
|
|
+ // 例: 应答 01 03 02 21 80 → 状态字 0x8021(小端)
|
|
|
+ return DataUtils.bytesToInt(Arrays.copyOfRange(read, 3, 5));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取 Last Time 最终测试状态 0x2303(ok/NG/alarm)
|
|
|
+ * 命令: 站号 03 23 03 00 01 + CRC;bit0=1 合格
|
|
|
+ */
|
|
|
+ public static int readLastTimeStatusWord() {
|
|
|
+ byte[] read = selectThenReadHolding("23 03", 1);
|
|
|
+ if (read == null || read.length < 5) {
|
|
|
+ throw new RuntimeException("读取最终状态2303失败, hex=" + DataUtils.bytesToHex(read == null ? new byte[0] : read));
|
|
|
+ }
|
|
|
+ int word = DataUtils.bytesToInt(Arrays.copyOfRange(read, 3, 5));
|
|
|
+ log.info("LastTime 2303 状态字=0x{}, bit0(合格)={}, 原始={}",
|
|
|
+ String.format("%04X", word), DataUtils.getBit(word, 0), DataUtils.bytesToHex(read));
|
|
|
+ return word;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Last Time 压力 2305-2306 */
|
|
|
+ public static double readLastTimePressure() {
|
|
|
+ return parseDwordValue(selectThenReadHolding("23 05", 2));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Last Time 压力单位 2307-2308 */
|
|
|
+ public static String readLastTimePressureUnit() {
|
|
|
+ return parseUnit(selectThenReadHolding("23 07", 2));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Last Time 泄漏 2309-230A */
|
|
|
+ public static double readLastTimeLeak() {
|
|
|
+ return parseDwordValue(selectThenReadHolding("23 09", 2));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Last Time 泄漏单位 230B-230C */
|
|
|
+ public static String readLastTimeLeakUnit() {
|
|
|
+ return parseUnit(selectThenReadHolding("23 0B", 2));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测完后读取 Last Time 最终结果(2303 判 OK/NG,2305/2309 压力泄漏)
|
|
|
+ */
|
|
|
+ public static FinalResult readLastTimeFinalResult() {
|
|
|
+ int statusWord = 0;
|
|
|
+ boolean isPass = false;
|
|
|
+ double pressureValue = 0;
|
|
|
+ String pressureUnit = "";
|
|
|
+ double leakValue = 0;
|
|
|
+ String leakUnit = "";
|
|
|
+
|
|
|
+ try {
|
|
|
+ statusWord = readLastTimeStatusWord();
|
|
|
+ isPass = DataUtils.getBit(statusWord, 0) == 1;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("读最终状态2303失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ sleepQuiet(50);
|
|
|
+ try {
|
|
|
+ pressureValue = readLastTimePressure();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("读最终压力2305失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ sleepQuiet(50);
|
|
|
+ try {
|
|
|
+ pressureUnit = readLastTimePressureUnit();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("读最终压力单位2307失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ sleepQuiet(50);
|
|
|
+ try {
|
|
|
+ leakValue = readLastTimeLeak();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("读最终泄漏2309失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ sleepQuiet(50);
|
|
|
+ try {
|
|
|
+ leakUnit = readLastTimeLeakUnit();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("读最终泄漏单位230B失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ FinalResult finalResult = new FinalResult(statusWord, isPass, pressureValue, pressureUnit, leakValue, leakUnit);
|
|
|
+ log.info(finalResult.toString());
|
|
|
+ return finalResult;
|
|
|
}
|
|
|
|
|
|
/** 压力 0x2206:先 10 30 04,再 03 22 06 00 02 */
|
|
|
@@ -237,12 +320,17 @@ public class ATEQ {
|
|
|
}
|
|
|
|
|
|
public static class MeasureResult {
|
|
|
- public final int statusCode; // 状态高字节: 00测试中, 21=OK, 其他=NG
|
|
|
+ /** 2204 完整状态字(如 0x8021) */
|
|
|
+ public final int statusCode;
|
|
|
public final Double pressureValue;
|
|
|
public final String pressureUnit;
|
|
|
public final Double leakValue;
|
|
|
public final String leakUnit;
|
|
|
+ /** bit5=0:测试进行中 */
|
|
|
public final boolean isTesting;
|
|
|
+ /** bit5=1:周期结束(最终 OK/NG 请读 2303) */
|
|
|
+ public final boolean isCycleEnd;
|
|
|
+ /** 2204 的 bit0,仅参考,收尾以 FinalResult 为准 */
|
|
|
public final boolean isPass;
|
|
|
|
|
|
public MeasureResult(int statusCode, Double pressureValue, String pressureUnit,
|
|
|
@@ -252,22 +340,54 @@ public class ATEQ {
|
|
|
this.pressureUnit = pressureUnit != null ? pressureUnit : "";
|
|
|
this.leakValue = leakValue;
|
|
|
this.leakUnit = leakUnit != null ? leakUnit : "";
|
|
|
- this.isTesting = statusCode == 0x00;
|
|
|
- this.isPass = statusCode == 0x21;
|
|
|
+ this.isCycleEnd = DataUtils.getBit(statusCode, 5) == 1;
|
|
|
+ this.isTesting = !this.isCycleEnd;
|
|
|
+ this.isPass = DataUtils.getBit(statusCode, 0) == 1;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
return "测量结果{" +
|
|
|
- " 状态码: 0x" + String.format("%02X", statusCode) +
|
|
|
+ " 状态字: 0x" + String.format("%04X", statusCode) +
|
|
|
", 测试中: " + isTesting +
|
|
|
- ", 通过: " + isPass +
|
|
|
+ ", 周期结束: " + isCycleEnd +
|
|
|
+ ", bit0参考合格: " + isPass +
|
|
|
", 压力值: " + pressureValue + pressureUnit +
|
|
|
", 泄漏值: " + leakValue + leakUnit +
|
|
|
'}';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** Last Time(23xx)最终结果 */
|
|
|
+ public static class FinalResult {
|
|
|
+ public final int statusWord; // 2303
|
|
|
+ public final boolean isPass; // bit0
|
|
|
+ public final Double pressureValue;
|
|
|
+ public final String pressureUnit;
|
|
|
+ public final Double leakValue;
|
|
|
+ public final String leakUnit;
|
|
|
+
|
|
|
+ public FinalResult(int statusWord, boolean isPass, Double pressureValue, String pressureUnit,
|
|
|
+ Double leakValue, String leakUnit) {
|
|
|
+ this.statusWord = statusWord;
|
|
|
+ this.isPass = isPass;
|
|
|
+ this.pressureValue = pressureValue;
|
|
|
+ this.pressureUnit = pressureUnit != null ? pressureUnit : "";
|
|
|
+ this.leakValue = leakValue;
|
|
|
+ this.leakUnit = leakUnit != null ? leakUnit : "";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return "最终结果LastTime{" +
|
|
|
+ " 2303=0x" + String.format("%04X", statusWord) +
|
|
|
+ ", 通过: " + isPass +
|
|
|
+ ", 压力: " + pressureValue + pressureUnit +
|
|
|
+ ", 泄漏: " + leakValue + leakUnit +
|
|
|
+ '}';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 读取实时结果(旧协议,保留备用)
|
|
|
public static RealtimeResult readRealtimeResult() {
|
|
|
String s1 = DataUtils.CRC16(ATEQ.getStationNo()+" 03 00 30 00 0D");
|