Shop OBEX P1 Docs P2 Docs Learn Events
Spin Language Equivalent? — Parallax Forums

Spin Language Equivalent?

worthyamherstworthyamherst Posts: 46
edited 2011-07-20 10:47 in Propeller 1
I am wondering how I can send a wait command for the SERIN command. We are communicating between basic stamp and a propeller. We are sending out

SEROUT Tx,Baud, ["!", var] ,

I am wondering what is the spin equivalent for

SERIN Pin, Baud [WAIT ("!"), var]

I am using BS2 Functions and i have

var := bs.serin_char(pin, baud, polarity bits).
How can I make it wait for a "!" ?

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-07-20 10:19
    I don't use BS2 functions.

    Assuming the below code works at reading in a character,
    var := bs.serin_char(pin, baud, polarity bits)
    

    Then the code below should wait for a "!" character.
    repeat
      var := bs.serin_char(pin, baud, polarity bits)
    while var <> "!"
    

    Duane
  • mindrobotsmindrobots Posts: 6,506
    edited 2011-07-20 10:26
    EDIT: (Never mind....it appears you are using these already.)

    Would the BS2 PBASIC library for the Prop help? The OBEX description says it emulates a lot of the BS2 functions in SPIN.

    http://obex.parallax.com/objects/search/?q=bs2&csrfmiddlewaretoken=83ad328c72f0f2e74e707c2a11f75fae
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-20 10:30
    mindrobots wrote: »

    Yeah, it helped. Didnt see the
    SERIN_WAIT
    
    Thansk Guys.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-20 10:47
    Using the BS2 library is a bad idea, IMHO -- it brings all the *problems* we have with the BS2 to the Propeller! EFX-TEK products use the Parallax AppMod protocol so what I do is create methods that duplicate what I would have done with a single line of serial code. Yes, it's more code, but ultimately it's better and more flexible (one method replaces many SEROUT calls from my BS2 program).

    For example, in PBASIC you can send the Set command to the RC-4 relay board like this:
    SEROUT Sio, Baud, ["!RC4", addr, "S", relays]
    

    ... where addr is the board address, and relays is the relay control bits. I do it this way in Spin:
    pub set_rc4(addr, relays)
    
      com1.str(string("!RC4))
      com1.tx(addr)
      com1.tx("S")
      com1.tx(relays)
    

    Don't be fooled into thinking you can use .str() for the whole command; a zero in the command will foul the stream output due to the way the .str() method works.

    Note that this assumes that you have a serial object called com1 that has been setup at the correct baud rate.
Sign In or Register to comment.