Shop OBEX P1 Docs P2 Docs Learn Events
Prop BS2 Functions — Parallax Forums

Prop BS2 Functions

HumanoidoHumanoido Posts: 5,770
edited 2010-12-06 18:07 in Propeller 1
The BASIC Stamp can do this:
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

  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-06 10:31
    You're asking to wait for a single specific character, then accept a decimal number. If you want to wait for a string of several characters, that's more complicated.

    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.
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-12-06 18:07
    Mike - this not only answers my question but explains a lot of things including the behavior of some previous code I was working on. Is there a good source of information where we can read more about this? Thank you!
Sign In or Register to comment.