Specifications

BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 315
2
badData. Note that a parity error takes precedence over other inputData
specifications; as soon as an error is detected, Serin aborts and goes to
the plabel routine.
Setting a Serial Timeout
In the examples above, the only way to end the Serin instruction (other
than RESET or power-off) is to give Serin the serial data it wants. If no
serial data arrives, the program is stuck. However, you can tell the BS2
to abort Serin if it doesn’t receive data within a specified number of
milliseconds. For instance, to receive a decimal number through pin 1
at 2400 baud, 8N, inverted and abort Serin after 2 seconds (2000 ms) if
no data arrives:
serin 1,16780,2000,noData,[DEC w1]
debug cls, ? w1
stop
noData:
debug cls, "timed out"
If no data arrives within 2 seconds, the program aborts Serin and con-
tinues at the label noData. This timeout feature is not picky about the
kind of data Serin receives; any serial data stops the timeout. In the
example above, Serin wants a decimal number. But even if Serin re-
ceived letters “ABCD...” at intervals of less than two seconds, it would
not abort.
Combining Parity and Timeout
You can combine parity and serial timeouts. Here is an example de-
signed to receive a decimal number through pin 1 at 2400 baud, 7E,
inverted with a 10-second timeout:
again:
serin 1,24972,badData,10000,noData,[DEC w1]
debug cls, ? w1
goto again
noData:
debug cls, "timed out"
goto again