Shop OBEX P1 Docs P2 Docs Learn Events
Another Serial Object Question... — Parallax Forums

Another Serial Object Question...

JomsJoms Posts: 279
edited 2009-07-16 20:49 in Propeller 1
I know I am almost beating a dead horse here, but I have searched and don't quite understand what I am reading. I have looked at the FDS4Port, Full Duplex Serial, and Extended Duplex Serial objects but still have a few questions.

I am trying to input a continuous string of data. I have done this several times in the stamp but having problems finding the right command in the prop objects. Ideally I would like to use the FDS4Port object as I will be input two or three strings at the same time, but I can always use another object 3 times if I had to.
Basically I am looking for the proper wait command.· The delimiter appears to be used differently then the wait command.

I do not have much code written yet as I am having problems getting started with this command. In Basic it would look something like this...

SERIN 15, 16572, [noparse][[/noparse]WAIT($A,$B,$C), variable]


Heres what I have for the start part of my program so far...


OBJ
  Data: "FDS4Port"   

PUB Start
  Data.Init
  Data.AddPort(0,26,Data#PINNOTUSED,Data#PINNOTUSED,Data#PINNOTUSED,Data#DEFAULTTHRESHOLD,Data#OCTX,4800)
  Data.AddPort(1,27,Data#PINNOTUSED,Data#PINNOTUSED,Data#PINNOTUSED,Data#DEFAULTTHRESHOLD,Data#OCTX,4800) 
  Data.Start

  Main

PUB Main

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-16 20:49
    There is no WAIT equivalent. You have to do it yourself like:
    REPEAT
       temp := Data.rx(0)
    UNTIL temp == $A or temp == $B or temp == $C
    variable := Data.rx(0)   ' For a single byte value
    variable |= Data.rx(0) << 16   ' Add for the 2nd byte of a 16-bit word value
    
  • JonnyMacJonnyMac Posts: 9,197
    edited 2009-07-16 20:49
    Assuming you have a serial input object called 'term' you could create custom methods; one to wait on a character (any byte, actually), another to wait on a string:

    pub waitch(ch) | check
    
      repeat
        check := term.rx
      until (check == ch)
    
    
    pub waitstr(pntr) | count, cpntr, check
    
      count := strsize(pntr)
      cpntr := pntr
    
      repeat while count
        check := term.rx                                            ' get character from stream
        if (check == byte[noparse][[/noparse]cpntr])                                   ' compare to string
          --count                                                   ' if match, update count
          ++cpntr                                                   '  and character pointer
        else
          count := strsize(pntr)                                    ' else reset count
          cpntr := pntr                                             '  and character pointer
    


    To handle your specific example you would do this:

    waitstr(string($A, $B, $C))
    variable := term.rx
    

    Post Edited (JonnyMac) : 7/16/2009 8:56:01 PM GMT
Sign In or Register to comment.