Search code examples
vb.netserial-portcrc

Reverse CRC calculation


I am trying (unsuccessfully) to reverse CRC calculation for serial communication between computer and device using VB.Net. I have few examples only.

Command (for reading the records from device):
ff ff ff ff ff 02 01 02 1a 03 aa aa

Responses with data:

02 01 0a 1a 3a 00 3b f6 ec 80 79 24 03 7f 7f
02 01 0a 1a 36 00 3c 13 a6 ad 69 24 03 02 02
02 01 0a 1a 12 00 13 6f ba af 69 24 03 df df
02 01 0a 1a 10 00 a7 05 43 2c e9 25 03 57 57

01 is device ID.
0a byte is length.
1a is command (probably).
Data is stored from byte 00 to byte 03.

Response when there is no data:
02 01 02 2a 03 87 87

I think that last two bytes are crc. Any help how to calculate them?
Thanks in advance.


Solution

  • That is the MAXIM CRC-8, which has these parameters:

    width=8 poly=0x31 init=0x00 refin=true refout=true xorout=0x00 check=0xa1 name="CRC-8/MAXIM"
    

    from the RevEng catalog. As noted in the comments, the 8-bit CRC is repeated in the message. (The five 0xff bytes in your first example are not included in the CRC calculation.)

    You can use crcany to generate the code for that CRC.