Shop OBEX P1 Docs P2 Docs Learn Events
How to WAIT for string — Parallax Forums

How to WAIT for string

PVJohnPVJohn Posts: 60
edited 2006-07-21 05:40 in Propeller 1
I know it's very simple, but not simple enough for me. I just got my Demo board
and my plan is to switch one application from BS2 to Propeller. I read about fullduplexserial,
BS2functions and I also checked an example made for el_paisa, but I couldn't find the answer.
Can anyone help me to convert this Pbasic to Spin code? I don't know how to "WAIT" for, and catch
"OK" from replay. In my new application I would like to use pins PO and P1 without MAX233 since
the external unit has 3V UART. Regards, PVJohn


'{$STAMP BS2px}
'{$PBASIC 2.5}
RX········ PIN 4···· ' receive
TX········ PIN 6···· ' transmit
Baud······ CON 1646············ '2400-N-8-1 with MAX 233
SEROUT TX, Baud, [noparse][[/noparse]"TR",CR]····· 'Take Reading command
SERIN· RX, Baud, [noparse][[/noparse]WAIT ("OK")]
SERIN RX, Baud, [noparse][[/noparse]WAIT (34),replay\10\34]··

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-19 05:30
    Something like this? [noparse][[/noparse]the search for "OK" needs to be fancier to be strictly correct]
    CON
      Cr = $0D
    VAR
      byte replay[noparse][[/noparse]10]
    OBJ
      ser : "FullDuplexSerial"
    PUB sample | t, i
      ser.start(4,6,%0000,2400)
      ser.str(string("TR",Cr))
      repeat until ser.rx == "O" and ser.rx == "K"
      repeat until ser.rx == 34
      i := 0
      repeat until (t := ser.rx) == 34 or i == 10
        replay[i] := t
        i += 1
    [/i]
    
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-07-19 06:01
    Mike,

    If Spin had "lazy conditionals", that would work. With lazy conditonals, if the term ser.rx == "O" were false, the second term in the and wouldn't be evaluated. But in Spin the entire conditional executes even if its outcome is preordained. So, the string "AOK", for example, wouldn't be recognized as an instance of "OK", since the incoming "A" gets compared with "O" and the "O" with "K". But "ABOK" would pass muster.

    -Phil
  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-19 06:12
    Yes, that's what I meant by "fancier". This will catch a simple "OK" response with nothing preceeding it. This might work better:
      c0 := -1
      repeat until c0 == "O" and (c1 := ser.rx) == "K"
        c0 := c1
    
    
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-07-19 06:22
    Mmm, nice! Basically a shift register, and easily extended to longer strings. In fact, for strings of four characters or less, you could shift the characters into a long and do a single compare.

    -P.
  • PVJohnPVJohn Posts: 60
    edited 2006-07-21 03:37
    Thanks for your replay. I'm having a problem to compile this code.
    Software expect to see " ) " ·right after· "·%0000" in line
    ··· ser.start(0,1,%0000,2400)
    It will take it when I change it to
    ····ser.start(0,1,%0000)
    but then it doesn't work. Am I doing something wrong?

    Regards, PVJohn
  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-21 04:47
    Make sure you have version 1.1 of FullDuplexSerial. I think the mode parameter was added in that version.
  • PVJohnPVJohn Posts: 60
    edited 2006-07-21 05:12
    I can't find it in download section. Do you have a link?

    Thanks.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-21 05:40
    Here's my copy of the file.
Sign In or Register to comment.