Shop OBEX P1 Docs P2 Docs Learn Events
SERIN WAITSTR question..... — Parallax Forums

SERIN WAITSTR question.....

CatspawCatspaw Posts: 49
edited 2012-01-16 08:40 in BASIC Stamp
I don't quite understand the help in the editor on this subject. What I'm trying to learn is how to wait for a specific string (but not accept any other data.) When the correct string is received, then I'll transmit something.

Basically to stay in keeping with the help example, serin should wait for the string "XXXX", then go send....something.

Here's what HELP says:

serStr VAR Byte(4) ' Make a 4-byte array

Main:
DEBUG "Enter a 4-character password", CR

SERIN 1, 16468, [STR serStr\4] ' Get the string

DEBUG "Waiting for: ", STR serStr\4, CR

SERIN 1, 16468, [WAITSTR serStr\4] ' Wait for a match

DEBUG "Password accepted!", CR

END

It appears to me that the second SERIN statment is comparing serStr to serStr...which in my mind means that as soon as any comparison is made it will be TRUE.

Shouldn't it be more like:

serString VAR Byte(4) 'String to make the comparison to and put X's in cells 0,1,2,3
...
...
serString(4) = 0 ' Put a zero in the last cell
serStr VAR Byte(4) 'Use this string array to put your received bytes into

Main:
DEBUG "Enter a 4-character password", CR 'Which in my example would be XXXX

SERIN 1, 16468, [STR serStr\4] ' Get the string

DEBUG "Waiting for: ", STR serStr\4, CR

SERIN 1, 16468, [WAITSTR serString\4] ' Compare the received string of serStr to the established serString

DEBUG "Password accepted!", CR

END

For your response....I thank you and my cats thank you.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-01-13 15:01
    Catspaw wrote: »
    I don't quite understand the help in the editor on this subject. It appears to me that the second SERIN statment is comparing serStr to serStr...which in my mind means that as soon as any comparison is made it will be TRUE.

    That's not how this works...the first SERIN is getting the characters which will be the password and storing them into the array. The second SERIN is waiting for data to come in equivalent to the data in the array, but as it tests each character as soon as a failed character is typed in it will reset what it is waiting for. So not just any string will match. You will need the exact string you typed in the first time before the second SERIN can terminate and the program can continue.
  • CatspawCatspaw Posts: 49
    edited 2012-01-13 16:07
    OOooohhh kay. We're talking about two different operations here.

    So you could just hard code the password and forget the first SERIN.

    And the second SERIN then answers my real question about just wanting to wait for a string, but, not taking any data along with it. (get the stamp's attention without passing data.)

    I didn't know if you could just use the WAIT without having the data parameter after it.

    Thanks!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-01-16 08:40
    Yes, the password could be 'hard-coded' as you say. Or it could have been stored from another part of the program into EEPROM, battery backed RAM (from a DS1302 or similar) or even DATA statements. Any data like this could be compared to what is coming into the SERIN statement. Now that method isn't necessarily the best way to accept a password serially, but it does work. The downside is the user sees no feedback and any mistakes means starting over again.
Sign In or Register to comment.