SERIN - BASIC Stamp Command Reference
Page 284
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
Special Formatter
Action
STR ByteArray \L {\E}
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 (Value)
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.
WAITSTR ByteArray {\L}
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).
SKIP Length
Ignore Length bytes of characters.
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) ' Make a 10-byte array.
SerString(9) = 0 ' Put 0 in last byte.
SERIN 1, 16468, [STR SerString\9] ' Get 9-byte string.
DEBUG STR SerString ' Display the string.
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) ' Make a 10-byte array.
SerString(9) = 0 ' Put 0 in last byte.
SERIN 1, 16468, [STR SerString\9\"*"] ' Stop at "*" or 9 bytes.
DEBUG STR SerString ' Display the string.
Table 5.77: BS2, BS2e, BS2sx and
BS2p Special Formatters.
T
HE
STR (
STRING
)
FORMATTER
.
2
e
2
sx
2
p
2
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
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...