CRC algorithm in PAC

Please help me, CRC algorithm in PAC how to achieve? C++ code is as follows

static BYTE crc_t1[]=
{
0x00,0x00,0xC1,0xC0,0x81,0xC1,0x40,0x01,0x01,0xC3,0xC0,0x03,0x80,0x02,0x41,0xC2,
0x01,0xC6,0xC0,0x06,0x80,0x07,0x41,0xC7,0x00,0x05,0xC1,0xC5,0x81,0xC4,0x40,0x04
};
static BYTE crc_t2[]=
{
0x00,0x00,0x01,0xCC,0x01,0xD8,0x00,0x14,0x01,0xF0,0x00,0x3C,0x00,0x28,0x01,0xE4,
0x01,0xA0,0x00,0x6C,0x00,0x78,0x01,0xB4,0x00,0x50,0x01,0x9C,0x01,0x88,0x00,0x44
};

WORD W_WLD_HThread::GetCRCCode(BYTE *pBuffer,int nSize)
{
BYTE *p = pBuffer;
WORD VX = 0;
for(int i = 0 ; i < nSize-2 ; i++)
{
BYTE dzl;
BYTE dzh;
BYTE VXL = (BYTE)(VX % 256);
BYTE VXH = (BYTE)(VX / 256);
dzl = ((p[i] ^ VXL) & 0x0F) * 2;
dzh = ((p[i] ^ VXL) & 0xF0) / 8;
VXL = (crc_t1[dzl] ^ crc_t2[dzh]) ^ VXH;
VXH = crc_t1[dzl + 1] ^ crc_t2[dzh + 1];
VX = VXH * 256 + VXL;
}
return VX;
}

c++ļ¼š dzl = ((p[i] ^ VXL) & 0x0F) * 2;
pacļ¼š dzl = ((p[i] bitxor VXL) bitand 0x0F) * 2;

Am I right?
Who has a subroutine, thank you!

Finished, thank you!

Did you try the built-in CRC commands in PAC Control? We have a couple different versions (checksum, CRC-16, etc.). Youā€™ll find them in the ā€œStringā€ group of commands.

1 Like

ā€™Generate Reverse CRC-16 on String is OKļ¼

The check polynomial is 107H.How can the CRC-8 algorithm be implemented in PAC?