I've searched the forum on this, plus the net, and not quite finding the answer i want.
A company i deal with is investing in a data acquisition system that requires data to be sent with a calculated checksum, or the data is ignored. Sounds like a pretty smart way to maintain data integrity. This would be a valuable tool also for Picaxe to Picaxe data communication, whether it be by wire or by the Radio modules ( eg Hope HM- TR or Xbee) that are becoming more and more accessible.
In the short term i'd like to send my own data from Picaxe to this data acquisition system.
I have been very sucessfully using the serout command to export data to computers and basic serial logging software (eg Eltima RS232 Data logger) and hyperterminal via RS232.
This computer company, http://www.trisol.com.au/ are saying that the way to send the data is as follows:
<MID>,<PID>,<Value>,<PID>,<Value>,<PID>,<Value>,<PID>,<Value>,CRC<CR><LF>
Where MID = Message ID, PID = Parameter ID and Value is value, all in ascii characters.
I can handle the message ID, Parameter Identifier and value OK with plain characters, text in invered commas, BintoAscii and then Serout. But now the Checksum CRC.
CRC = ASCII representation of exclusive-or (XOR) sum of all characters from MID(inclusive) to the last value (excluding CRC, <CR> and <LF>).
This Checksum system is apparently also used for data which comes from a Garmin GPS antenna..
The receiving computer also calculates the checksum on the incoming data, and if the checksums match, then it accepts the data. Sounds simple.
Picaxe can do XOR, represented by ^. I understand what it is, but not how the maths works. The only thing i can think of is something like:
b1 = b2^b3^b4^b5^ etc
bintoascii b1,b9,b10,b11
Serout 1, T1200, (b2,b3,b4,b5,......b9,b10,b11,13,10)
This code runs on the simulator OK.
b1 = b2^b3^b4^b5
bintoascii b1,b9,b10,b11
Serout 1, T1200, (b2,b3,b4,b5,b9,b10,b11,13,10)
But, i would be using up a lot of variables and i have no way of knowing if i was generating the right number anyway. There must be a better way.
This idea of generating a checksum and then testing for it seems like such a good idea that you would think that it would have been done in picaxe world before. But I can't find where or how. The guy from Trilogy is off on holidays now, so i can't quiz further, till January, but he can't tell me Picaxe code anyway.
Any ideas on using a XOR sum of all characters as described to generate a checksum?
A company i deal with is investing in a data acquisition system that requires data to be sent with a calculated checksum, or the data is ignored. Sounds like a pretty smart way to maintain data integrity. This would be a valuable tool also for Picaxe to Picaxe data communication, whether it be by wire or by the Radio modules ( eg Hope HM- TR or Xbee) that are becoming more and more accessible.
In the short term i'd like to send my own data from Picaxe to this data acquisition system.
I have been very sucessfully using the serout command to export data to computers and basic serial logging software (eg Eltima RS232 Data logger) and hyperterminal via RS232.
This computer company, http://www.trisol.com.au/ are saying that the way to send the data is as follows:
<MID>,<PID>,<Value>,<PID>,<Value>,<PID>,<Value>,<PID>,<Value>,CRC<CR><LF>
Where MID = Message ID, PID = Parameter ID and Value is value, all in ascii characters.
I can handle the message ID, Parameter Identifier and value OK with plain characters, text in invered commas, BintoAscii and then Serout. But now the Checksum CRC.
CRC = ASCII representation of exclusive-or (XOR) sum of all characters from MID(inclusive) to the last value (excluding CRC, <CR> and <LF>).
This Checksum system is apparently also used for data which comes from a Garmin GPS antenna..
The receiving computer also calculates the checksum on the incoming data, and if the checksums match, then it accepts the data. Sounds simple.
Picaxe can do XOR, represented by ^. I understand what it is, but not how the maths works. The only thing i can think of is something like:
b1 = b2^b3^b4^b5^ etc
bintoascii b1,b9,b10,b11
Serout 1, T1200, (b2,b3,b4,b5,......b9,b10,b11,13,10)
This code runs on the simulator OK.
b1 = b2^b3^b4^b5
bintoascii b1,b9,b10,b11
Serout 1, T1200, (b2,b3,b4,b5,b9,b10,b11,13,10)
But, i would be using up a lot of variables and i have no way of knowing if i was generating the right number anyway. There must be a better way.
This idea of generating a checksum and then testing for it seems like such a good idea that you would think that it would have been done in picaxe world before. But I can't find where or how. The guy from Trilogy is off on holidays now, so i can't quiz further, till January, but he can't tell me Picaxe code anyway.
Any ideas on using a XOR sum of all characters as described to generate a checksum?