Shop OBEX P1 Docs P2 Docs Learn Events
timeout — Parallax Forums

timeout

at_jayat_jay Posts: 16
edited 2011-08-06 08:34 in Propeller 1
Hi all!

I am looking forward for some immediate help in realm of the timeout function using propeller.
In case of FullDuplexSerial.spin we have rxtime(ms) PUB function that takes serial in the char value if not within time 'ms' it will step forward and execute next instruction.
I want to implement the similar case for ParallaxSerialTerminal.spin case for the PUB function DecIn.

The code for the FullDuplexSerial.spin is
PUB rxtime(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) => 0 or (cnt - t) / (clkfreq / 1000) > ms

How should I implement the same for ParallaxSerialTerminal.spin DecIn case? or how to modify the case for former for Decimal entries instead of char?

Looking forward for your help.

Thanks
Jay

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-08-06 06:40
    Jay, when you say decimal, do mean something like 123.45? If so, the decimal is 6 bytes long. How many bytes are you expecting before a timeout? What is the min and max value of the decimal?
  • LeonLeon Posts: 7,620
    edited 2011-08-06 06:49
    I think he means "denary"!
  • at_jayat_jay Posts: 16
    edited 2011-08-06 07:23
    Thanks for your replies, well for DecIn I am assuming "long" --> 4 bytes
  • Mike GMike G Posts: 2,702
    edited 2011-08-06 07:33
    DecIn is string command that waits for a <cr>. Then it handles the string.

    If you need a 4 byte LONG value then create a loop that reads, validates, and stores the 4 bytes in memory. Use the rxbyte method of the Full-Duplex Serial object to read the bytes without blocking.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-06 07:58
    You've started another identical thread in the General Discussion forum. This is against forum rules. Do not do it again!

    Since ParallaxSerialTerminal has an rxcheck routine, you can just add the same rxtime routine routine to it that you showed. DecIn uses the routine StrInMax which uses CharIn which uses rxcheck. You could substitute a call to rxtime for the call to CharIn to come up with a StrInMaxTime routine, then you'd have DecInTime call StrInMaxTime.
    PUB StrInMaxTime(stringptr, maxcount, mstime) | temp
    {{Receive a string of characters (either carriage return terminated or maxcount in length) and stores it (zero terminated)
    starting at stringptr.  Waits until either full string received or maxcount characters received.  Times out in mstime milliseconds.
    Returns true if a timeout occurred, false otherwise.
      Parameters:
        stringptr - pointer to memory in which to store received string characters.
                    Memory reserved must be large enough for all string characters plus a zero terminator (maxcount + 1).
        maxcount  - maximum length of string to receive, or -1 for unlimited.
        mstime - timeout in milliseconds (for each received character)}}
        
      repeat while (maxcount--)                                                     'While maxcount not reached
        if (temp := rxtime(mstime)) < 0                                           ' Stop on a timeout
          byte[stringptr]~                                                                ' Zero terminate string
          return true
        if (byte[stringptr++] := temp) == NL                                      'Get chars until NL
          quit
      byte[stringptr+(byte[stringptr-1] == NL)]~                                    'Zero terminate string; overwrite NL or append 0 char
    
  • at_jayat_jay Posts: 16
    edited 2011-08-06 08:34
    Sorry for that, actually its my first time and I posted my question in General discussion forum... then realize that I should need to put in Propeller forum as my question is specific to spin.
    meanwhile thanks for the support, will take care in future.

    Thanks
    Jay
Sign In or Register to comment.