PDA

View Full Version : ?? - = - easy way to compare a byte array with a text string - = - ??



r3b0
04-26-2007, 04:17 AM
i have a 17 character string stored in aˇ byte array. i need a way to easily compare it to a list of character strings. to my knowledge, there is'nt an easy way to do this. i thought maybe serout it on one pin and then serin it back into an array and do a for next loop to match all the characters, but then i started wondering about timing and the fact it would take 2 i/o's to do. as you can see in the code below, it's not very accurate. i only check one character out of 12 to see who it is. I would like to make the unit self contained and not have to have a pc to check the id's.

anyone got any ideas?

i need to find out if bBuffer() is equal to a list ofˇid's formattedˇlike so, xx:xx:xx:xx:xx:xx, then if it is, make a pin go high for a moment.



GetVisible:
'get visable id's and send them to the serialport
SEROUT 1,84,["lst visible 10",CR]
SEROUT serialport,baud,["List Visible...",CR]
SERIN 0,84,[WAIT("ACK",CR)]
'SEROUT serialport,baud,["ACK",CR]
GetList:
'Buffer eb500 response
SERIN 0,84,[STR bBuffer\16\">"]
SEROUT serialport,baud,["Start data buffer...",CR]
SEROUT SerialPort,Baud,[STR bBuffer]
'SERIN SerialPort,Baud,[ControlCode] 'Watch for controlcode from pc. OPEN
'SEROUT SerialPort,Baud,[STR ControlCode,CR]
IF bBuffer(0) = "E" THEN ErrorCode 'Watch for Error codes
IF bBuffer(0) = 0 THEN GetVisible 'Watch for end of list VIA blank buffer
' *****************************
' FOR TESTING ONLY, NOT SECURE!
' *****************************
IF bBuffer(15) = "2" THEN SEROUT serialport,baud,["OPEN DOOR FOR - CLARK!",CR]: HIGH 7
IF bBuffer(15) = "A" THEN SEROUT serialport,baud,["OPEN DOOR FOR - BEN!",CR]: HIGH 7
IF bBuffer(15) = "3" THEN SEROUT serialport,baud,["OPEN DOOR FOR - CHRIS!",CR]: HIGH 7
IF bBuffer(15) = "C" THEN SEROUT serialport,baud,["OPEN DOOR FOR - OLD POCKET PC!",CR]: HIGH 7
IF bBuffer(15) = "8" THEN SEROUT serialport,baud,["OPEN DOOR FOR - SCOTT!",CR]: HIGH 7
IF bBuffer(15) = "F" THEN SEROUT serialport,baud,["OPEN DOOR FOR - BRYAN!",CR]: HIGH 7
IF bBuffer(15) = "C" THEN SEROUT serialport,baud,["OPEN DOOR FOR - JOHNATHAN THE NEW GUY!",CR]: HIGH 7
' *****************************
LOW 7

GOTO GetList

Chris Savage
04-26-2007, 11:21 PM
Hello,

You cannot SEROUT one pin and SERIN another. The BASIC Stamp doesn’t have a UART/FIFO and so while the data was being sent it would not be picked up at the receiving pin. What you’re trying to do is actually quite easy and an example can be found in our RFID.BS2 sample code. Typically on a BS2 the tag is read into an array and compared with a list of known tags. You can find this code on the following web page. Take care.

http://www.parallax.com/detail.asp?product_id=28140

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support

r3b0
04-27-2007, 12:26 AM
that helps alot!

just one thing though. i'm not sure i follow how to store the code list into the eeprom. can you shed a little more light on that?

Chris Savage
04-27-2007, 01:43 AM
That really depends on whether you want it stored at compile time or at run time. If at compile time refer to the example where the information is stored in DATA statements. If at run time then you will need to use WRITE to store the information and READ to get it back. You will need to keep track of your place in the EEPROM with an index variable as well. Take care.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support