Shop OBEX P1 Docs P2 Docs Learn Events
String multiple bytes into a usable string — Parallax Forums

String multiple bytes into a usable string

deanwesterburgdeanwesterburg Posts: 25
edited 2011-11-02 18:55 in BASIC Stamp
I am using code from the RFID_Basics.ZIP file on the Parallax site. They read an RFID tag by looping 10 times and reading one byte each time.

I would like to string the bytes all together into a usable string so I can evaluate the RFID number with a CASE statment.

Here is the code that loops 10 times to read the RFID tags

FOR idx = 0 TO 9 ' scan bytes in tag
#IF __No_SPRAM #THEN
SEROUT TX, LcdBaud, [buf(idx)]
#ELSE
GET idx, Char ' read char from SPRAM
SEROUT TX, LcdBaud, [Char]
#ENDIF
NEXT

Can someone help point me in the right direction on how to string each byte together?

Thanks!

Comments

  • deanwesterburgdeanwesterburg Posts: 25
    edited 2011-01-04 17:44
    Well, I found a way around this but it wastes a lot of memory

    I have setup a tree of Case statements and evaluate each of the 10 bytes. If the byte matches, it moves down the tree and goes through those case statements.

    It works, but there has got to be a better way.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-01-04 18:13
    What do you mean by "string them together"? Are you trying to match them to a set of known IDs and then ..... ?
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-01-04 20:50
    I don't recall any string handling functions. I don't think the BS handles strings at all. If you: IDTAG DATA "Some ID tag A12345XXXBC"
    It still stores and is handled in bytes.

    Can you store them to an array with a pointer? You could write a dedicated compare routine for this.

    RFID1 DATA "A",1,2,3,4,5,"XXXBC"
    IDTAG VAR Byte(6)

    ptr=RFID1
    FOR n=0 to 5
    READ ptr+n, i
    IF i <> IDTAG(n) THEN flag=0:return 'Sequence failed
    NEXT
    flag=1 'Sequence confirmed
    RETURN
  • deanwesterburgdeanwesterburg Posts: 25
    edited 2011-11-02 18:55
    Sorry for such a late reply. I have not been able to spend time with my hobbies in a while!

    Yes. I am trying to evaluate the entire ID of the tag, not just the last 2 values.
Sign In or Register to comment.