[RESOLVED] CRC calculation implementation HELL..
So now i can comms with the device, however the CRC calculation does not work correctly... (I have 0 access to the Firmware) but the suppliers graciously gave us the CRC calculation in C++, which is as such
Now my VB implementation
static unsigned BitsSet (unsigned char ch)
n = 0;
n += (ch & 1);
ch >>= 1;
unsigned CRCof (const char *message, unsigned len)
unsigned char k;
crc = 0;
for (i=0; i<len; i++)
k = (unsigned char)(message[i]) ^ crc;
crc = (crc / 256) ^ (k*128) ^ (k*64);
if ((BitsSet(k) & 1) != 0)
crc ^= 0xC001;
Now no matter what i send to the device it always reply's with CRC error "GL!ER20A624" (the last 4 digits are the modules calculated CRC)... And if i send the module some Garbage i get a Invalid request "GL!ER2166E5"..
Friend Function CRC(ByVal ParamArray Msg As Byte()) As Byte() 'CRC is 2 byte length
Dim Result As UInt16 = 0
Dim tmpB As Byte = 0
Dim tmpint As Integer
For tmpint = 0 To Msg.Length - 1
tmpB = Msg(tmpint) Xor Result And &HFF
Result = (Result \ 256) Xor (tmpB * 128) Xor (tmpB * 64)
If ((BitsSet(tmpUint) And 1) <> 0) Then
Result = Result Xor &HC001
CRC = ToByteArray(Result)
Friend Function BitsSet(ByVal data As UInt32) As Byte
BitsSet = 0
BitsSet += (data And 1)
data >>= 1
now using my code i'm trying to replicate the CRC, with 0 luck ....
What have i converted incorrectly ???? I just cant see it.....
Re: CRC calculation implementation HELL..
True's nuts... Post about it and all of a sardine you fix it, never mind you've spent day's on it...
Still not 100% sure what was wrong, but i tidied up the code to post it here, and when i put it back into the app from here, it worked...
Must have been a typo somewhere, that i missed but accidentally fixed when making it tidy to post...
Regardless.. it works now \o/ \o/ \o/ ....