Help with comparing bytes in an array with buffer
Don M
Posts: 1,652
I am playing around with the RFID reader and an EMIC board. I have some tags and I want to do a compare with a list of tags then it will speak the appropriate name for the tag.
Here' my compare logic for just one tag. No matter what tag I scan it always seems to be true:
What am I doing wrong here?
Thanks.
Don
Here' my compare logic for just one tag. No matter what tag I scan it always seems to be true:
PUB CheckBusTag repeat i from 0 to 11 'Compare tag's 10 unique ID #s against ID #s stored in data table if byte[@RFIDdata[i]] == byte[@Tag1[i]] serial.TX("S") serial.Str(@BusTag1) ' Send the desired string to convert to speech (stored in the DAT section below) serial.TX(pst#NL) repeat until serial.RxCheck == ":" ' Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command return DAT Tag1 byte 10, 65, 48, 48, 48, 48, 68, 66, 66, 56, 48, 13 '<-- Enter your own RFID tag ID numbers here Tag2 byte 10, 48, 70, 48, 50, 65, 54, 55, 48, 69, 48, 13 BusTag1 byte "Good Morning Amy Lee. Thank you for scanning your tag", 0 BusTag2 byte "Good Morning Janelle. Thank you for scanning your tag", 0 BusTag3 byte "Good Morning Trevin. Thank you for scanning your tag", 0
What am I doing wrong here?
Thanks.
Don
Comments
It looks like you're only checking a single byte before taking action. You really need to run through all the bytes in question before deciding if there's a match or not.
Here's my take:
BusTag3 will never be read since there are only two serial numbers.
I have some RFID code you might want to look at. Here's a link.
What I tried next was to just append a "0" to the end of the data read into RFIDdata buffer and also added a "0" to end of tags in DAT section and tried a strcomp. That seems to work too.
I wondered about using strcomp but then you can't have a zero as one of your data bytes.
Make sure and test out the method "FindString". I find it extremely useful when wanting to display text based on some index number.
Where do I find this method?
It's included in the code posted in post #2.