| | |
| | | String receivedCRC = hexData.substring(hexData.length() - 6); |
| | | byte[] cmdBytes = HexUtil.hexStringToBytes(hexData.replace(receivedCRC,"")); |
| | | String crc = HexUtil.calculate(cmdBytes)+"00"; |
| | | System.out.println("收到的完整数据是:"+hexData); |
| | | System.out.println("收到数据校验码是:"+receivedCRC); |
| | | System.out.println("校验码是:"+crc); |
| | | //System.out.println("收到的完整数据是:"+hexData); |
| | | //System.out.println("收到数据校验码是:"+receivedCRC); |
| | | //System.out.println("校验码是:"+crc); |
| | | return receivedCRC.equalsIgnoreCase(crc); |
| | | } catch (Exception e) { |
| | | System.err.println("CRC校验异常: " + e.getMessage()); |
| | |
| | | sb.append("9. 电压: ").append(String.format("%.2f", voltage)); |
| | | sb.append("10. 电流: ").append(String.format("%.2f", current)); |
| | | sb.append("数据长度: ").append(dataLength).append(" 字节"); |
| | | // System.out.println(sb.toString()); |
| | | // //System.out.println(sb.toString()); |
| | | return sb.toString(); |
| | | } |
| | | |