Shop OBEX P1 Docs P2 Docs Learn Events
Newbie question about Serin and loops — Parallax Forums

Newbie question about Serin and loops

NewJerseyTNNewJerseyTN Posts: 14
edited 2007-04-03 15:30 in BASIC Stamp
If I have a serin in a loop does execution stop at the serin until a byte is on the pin the serin is looking at?· What I'm hoping is that it doesn't and it just continues to the rest of the code.

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-04-03 13:27
    NewJersey TN -

    Execution does stop until one of two things occurs. One is that the SERIN criteria is satisfied, or two, the timeout period has expired.

    Satisfying the SERIN critera may mean matching particular specified characters, or accepting a specified number of digits or an EOD indication (i.e. carraige return).

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-04-03 13:44
    Yes, the BS2 is a single-tasking machine. So it ONLY recieves data while sitting in a SERIN command, and while it's sitting in the SERIN command it's not doing anything else. There's NO buffering, in other words. So you do have to do something to allow the BS2 to 'miss' bytes and still be able to 'synchronize' with a sender.

    On the good side, it can SERIN on any I/O pin. On the bad side, only one at a time.
  • NewJerseyTNNewJerseyTN Posts: 14
    edited 2007-04-03 13:50
    Well, that sounds like I might be ok then if the timeout is short enough. Basically what I'm wanting to do is this:

    Get a byte from my PocketPC
    If a byte was sent set a varible to that byte
    depending on the varible move a servo to a setpostion + an additional small random number
    get a new random number
    loop back to getting a byte from the PocketPC

    I don't want the stamp to sit waiting for data from the PocketPC. I want it to go on updating that random number and making small movements in the servo. But when data is there I want it to get it.
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-04-03 13:53
    The servo needs to be updated every 20 mSec. So you can spend that 20 mSec in the 'Wait' timeout for the SERIN. You might want to send the byte from your PocketPC more than once, though.
  • NewJerseyTNNewJerseyTN Posts: 14
    edited 2007-04-03 14:19
    allanlane5,

    Well, that's why I have the varible that I'm setting the BYTE from serin to. As long as that varible isn't updated by the serin it should stay the same and the servo will get an updated signal in the loop after the serin call. Also I'm thinking of getting the serial servo controler from Parallax anyway. I believe it keeps a constant signal to the servo. I've looked at the help again on serin and the timeout parameter looks like just what the doctor ordered.
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-04-03 15:15
    I think when a SERIN does a timeout, it zero's the returned variable. This doesn't have to be a problem if you have a spare byte of variable space to store the 'last good' servo position. Also, probably 'zero' is not a 'good value' to set the servo to, so you can detect this 'bad' value.
  • NewJerseyTNNewJerseyTN Posts: 14
    edited 2007-04-03 15:30
    allanlane5,

    Yeah, a returned zero will be fine because the data I'm going to get from the PocketPC isn't going to be positional, more of an action to take. So I'm going to have the PocketPC send a character for "forward" and let the basic stamp handle what the right position for "forward" is.
Sign In or Register to comment.