BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – SERIN
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 405
three bytes (elements). See the "Defining Arrays" section in Chapter 4 for
more information on arrays.
Here is an example that receives nine bytes through I/O pin 1 at 9600 bps,
N81/inverted and stores them in a 10-byte array:
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 nine bytes
DEBUG STR serStr ' display
Why store only 9 bytes in a 10-byte array? We want to reserve space for
the 0 byte that many BASIC Stamp string-handling routines regard as an
end-of-string marker. This becomes important when dealing with
variable-length arrays. For example, the STR formatter (see Table 5.101)
can accept an additional parameter telling it to end the string when a
particular byte is received, or when the specified length is reached,
whichever comes first. An example:
serStr VAR Byte(10) ' make 10-byte array
serStr(9) = 0 ' put 0 in last byte of array
SERIN 1, 16468, [STR serStr\9\"*"] ' stop at "*" or nine bytes
DEBUG STR serStr ' display
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) control character! 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")]
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
MATCHING A SEQUENCE OF CHARACTERS
WITH
WAIT.
NOTE: The rest of the code examples
for this section are written for the BS2,
using the BS2's BaudMode and
Timeout values. Be sure to adjust the
value for your BASIC Stamp.
All
2
All
2
All
2