Shop OBEX P1 Docs P2 Docs Learn Events
How to read a char from FullDuplexSerial without removing it from buffer? — Parallax Forums

How to read a char from FullDuplexSerial without removing it from buffer?

william chanwilliam chan Posts: 1,326
edited 2012-01-13 09:09 in Propeller 1
Hi,

Actually I am using FullDuplexSerial_rr004 which is quite similar.
Does anyone know how to read a char received without removing it from the receive buffer?

Thanks.

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-01-12 19:50
    Sure add a getter to the FullDuplexSerial object.
    PUB GetBuffer(index)
      return rx_buffer[index]
    

    I have to ask... why??? There is probably a better way to handle your business logic.
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-01-12 23:03
    Just add this spin routine to the FDX spin code and call it.
    PUB rxtwice : rxbyte
    '' Check if byte received (never waits)
    '' returns -1 if no byte received, $00..$FF if byte
    '' does not clear from buffer
      rxbyte--
      if rx_tail <> rx_head
        rxbyte := rx_buffer[rx_tail]
    

    You will notice it is just the routine Rxbyte with the buffer decrement line removed.

    If you just want to know if there is a char in the buffer you can use Rxavail.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-01-13 00:17
    Mike G wrote:
    I have to ask... why???
    Contextual lookahead. 'Seems legit to me. It can be simpler than unbuffering, then having to stash it temporarily because you weren't quite ready for it.

    -Phil
  • william chanwilliam chan Posts: 1,326
    edited 2012-01-13 01:02
    So for FullDuplexSerial_rr004,

    I just change this line
    rx_tail := (rx_tail + 1) & bufmsk

    to become

    rx_tail := rx_tail & bufmsk

    for the lookahead method?
    Thanks.
  • william chanwilliam chan Posts: 1,326
    edited 2012-01-13 01:08
    Now I think I get it,

    I should remove this line
    rx_tail := (rx_tail + 1) & bufmsk
    totally for the lookahead method right?

    I feel so stupid, thanks Cluso and Mike.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-01-13 09:09
    William,

    I'm not sure if it would be useful in your case or not, but I modifed Tim Moore's four port serial driver to watch for an end of message character.

    With a 512 byte rx buffer, I just let the message sit in the rx buffer until it's complete and then process the message. It has really simplified a lot of my projects. I don't have to continually move bytes from one buffer to another as I watch for the final byte of the message.

    The modified driver is attached to post #9 of this thread.
Sign In or Register to comment.