Shop OBEX P1 Docs P2 Docs Learn Events
Timer and Serial Coms help — Parallax Forums

Timer and Serial Coms help

Zap-oZap-o Posts: 452
edited 2009-09-08 16:18 in Propeller 1
I am trying to get this code to work. It seems that the timer is not activated.


Pub Getstring | TimerX, StringCount

TimerX := Cnt
StringCount := 0 
   
  Repeat Until ((SerialData[noparse][[/noparse] StringCount ] := Coms.rx) == ".") or ((Cnt - timerx) / (clkfreq / 1000) => 100)                                          
          StringCount++





i am using the fullDuplexSerial object and just want to set a timer up to move on.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 16:10
    1) The system clock is always running

    2) Your problem is that Coms.rx doesn't return until a character is available. You could use Coms.rxcheck which returns a -1 if there's no character available or you could use Coms.rxtime(100) which already does the timeout checking and returns -1 if there's a timeout.
    repeat until (result := Coms.rxtime(100)) < 0 or result == "."
       SerialData[noparse][[/noparse] StringCount++ ] := result
    
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-09-08 16:12
    The rx method blocks until a character has been received. So it's possible you could be waiting at the call to rx until after cnt rolls past timerx, at which point it's too late to catch a timeout. Use the method rxcheck to make sure there's a character waiting before calling rx. Since Spin does not use lazy evaluation of Boolean expressions, you will need to incorporate an if statement into your repeat loop.

    -Phil

    Update: Mike beat me to it with a much better suggestion. smile.gif
  • Zap-oZap-o Posts: 452
    edited 2009-09-08 16:18
    Phil thanks for the explanation. It makes since now. I can see now that I was using the wrong function in the object.

    Mike thanks for the code. Its opened my eyes. Seems I often overlook the obvious.
Sign In or Register to comment.