5: BASIC Stamp Command Reference – SERIN
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 285
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:
SERIN 1, 16468, [WAIT ("SESAME")] 'Wait for word SESAME.
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:
SerString VAR BYTE(10) ' Make a 10-byte array.
SerString(9) = 0 ' Put 0 in last byte.
SERIN 1, 16468, [STR SerString\9\"!"] ' Get the string
DEBUG "Waiting for: ", STR SerString, CR
SERIN 1, 16468, [WAITSTR SerString] 'Wait for a match
DEBUG "Password accepted!", CR
You can also use WAITSTR with fixed-length strings as in the following
example:
M
ATCHING A SEQUENCE OF
CHARACTERS WITH
WAIT.
M
ATCHING A SEQUENCE OF
CHARACTERS WITH
WAITSTR.
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...