Table 5.86: BS2, BS2e, BS2sx and
BS2p Special Formatters.
T
STR (
)
HE
STRING
FORMATTER
U
SING PARITY AND HANDLING PARITY
.
ERRORS
5: BASIC Stamp Command Reference – SEROUT
Special Formatter
?
ASC ?
STR ByteArray {\L}
REP Byte \L
The string formatter is useful for transmitting a string of characters from 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 transmits five bytes (from a byte array) through
I/O pin 1 at 9600 bps, N81/inverted:
SerString
VAR
SerString(0) = "H"
SerString(1) = "E"
SerString(2) = "L"
SerString(3) = "L"
SerString(4) = "O"
SEROUT 1, 16468, [ STR SerString\5 ]
Note that we use the optional \L argument of STR. If we didn't specify
this, the BASIC Stamp would try to keep sending characters until it found
a byte equal to 0. Since we didn't specify a last byte of 0 in the array, we
chose to tell it explicitly to only send 5 characters.
Parity is a simple error-checking feature. When the SEROUT command's
Baudmode is set for even parity it counts the number of 1s in the outgoing
byte and uses the parity bit to make that number even. For instance, if it is
Displays "symbol = x' + carriage return; where x is a number.
Default format is decimal, but may be combined with
conversion formatters (ex: BIN ? x to display "x =
binary_number").
Displays "symbol = 'x'" + carriage return; where x is an ASCII
character.
Send character string from an array. The optional \L
argument can be used to limit the output to L characters,
otherwise, characters will be sent up to the first byte equal to
0 or the end of RAM space is reached.
Send a string consisting of Byte repeated L times
(ex: REP "X"\10 sends "XXXXXXXXXX").
BYTE(5)
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 301
Action
' Make a 5-byte array.
' Send 5-byte string.
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?