SERIN - BASIC Stamp Command Reference
Special Formatter
STR ByteArray \L {\E}
WAIT (Value)
WAITSTR ByteArray {\L}
SKIP Length
The string formatter is useful for receiving a string of characters into a byte
array variable.
A string of characters is a set of characters that are
arranged or accessed in a certain order. The characters "ABC" could be
stored in a string with the "A" first, followed by the "B" and then followed
by the "C." A byte array is a similar concept to a string; it contains data
that is arranged in a certain order. Each of the elements in an array is the
same size. The string "ABC" could be stored in a byte array containing
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:
SerString
VAR
BYTE(10)
SerString(9) = 0
SERIN 1, 16468, [STR SerString\9]
DEBUG STR SerString
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.77) 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:
SerString
VAR
BYTE(10)
SerString(9) = 0
SERIN 1, 16468, [STR SerString\9\"*"]
DEBUG STR SerString
Page 284 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
Input a character string of length L into an array. If specified, an
end character E causes the string input to end before reaching
length L. Remaining bytes are filled with 0s (zeros).
Wait for a sequence of bytes specified by value. Value can be
numbers separated by commas or quoted text (ex: 65, 66, 67 or
"ABC"). The WAIT formatter is limited to a maximum of six
characters.
Wait for a sequence of bytes matching a string stored in an array
variable, optionally limited to L characters. If the optional L
argument is left off, the end of the array-string must be marked
by a byte containing a zero (0).
Ignore Length bytes of characters.
' Make a 10-byte array.
' Put 0 in last byte.
' Get 9-byte string.
' Display the string.
' Make a 10-byte array.
' Put 0 in last byte.
' Stop at "*" or 9 bytes.
' Display the string.
Action
Table 5.77: BS2, BS2e, BS2sx and
BS2p Special Formatters.
T
STR (
)
HE
STRING
FORMATTER
2
2
2
2
e
p
sx
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.
2
2
2
2
e
p
sx
.
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?