BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – SERIN
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 399
The SERIN command provides a formatter, called the decimal formatter,
which will interpret this for us. Look at the following code:
SYMBOL serData = B2
SERIN 1, N2400, #serData
-- or --
serData VAR Byte
SERIN 1, 16780, [DEC serData]
Notice the decimal formatter in the SERIN command. It is the “#” (for the
BS1) or “DEC” (for all BS2 models) that appears just to the left of the
serData variable. This tells SERIN to convert incoming text representing
decimal numbers into true-decimal form and store the result in serData. If
the user running the terminal software pressed the "1", "2" and then "3"
keys followed by a space or other non-numeric text, the value 123 will be
stored in serData. Afterwards, the program can perform any numeric
operation on the number just like with any other number. Without the
decimal formatter, however, you would have been forced to receive each
character (“1”, “2” and “3”) separately, and then would still have to do
some manual conversion to arrive at the number 123 (one hundred twenty
three) before you can do the desired calculations on it.
The decimal formatter is designed to seek out text that represents decimal
numbers. The characters that represent decimal numbers are the
characters “0” through “9”. Once the SERIN command is asked to use the
decimal formatter for a particular variable, it monitors the incoming serial
data, looking for the first decimal character. Once it finds the first decimal
character, it will continue looking for more (accumulating the entire multi-
digit number) until is finds a non-decimal numeric character. Keep in
mind that it will not finish until it finds at least one decimal character
followed by at least one non-decimal character.
To further illustrate this, consider the following examples (assuming we’re
using the same code example as above):
1) Serial input: ABC
Result: The BASIC Stamp halts at the SERIN command,
continuously waiting for decimal text.
DECIMAL FORMATTER SPECIFICS.
Note: This is written with the BS2's
Baudmode value. Be sure to adjust the
value for your BASIC Stamp.
1
All
2