| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- package com.mes.util;
- import com.mes.ui.MesClient;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import java.util.Arrays;
- public class ATEQ2 {
- private static final Logger log = LoggerFactory.getLogger(ATEQ2.class);
- public static boolean stop() {
- String s1 = DataUtils.CRC16(ATEQ2.getStationNo()+" 05 00 00 FF 00");
- byte[] read = MesClient.serialPortUtils2.read(s1);
- boolean result = Arrays.equals(read, DataUtils.hexStringToByteArray(s1));
- log.info("右工位气密仪停止{}", result ? "成功" : "失败");
- return result;
- }
- public static boolean start() {
- String s1 = DataUtils.CRC16(ATEQ2.getStationNo()+" 05 00 01 FF 00");
- System.out.println("s1:"+s1);
- byte[] read = MesClient.serialPortUtils2.read(s1);
- boolean result = Arrays.equals(read, DataUtils.hexStringToByteArray(s1));
- log.info("右工位气密仪开始{}", result ? "成功" : "失败");
- return result;
- }
- // public static boolean resetFIFO() {
- // byte[] read = SerialUtil.read("01 05 00 02 FF 00 2D FA");
- // boolean result = Arrays.equals(read, DataUtils.hexStringToByteArray("01 05 00 02 FF 00 2D FA"));
- // log.info("重置FIFO{}", result ? "成功" : "失败");
- // return result;
- // }
- // 读取实时结果
- public static RealtimeResult readRealtimeResult() {
- String s1 = DataUtils.CRC16(ATEQ2.getStationNo()+" 03 00 30 00 0D");
- byte[] read = MesClient.serialPortUtils2.read(s1);
- System.out.println("右工位结果读取:"+DataUtils.bytesToHex(read));
- if(read.length > 30) {
- return new RealtimeResult(read);
- } else {
- throw new RuntimeException("右工位读取实时结果时, 返回的数据长度不够");
- }
- }
- // // 读取先入先出队列中的待处理结果
- // public static FIFOResult readFIFOResult() {
- // byte[] read = SerialUtil.read("01 03 00 10 00 0D 85 CA");
- // if(read.length > 28) {
- // return new FIFOResult(read);
- // } else {
- // throw new RuntimeException("读取FIFO结果时, 返回的数据长度不够");
- // }
- // }
- // 读取最后结果
- public static LastResult readLastResult() {
- String s1 = DataUtils.CRC16(ATEQ2.getStationNo()+" 03 00 11 00 0C");
- byte[] read = MesClient.serialPortUtils2.read(s1);
- if(read.length > 20) {
- return new LastResult(read);
- } else {
- throw new RuntimeException("右工位读取FIFO结果时, 返回的数据长度不够");
- }
- }
- // 获取参数, 传入程序号, 获取对应程序号的参数
- public static Parameters getParams(Integer programNumber) {
- // 步骤1: 选择要编辑的程序
- String s1 = DataUtils.CRC16("01 10 30 04 00 01 02 " + DataUtils.intToWord(programNumber - 1));
- MesClient.serialPortUtils2.read(s1);
- // 步骤2: 写入要读取的标识符
- String s2 = "01 10 00 00 00 04 08 03 00 01 00 02 00 03 00 F6 F6"; // s2 表示读取3个参数, 分别是 填充时间、稳定时间、测试时间
- MesClient.serialPortUtils2.read(s2);
- // 步骤3: 读取数据
- byte[] read = MesClient.serialPortUtils2.read("01 03 00 00 00 09 85 CC");
- if(read.length > 22) {
- return new Parameters(read);
- } else {
- throw new RuntimeException("读取参数时, 返回的数据长度不够");
- }
- }
- // 获取站号
- public static String getStationNo() {
- try{
- int decimalNumber = Integer.valueOf(MesClient.configParam.getModbusSite2()); // 示例十进制数
- String hexString = Integer.toHexString(decimalNumber); // 转换为16进制字符串
- // System.out.println(hexString.toUpperCase()); // 输出结果
- if(hexString.length() == 1) {
- hexString = "0" + hexString;
- }
- return hexString;
- }catch (Exception e){
- return "01";
- }
- }
- public static class RealtimeResult {
- public final Integer programNumber; // 程序号
- // public final Integer FIFO_Number;
- public final String testType; // 测试类型
- public final String step; // 当前步骤
- public final Integer stepCode; // 当前步骤码
- public final Double pressureValue; // 压力值
- public final Double leakValue; // 泄漏值
- public final Boolean isCycleEnd; // 测试是否结束
- public final Boolean isPass; // 测试是否通过
- public final Boolean isKeyExist; //
- public final String pressureUnit; // 压力单位
- public final String leakUnit; // 泄漏单位
- public RealtimeResult(byte[] data) {
- // 大端排序互换位置
- // 01031a 0000(程序号) 0800(测试模式) 0100(测试状态) 0080(报警状态) 0600(测试阶段) 160d0000(测试压力) e02e0000(压力单位) 00000000(泄漏量结果) 38c70000(泄漏量单位) cf93
- // 01031a 0000(程序号) 0800(测试模式) 0100(测试状态) 3080(报警状态) ffff(测试阶段) 160d0000(测试压力) e02e0000(压力单位) 00000000(泄漏量结果) 38c70000(泄漏量单位) 1b0a
- System.out.println("右工位实时数据:"+DataUtils.bytesToHex(data));
- this.programNumber = DataUtils.bytesToInt(Arrays.copyOfRange(data, 3, 5)) + 1;
- // this.FIFO_Number = DataUtils.bytesToInt(Arrays.copyOfRange(data, 5, 7));
- this.testType = getTestTypeStr(DataUtils.bytesToInt(Arrays.copyOfRange(data, 5, 7)));
- int state = DataUtils.bytesToInt(Arrays.copyOfRange(data, 7, 9));
- this.isCycleEnd = DataUtils.getBit(state, 5) == 1;
- this.isPass = DataUtils.getBit(state, 0) == 1;
- this.isKeyExist = DataUtils.getBit(state, 15) == 1;
- this.stepCode = DataUtils.bytesToInt(Arrays.copyOfRange(data, 11, 13));
- this.step = getStepStr(this.stepCode);
- this.pressureValue = DataUtils.bytesToInt(Arrays.copyOfRange(data, 13, 17)) / 1000.0;
- this.pressureUnit = getUnit(DataUtils.bytesToInt(Arrays.copyOfRange(data, 17, 21)));
- this.leakValue = DataUtils.bytesToInt(Arrays.copyOfRange(data, 21, 25)) / 1000.0;
- this.leakUnit = getUnit(DataUtils.bytesToInt(Arrays.copyOfRange(data, 25, 29)));
- }
- @Override
- public String toString() {
- return "右工位实时结果{" +
- " 压力值: " + pressureValue +
- ", 泄漏值: " + leakValue +
- // ", FIFO数量: " + FIFO_Number +
- ", 当前步骤CODE: " + stepCode +
- ", 当前步骤: " + step +
- // ", 循环是否结束: " + isCycleEnd +
- // ", 测试通过: " + isPass +
- // ", 是否关键存在: " + isKeyExist +
- ", 程序号: " + programNumber +
- // ", 测试类型: " + testType +
- '}';
- }
- }
- // public static class FIFOResult {
- // public final Integer programNumber;
- // public final String testType;
- // public final Double pressureValue;
- // public final Double leakValue;
- // public final Boolean isPass;
- // public final Boolean isTestLeak;
- // public final Boolean isReferLeak;
- // public final String pressureUnit;
- // public final String leakUnit;
- // public FIFOResult(byte[] data) {
- // this.programNumber = DataUtils.bytesToInt(Arrays.copyOfRange(data, 3, 5)) + 1;
- // this.testType = getTestTypeStr(DataUtils.bytesToInt(Arrays.copyOfRange(data, 5, 7)));
- // int state = DataUtils.bytesToInt(Arrays.copyOfRange(data, 7, 9));
- // this.isPass = DataUtils.getBit(state, 0) == 1;
- // this.isTestLeak = DataUtils.getBit(state, 1) == 1;
- // this.isReferLeak = DataUtils.getBit(state, 2) == 1;
- // this.pressureValue = DataUtils.bytesToInt(Arrays.copyOfRange(data, 11, 15)) / 1000.0;
- // this.pressureUnit = getUnit(DataUtils.bytesToInt(Arrays.copyOfRange(data, 15, 19)));
- // this.leakValue = DataUtils.bytesToInt(Arrays.copyOfRange(data, 19, 23)) / 1000.0;
- // this.leakUnit = getUnit(DataUtils.bytesToInt(Arrays.copyOfRange(data, 23, 27)));
- // }
- //
- // @Override
- // public String toString() {
- // return "FIFO结果{" +
- // " 压力值: " + pressureValue +
- // ", 泄漏值: " + leakValue +
- // ", 测试通过: " + isPass +
- // ", 测试泄漏: " + isTestLeak +
- // ", 参考泄漏: " + isReferLeak +
- // ", 程序号: " + programNumber +
- // ", 测试类型: " + testType +
- // '}';
- // }
- // }
- // 最后结果类
- public static class LastResult {
- public final Integer programNumber; // 程序号
- public final String testType; // 测试类型
- public final Double pressureValue; // 压力值
- public final Double leakValue; // 泄漏值
- public final Boolean isPass; // 测试是否通过(true表示OK, false表示NG)
- public final Boolean isTestLeak;
- public final Boolean isReferLeak;
- public final String pressureUnit; // 压力单位
- public final String leakUnit; // 测试单位
- public LastResult(byte[] data) {
- // 010318 0000(程序号) 0100(测试模式) 0800(测试状态) 0200(报警状态) 160D0000(压力值) E02E0000(压力单位) 00000000(泄露值) 38C70000(泄露值单位) 1EE9
- log.info("最终结果:"+DataUtils.bytesToHex(data));
- this.programNumber = DataUtils.bytesToInt(Arrays.copyOfRange(data, 3, 5)) + 1;
- this.testType = getTestTypeStr(DataUtils.bytesToInt(Arrays.copyOfRange(data, 5, 7)));
- int state = DataUtils.bytesToInt(Arrays.copyOfRange(data, 7, 9));
- this.isPass = DataUtils.getBit(state, 0) == 1;
- this.isTestLeak = DataUtils.getBit(state, 1) == 1;
- this.isReferLeak = DataUtils.getBit(state, 2) == 1;
- this.pressureValue = DataUtils.bytesToInt(Arrays.copyOfRange(data, 11, 15)) / 1000.0;
- this.pressureUnit = getUnit(DataUtils.bytesToInt(Arrays.copyOfRange(data, 15, 19)));
- this.leakValue = DataUtils.bytesToInt(Arrays.copyOfRange(data, 19, 23)) / 1000.0;
- this.leakUnit = getUnit(DataUtils.bytesToInt(Arrays.copyOfRange(data, 23, 27)));
- if(this.leakValue == 0 && !this.isPass){
- // this.leakValue = Double.valueOf(9999);
- }
- }
- @Override
- public String toString() {
- return "最后结果{" +
- " 压力值: " + pressureValue +
- ", 泄漏值: " + leakValue +
- ", 测试通过: " + isPass +
- ", 测试泄漏: " + isTestLeak +
- ", 参考泄漏: " + isReferLeak +
- ", 程序号: " + programNumber +
- // ", 测试类型: " + testType +
- '}';
- }
- }
- // 参数类
- public static class Parameters {
- public final Integer fillTime; // 填充时间
- public final Integer stabilizeTime; // 稳定时间
- public final Integer testTime; // 测试时间
- public Parameters(byte[] data) {
- log.info("时间参数:"+DataUtils.bytesToHex(data));
- this.fillTime = DataUtils.bytesToInt(Arrays.copyOfRange(data, 5, 9)) / 1000;
- this.stabilizeTime = DataUtils.bytesToInt(Arrays.copyOfRange(data, 11, 15)) / 1000;
- this.testTime = DataUtils.bytesToInt(Arrays.copyOfRange(data, 17, 21)) / 1000;
- }
- @Override
- public String toString() {
- return "参数{" +
- "填充时间: " + fillTime +
- "s, 稳定时间: " + stabilizeTime +
- "s, 测试时间: " + testTime +
- "s}";
- }
- }
- private static String getTestTypeStr(Integer testTypeCode) {
- String s = "未知";
- if(testTypeCode == 1) {
- s = "泄漏";
- }
- return s;
- }
- private static String getStepStr(Integer stepCode) {
- String s = "未知";
- switch (stepCode) {
- case 0:
- s = "预填充";
- break;
- case 1:
- s = "预排气";
- break;
- case 2:
- s = "密封零件测试充气";
- break;
- case 3:
- s = "密封零件测试保压";
- break;
- case 4:
- s = "充气";
- break;
- case 5:
- s = "保压";
- break;
- case 6:
- // s = "测试"; // 充气
- s = "充气";
- break;
- case 7:
- // s = "排气"; // 保压
- s = "保压";
- break;
- case 8:
- s = "测试"; // 保压
- break;
- case 65535:
- s = "未进行测试";
- break;
- }
- return s;
- }
- private static String getUnit(Integer unitCode) {
- String s = "";
- switch (unitCode) {
- case 0:
- s = "cm3/s";
- break;
- case 1000:
- s = "cm3/min";
- break;
- case 2000:
- s = "cm3/h";
- break;
- case 6000:
- s = "Pa";
- break;
- case 8000:
- s = "Pa/s";
- break;
- case 11000:
- s = "Bar";
- break;
- case 12000:
- s = "kPa";
- break;
- case 50000:
- s = "ml/s";
- break;
- case 51000:
- s = "ml/min";
- break;
- case 52000:
- s = "ml/h";
- break;
- }
- return s;
- }
- }
|