BASIC stamp manual v2.2
SERIN - BASIC Stamp Command Reference
Page 406 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com
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:
serStr VAR Byte(10) ' make 10-byte array
serStr(9) = 0 ' put 0 in last byte of array
SERIN 1, 16468, [STR serStr\9\"!"] ' get the string
DEBUG "Waiting for:", STR serStr, CR
SERIN 1, 16468, [WAITSTR serStr] ' wait for match
DEBUG "Password accepted."
You can also use WAITSTR with fixed-length strings as in the following
example:
serStr VAR Byte(4) ' make 4-byte array
DEBUG "Enter 4-character password"
SERIN 1, 16468, [STR serStr\4] ' get the string
DEBUG "Waiting for:", STR serStr\4, CR
SERIN 1, 16468, [WAITSTR serStr\4] ' wait for match
DEBUG "Password accepted."
SERIN’s InputData can be structured as a sophisticated list of actions to
perform on the incoming data. This allows you to process incoming data
in powerful ways. For example, suppose you have a serial stream that
contains “pos: xxxx yyyy” (where xxxx and yyyy are 4-digit numbers) and
you want to capture just the decimal y value. The following code would
do the trick:
yOffset VAR Word
SERIN 1, 16468, [WAIT("pos: "), SKIP 4, DEC4 yOffset]
DEBUG ? yOffset
The items of the InputData list work together to locate the label “pos: ”,
skip over the four-byte x data, then convert and capture the decimal y
data. This sequence assumes that the x data is always four digits long; if its
length varies, the following code would be more appropriate:
yOffset VAR Word
SERIN 1, 16468, [WAIT("pos: "), DEC yOffset, DEC4 yOffset]
DEBUG ? yOffset
M
ATCHING A SEQUENCE OF CHARACTERS
WITH WAITSTR.
B
UILDING COMPOUND INPUTDATA
STATEMENTS
.
All
2
All
2
All
2
All
2