I am working on a RFID reader using the ID-20. It outputs serial data in the following format. Each [] is one ascii byte.

[STX]

[D1] [D2] [D3] [D4] [D5] [D6] [D7] [D8] [D9] [D10]

[CS1] [CS2]

[CR]

[LF]

[ETX]

The part I care about is the D1-D10, the actual data, 10 ascii charactors. CS1 and CS2 are 2 ascii charactors that are the checksum for the data. I would like to implement checking the data against the check sum but I cant seem to convert the charactors into the format I need. Here is how the data sheet says the checksum is done to the data

if the 10 digits of ascii come in and lets say they equal

2 4 0 0 C C 5 7 8 3

and the check sum is

3 C

then to get the checksum you need to take pairs of ascii and convert them into one HEX byte and then XOR the hex bytes. which would look like this.

2 4 0 0 C C 5 7 8 3

becomes

[24] [00] [CC] [57] [83]

and 3 C becomes [3C]

then you can do a simple [24] ^ [00] ^ [CC] ^ [57] ^ [83] (^ is XOR) to see if it = [3C]

The problem I am having is I dont know how to convert 10 ascii bytes into 5 pairs of 2 HEX bytes.

again... here is what I need to do (brackets [] used to illustrate seperate bytes)

ASCII [a]

[STX]

[D1] [D2] [D3] [D4] [D5] [D6] [D7] [D8] [D9] [D10]

[CS1] [CS2]

[CR]

[LF]

[ETX]

The part I care about is the D1-D10, the actual data, 10 ascii charactors. CS1 and CS2 are 2 ascii charactors that are the checksum for the data. I would like to implement checking the data against the check sum but I cant seem to convert the charactors into the format I need. Here is how the data sheet says the checksum is done to the data

if the 10 digits of ascii come in and lets say they equal

2 4 0 0 C C 5 7 8 3

and the check sum is

3 C

then to get the checksum you need to take pairs of ascii and convert them into one HEX byte and then XOR the hex bytes. which would look like this.

2 4 0 0 C C 5 7 8 3

becomes

[24] [00] [CC] [57] [83]

and 3 C becomes [3C]

then you can do a simple [24] ^ [00] ^ [CC] ^ [57] ^ [83] (^ is XOR) to see if it = [3C]

The problem I am having is I dont know how to convert 10 ascii bytes into 5 pairs of 2 HEX bytes.

again... here is what I need to do (brackets [] used to illustrate seperate bytes)

ASCII [a]

**[c] [d] [e] [f]**

HEX [ab] [cd] [ef]

Here is a piece of sample code that is not working that is attempting to do thisHEX [ab] [cd] [ef]

Here is a piece of sample code that is not working that is attempting to do this

Code: Select all

I found a link to someone who did this in assembly language but I am trying to do it on an arduino so the codes not even close. Anyone know how to do this?```
int count = 0;
for ( int i = 0; i < 10; i+=2 )
{
hex[count] = data[i]+data [i+1];
count++;
}
```

www.pcmofo.com