Shop OBEX P1 Docs P2 Docs Learn Events
serial rxtime(ms) example wanted — Parallax Forums

serial rxtime(ms) example wanted

kkibbekkibbe Posts: 11
edited 2009-04-21 14:07 in Propeller 1
I'm having trouble getting my serial port code working. All is well rx'ing data but I would like the code to timeout after a second or so and give up receiving data.... I'm using the FullDuplexSerialPlus object.

I have what looks like this below but I would love to see an example from someone using the rxtime(ms) format.
 .                  repeat                      
 .                      
 .                      char := uart.rxtime(1000)
 .                      if char == -1 
 .                         quit  
 .            
 .                      otherwise do something else              



Thanks,
Kevin

Comments

  • JomsJoms Posts: 279
    edited 2009-04-21 01:45
    Here is an example of it in use.· It is the string version, but works about the same way...
  • kkibbekkibbe Posts: 11
    edited 2009-04-21 01:51
    Thanks Joms but I can't see how you are using it any differntly than just a rxstr. How would your code time out?

    Kevin
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-21 05:24
    kkibbe,
    Joms' program doesn't really time out as you noticed. rxtime() just returns an illegal character (-1) when a timeout occurs. What you do with it depends on what you want your program to do on a time out. One possibility is to do an abort if rxtime() returns a -1 and catch that higher up the call path where it would make sense. Anything like that would require changes to the lower level code, but that's normally the case when you want to improve the error handling of a library. You have to design in the error detection and recovery all up and down the call path (A calls B calls C ....).
  • kkibbekkibbe Posts: 11
    edited 2009-04-21 11:13
    Hello Mike

    In the little code fragment I posted at the top I have the command "quit" if the character returned is a -1 but somehow it isn't exiting the repeat loop. Can you see a reason why I won't get the -1. I know my serial port becomes inactive but I'm thinking if my serial port is being held high or perhaps low the code that looks for a time out condition isn't being reached. The serial port is a 3 wire rx/tx/gnd connection.

    If I send to the prop via the serial port the letter "K" and set the repeat loop to exit on the letter "K" then everything is fine, the loop exits.

    Kevin
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-21 13:02
    It's hard to tell from just the fragment (hint ... hint ... that's why posting fragments often doesn't help ... you leave out the crucial piece). If char is declared as a byte, it can only hold values from 0 to 255. The -1 will be stored as 255 and the comparison won't ever be true.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-04-21 13:10
    Hello kkibbe,

    please ATTACH your WHOLE program to a posting by using the ARCHIVE-function of the Propeller-Tool.

    The solution will be found 3 times faster if you do that

    best regards

    Stefan
  • kkibbekkibbe Posts: 11
    edited 2009-04-21 14:01
    Mike you have hit upon it. I couldn't understand how a byte could be a -1 so I concluded it was some trick the compiler was doing...

    Thanks,
    Kevin
  • kkibbekkibbe Posts: 11
    edited 2009-04-21 14:07
    Thanks to Mike StefanL and Joms for helping. I'll trap the error on 255 and all will be well. I won't get $FF in my data so that is nice and easy.

    Kevin
Sign In or Register to comment.