Main Site Documentation

CRC + A coding question


#1

Hi guys,

First of all, how do you work the CRC method supplied by GHI?

I’m trying the following:

                ushort seed = 0xFFFF;

                seed = CRC.CRC_16_CCITT(packet[], offset, z, seed);

with packet[] being a byte[] and offset, z being integers, yet I am told that

“The best overloaded match for… has some invalid arguments”

What am I doing wrong?

I could implement CRC myself, but I have a feeling it’d be too slow.

Second of all, I’m using certain bytes to encode data into a bit balanced format. Is there a neater way of doing this than the following?

for (; z < chars.Length; z++) 
            { 
                switch (chars[z])
                {
                    case '0':
                        packet[i++] = 0xA6;
                        break;
                    case '1':
                        packet[i++] = 0x65;
                        break;
                    case '2':
                        packet[i++] = 0x59;
                        break;
                    case '3':
                        packet[i++] = 0x56;
                        break;
                    case '4':
                        packet[i++] = 0xCC;
                        break;
                    case '5':
                        packet[i++] = 0x4D;
                        break;
                    case '6':
                        packet[i++] = 0xD4;
                        break;
                    case '7':
                        packet[i++] = 0xCD;
                        break;
                    case '8':
                        packet[i++] = 0xCE;
                        break;
                    case '9':
                        packet[i++] = 0xDC;
                        break;
                    case 'A':
                        packet[i++] = 0xEC;
                        break;
                    case 'B':
                        packet[i++] = 0x33;
                        break;
                    case 'C':
                        packet[i++] = 0x73;
                        break;
                    case 'D':
                        packet[i++] = 0x3B;
                        break;
                    case 'E':
                        packet[i++] = 0x37;
                        break;
                    case 'F':
                        packet[i++] = 0xB3;
                        break;
                    case 'G':
                        packet[i++] = 0x72;
                        break;
                    case 'H':
                        packet[i++] = 0x6C;
                        break;
                    default:
                        packet[i++] = 0x00;
                        break;
                }

Thanks for any advice.


#2

Okay I’ve written my own CRC code, so I guess that solves my CRC issue.


#3

Use a latch gate chip


#4

Thanks - I deleted my question, because it has all of the sudden started latching by itself. I must have been doing something wrong before :).

Oh - What’s the WritePin and ReadPin for on the Parallel port? I just assigned it to a random pin…


#5

Xarren,

On your original question… I think your code should be like this:

seed = CRC.CRC_16_CCITT(packet, offset, z, seed);

Notice that I removed the brackets from the “packet” parameter.


#6

Oh jeeze, of course. That was stupid of me. Thanks Jasdev.