SERIN WAITSTR question.....
Catspaw
Posts: 49
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.
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
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.
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!