package com.sandu.ximon.admin.manager.iot.rrpc.util; public class CRCUtils { /** * 计算CRC16/Modbus校验码 高位在前,低位在后 * * @param hex 十六进制字符串 * @return CRC16校验码 */ public static String getCRC16 (String hex) { byte[] tx_buff = SupplementUtils.hexStringToBytes(hex); int[] result = CRCValidate.calculateCRC(tx_buff, 0, tx_buff.length); String hex1 = Integer.toHexString(result[1]); String hex2 = Integer.toHexString(result[0]); if (hex1.length()<2) { hex1 = "0" + hex1; } if (hex2.length()<2) { hex2 = "0" + hex2; } return ( hex2 + hex1 ).toUpperCase(); } }