I'm trying to calculate checksum for serial communication. so I made a byte array for databuffer. I don't know how to use this byte array of databuffer to this fuction. because this function's parameter type is byte pointer. How do I use this function?
byte[] arrayForChecksum // for databuffer
// calculating a checksum for C#
public unsafe static ushort CalcCRC(byte * pDataBuffer, uint usDataLen)
{
byte nTemp;
ushort wCRCWord = 0xFFFF;
while ((usDataLen--) != 0)
{
nTemp = (byte)(wCRCWord ^*pDataBuffer++);
wCRCWord >>= 8;
wCRCWord ^= TABLE_CRCVALUE[nTemp];
}
return wCRCWord;
}
// original code in C
unsigned short CalcCRC(unsigned char* pDataBuffer, unsigned long usDataLen)
{
unsigned char nTemp;
unsigned short wCRCWord = 0xFFFF;
while (usDataLen--)
{
nTemp = wCRCWord ^ *(pDataBuffer++);
wCRCWord >>= 8;
wCRCWord ^= TABLE_CRCVALUE[nTemp];
}
return wCRCWord;
}