美文网首页
crc循环校验

crc循环校验

作者: 银弹星空 | 来源:发表于2025-08-26 14:25 被阅读0次

传入10进制数据如何转换 高低 位显示

    /**
     * 发送指令
     *
     * @param plateAddress
     * @param functionCode 0x03 读 0x06写 0x10写
     *                     外边传入的都为10进制数 需进行校验
     */
    public void sendTrashCan(int plateAddress, String functionCode, String order, String byteNum) {
        int address = TRASH_BASE_ADDRESS + plateAddress;
        //判断写入的字符有没有高8位 低8位最高能表达255 所以256进1 所以除以256
        int byteNumInt = Integer.parseInt(byteNum);
        int highWei = byteNumInt / 256;
        int lowWei = byteNumInt % 256;
        String byte2hex = HexUtil.byte2hex(CRC16Util.Crc16RetDiGao(new byte[]{(byte) address, (byte) Integer.parseInt(functionCode),
                0, (byte) Integer.parseInt(order), (byte) highWei, (byte) lowWei}));
        LogUtil.e("发送垃圾桶命令 : " + byte2hex);
        try {
            sendTrashCanCMD(byte2hex.replaceAll(" ", ""));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

相关文章

网友评论

      本文标题:crc循环校验

      本文链接:https://www.haomeiwen.com/subject/zlgdajtx.html