Prop BS2 Functions
Humanoido
Posts: 5,770
The BASIC Stamp can do this:
What is the same code syntax using the Basic Stamp 2 library "BS2_Functions"
on the Propeller chip? I'm trying to get the prop to wait for a special character
sent from the Stamp. Thanks in advance.
sData VAR Byte Main: SERIN 1, 16780, [WAIT("XYZ"), DEC sData] END 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 sData variable would end up with the number 100 after the [B]SERIN[/B] line finishes. If the device sent some data other than "XYZ" followed by a number, the BASIC Stamp would continue to wait at the [B]SERIN[/B] command.
What is the same code syntax using the Basic Stamp 2 library "BS2_Functions"
on the Propeller chip? I'm trying to get the prop to wait for a special character
sent from the Stamp. Thanks in advance.
bs : "BS2_Functions" number := BS.serin_char(rx, baudRate, polarity, bits)
Comments
repeat until BS.serin_char(rx, baudRate, polarity, bits) == desiredCharacter
number := BS.serin_dec(rx, baudRate, polarity, bits)
Note that .serin_dec expects a carriage return at the end of the number. You would need to modify the .serin_dec routine if you want it to act differently. .serin_dec stores the received characters in a buffer up to the carriage return, then converts the saved string to a number.