Shop OBEX P1 Docs P2 Docs Learn Events
Serial receiving with timeout — Parallax Forums

Serial receiving with timeout

jnoguesjnogues Posts: 25
edited 2010-01-31 11:04 in Propeller 1
Hi everybody,
Is possible received a string using Parallax Serial Terminal.spin object, with a timeout?

Regards,

Jaume Nogues
Barcelona
Spain

Comments

  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-01-31 11:04
    I've been using this serial object obex.parallax.com/objects/340/

    It has 4 serial objects in one cog, but regarding timeouts, it has
    PUB rxtime(port,ms) : rxbyte | t
    '' Wait ms milliseconds for a byte to be received
    '' returns -1 if no byte received, $00..$FF if byte
      t := cnt
      repeat until (rxbyte := rxcheck(port)) => 0 or (cnt - t) / (clkfreq / 1000) > ms
    
    



    The object has a large buffer, so I prefer to poll to see if anything is in the buffer
    PUB rxavail(port) : truefalse
    
    '' Check if byte(s) available
    '' returns true (-1) if bytes available
      if long[noparse][[/noparse]@rx_tail][noparse][[/noparse]port] <> long[noparse][[/noparse]@rx_head][noparse][[/noparse]port]
        truefalse:=-1
      else
        truefalse:=0
    
    



    and then get a byte and then check again if anything is there.

    It is faster than waiting for timeouts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
Sign In or Register to comment.