Parallax BASIC Stamp 2e Programming Manual page 288

Table of Contents

Advertisement

SERIN - BASIC Stamp Command Reference
SerString
VAR
BYTE(4)
DEBUG "Enter a 4 character password", CR
SERIN 1, 16468, [STR SerString\4]
DEBUG "Waiting for: ", STR SerString\4, CR
SERIN 1, 16468, [WAITSTR SerString\4]
DEBUG "Password accepted!", CR
SERIN's InputData can be structured as a sophisticated list of actions to
perform on the incoming data. This allows you to process incoming data
in powerful ways. For example, suppose you have a serial stream that
contains "pos: xxxx yyyy" (where xxxx and yyyy are 4-digit numbers) and
you want to capture just the decimal y value. The following code would
do the trick:
YOffset
VAR
WORD
SERIN 1, 16468, [WAIT ("pos: "), SKIP 4, DEC yOffset]
DEBUG ? yOffset
The items of the InputData list work together to locate the label "pos: ",
skip over the four-byte x data, then convert and capture the decimal y
data. This sequence assumes that the x data is always four digits long; if its
length varies, the following code would be more appropriate:
YOffset
VAR
WORD
SERIN 1, 16468, [WAIT ("pos: "), DEC yOffset, DEC yOffset]
DEBUG ? yOffset
The unwanted x data is stored in yOffset then replaced by the desired y
data. This is a sneaky way to filter out a number of any size without using
an extra variable. With a little creativity, you can combine the InputData
modifiers to filter and extract almost any data.
Parity is a simple error-checking feature. When a serial sender is set for
even parity (the mode the BASIC Stamps support) it counts the number of
1s in an outgoing byte and uses the parity bit to make that number even.
For instance, if it is sending the 7-bit value: %0011010, it sets the parity bit
to 1 in order to make an even number of 1s (four).
The receiver also counts the data bits to calculate what the parity bit
should be. If it matches the parity bit received, the serial receiver assumes
that the data was received correctly. Of course, this is not necessarily true,
since two incorrectly received bits could make parity seem correct when
Page 286 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
' Make a 4-byte array.
' Get the string
'Wait for a match
2
2
2
2
e
sx
p
B
I
UILDING COMPOUND
NPUT
.
STATEMENTS
2
2
2
2
e
sx
p
2
2
2
2
e
p
sx
U
SING PARITY AND HANDLING PARITY
.
ERRORS
D
ATA

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?

Table of Contents