5: BASIC Stamp Command Reference – SERIN
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 281
available for the SERIN command. If not using a BS1, see the “Additional
Conversion Formatters” section below for more information.
The SERIN command can also be configured to wait for specified data
before it retrieves any additional input. For example, suppose a device
that is attached to the BASIC Stamp is known to send many different
sequences of data, but the only data you desire happens to appear right
after the unique characters, “XYZ”. The BS1 has optional Qualifier
arguments for this purpose. On the BS2, BS2e, BS2sx and BS2p a special
formatter called WAIT can be used for this.
Symbol SerData = B0
SERIN 1, N2400, ("XYZ"), #SerData
--or--
SerData VAR BYTE
SERIN 1, 16780, [WAIT("XYZ"), DEC SerData]
The above code waits for the characters “X”, “Y” and “Z” to be received,
in that order, and then it looks for a decimal number to follow. If the
device in this example were to send the characters “XYZ100” followed by
a carriage return or some other non-decimal numeric character, the
SerData variable would end up with the number 100 after the SERIN line
finishes. If the device sent some data other than “XYZ” followed by a
number, the BASIC Stamp would continue to wait at the SERIN
command.
The BS1 will accept an unlimited number of Qualifiers. The BS2, BS2e,
BS2sx and BS2p will only accept up to six bytes (characters) in the WAIT
formatter.
Keep in mind that when we type “XYZ” into the SERIN command, the
BASIC Stamp actually uses the ASCII codes for each of those characters for
its tasks. We could also have typed: 88, 89, 90 in place of “XYZ” and the
code would run the same way since 88 is the ASCII code for the “X”
character, 89 is the ASCII code for the “Y” character, and so on. Also note,
serial communication with the BASIC Stamp is case sensitive. If the device
mentioned above sent, “xYZ” or “xyZ”, or some other combination of
lower and upper-case characters, the BASIC Stamp would have ignored it
because we told it to look for “XYZ” (all capital letters).
U
SING
SERIN
TO WAIT FOR SPECIFIC
DATA BEFORE PROCESSING
.
U
SING
ASCII
CODES AND CASE
SENSITIVITY
.
1
2
e
2
sx
2
p
2
T
HIS IS WRITTEN WITH THE
BS2'
S
B
AUD
M
ODE VALUE
. B
E SURE TO
ADJUST THE VALUE FOR YOUR
BASIC
S
TAMP
.
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...