An update: I know how I need to work with the reader, I just don't know how to code it in Basic.
Mike has been a source of great help but I still am struggling to learn the subtleties of this language.
A brief text version of how it is supposed to work; The reader sends 5 bytes when it 'sees' a tag. The bytes are in hex. Bytes 1-4 are the tag's unique number and the 5th byte is the checksum. Checksum is generated by taking the 4 bytes of payload and successively XORing them such as byte1 XOR byte2 XOR byte3 XOR byte4 = checksum
So, I can provide some pseudo-code for what I need to do:
1. receive serial packet of 5 bytes into an array length of 5 bytes called 'DATA'
2. Variable CHKSUM=5th byte of DATA
3. Variable TEMPCHK=DATA(1) XOR DATA(2) XOR DATA(3) XOR DATA(4) - number in () is byte in array
4. If TEMPCHK <> CHKSUM then print "Bad Packet, else print "Good Packet"
5. Variable TAG = hextoint (mid(data,1,4)
An example using real numbers from a serial eavesdrop on the serial line-
00 82 6A 25 CD
00 XOR 82 XOR 6A XOR 25 = CD
00 82 6A 25 hex to dec is 0008546853 which is written on the tag which confirms what I need to accomplish.
Things I haven't been able to find out-
1. I don't see how to create an array with a specified length, eg DATA(5) meaning array DATA has 5 elements.
2. How to equate a variable as a specific element in the array such as variable CHKSUM=DATA(5)
3. Don't know if basic assumes the serial string is decimal or hex, need to specify hex
I think the serial branch is working, but I cannot get it to print correctly.
I am still fuzzy on variables as it relates to this version of basic and my experience in variables, arrays, bits, bytes, and words and how to get to any one of these does not help with this basic so apologies if this is written somewhere, just point me to it. I am still learning.........
For example in Picbasic Pro ( my native language):
to define a variable 'DATA' as an array of 5 byes is:
DATA var byte(5)
to define a variable 'CHKSUM' as element 5 in data array 'DATA' is:
CHKSUM var DATA(5)
Just looking for clarification and thanks again to all who are trying to help - especially Mike.
Regards to All,
Steve
- Albert Einstein