BASIC stamp manual v2.2
SERIN - BASIC Stamp Command Reference
Page 408 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com
Bad_Data. 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).
In all 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
BASIC Stamp to abort SERIN if it doesn’t receive a byte within a specified
number of milliseconds. For instance, to receive a decimal number
through pin 1 at 9600 baud, 8N, inverted and abort SERIN after 2 seconds
(2000 ms) of inactivity on the serial input:
result VAR Word
Main:
SERIN 1, 16468, 2000, No_Data, [DEC result]
DEBUG CLS, ? result
STOP
No_Data:
DEBUG CLS, "Timeout error"
STOP
If no data arrives within 2 seconds, the program aborts SERIN and
continues at the label No_Data. Note that on multi-byte input, the timeout
timer is reset after the receipt of any valid data byte; with long timeout
values this factor could have an adverse affect on program operation if
data packets are transmitted with gaps between individual data bytes.
Finally, be cautious when using very short timeout values. Without
external flow control, very short timeout values may cause the program to
branch to the Tlabel address unnecessarily.
Here's a very important concept: this timeout feature is not picky about
the kind of data SERIN receives; if any serial data is received, it prevents
the timeout. In the example above, SERIN wants a decimal number. But
even if SERIN received letters “ABCD...” at intervals of less than two
seconds, it would never abort.
You can combine parity and serial timeouts. Here is an example for the
BS2 designed to receive a decimal number through pin 1 at 9600 baud, 7E,
inverted with a 10-second timeout:
U
SING THE SERIAL TIME-OUT FEATURE.
R
EMEMBER: TIMEOUT DOES NOT CARE
WHAT KIND OF DATA IS RECEIVED
, ONLY
THAT DATA IS RECEIVED OR NOT
!
C
OMBINING PARITY AND TIME-OUT.
All
2