M
ATCHING A SEQUENCE OF
WAIT.
CHARACTERS WITH
2
2
e
M
ATCHING A SEQUENCE OF
WAITSTR.
CHARACTERS WITH
2
2
e
5: BASIC Stamp Command Reference – SERIN
If the serial input were "hello*" DEBUG would display "hello" since it
collects bytes up to (but not including) the end character. It fills the unused
bytes up to the specified length with 0s. DEBUG's normal STR formatter
understands a 0 to mean end-of-string. However, if you use DEBUG's
fixed-length string modifier, STR ByteArray\L, you will inadvertently clear
the DEBUG screen. The fixed-length specification forces DEBUG to read
and process the 0s at the end of the string, and 0 is equivalent to DEBUG's
CLS (clear-screen) instruction! Be alert for the consequences of mixing
fixed- and variable-length string operations.
As shown before, SERIN can compare incoming data with a predefined
sequence of bytes using the WAIT formatter. The simplest form waits for a
sequence of up to six bytes specified as part of the InputData list, like so:
2
2
SERIN 1, 16468, [WAIT ("SESAME")]
p
sx
DEBUG "Password accepted"
SERIN will wait for that word, and the program will not continue until it
is received. Since WAIT is looking for an exact match for a sequence of
bytes, it is case-sensitive—"sesame" or "SESAmE" or any other variation
from "SESAME" would be ignored.
SERIN can also wait for a sequence that matches a string stored in an array
variable with the WAITSTR formatter. In the example below, we'll capture
a string with STR then have WAITSTR look for an exact match:
2
2
SerString
VAR
sx
p
SerString(9) = 0
SERIN 1, 16468, [STR SerString\9\"!"]
DEBUG "Waiting for: ", STR SerString, CR
SERIN 1, 16468, [WAITSTR SerString]
DEBUG "Password accepted!", CR
You can also use WAITSTR with fixed-length strings as in the following
example:
BYTE(10)
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 285
'Wait for word SESAME.
' Make a 10-byte array.
' Put 0 in last byte.
' Get the string
'Wait for a match
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?