View Full Version : Timeout feature of FullDuplexSerial & Extended_FDSerial objects

05-15-2008, 06:33 PM

According to the info for EXTENDED_FDSerial & FullDuplexSerial objects..

If the timeout functions are used ( e.g. rxtime(ms)) and a timeout occurs a -1 is sent back as a byte.

So, If I have a routine that reads these BYTES back in to make a STRING ( using the BYTE[@mystring][index] etc Commands) then ..

Q1) what does a -1 mean to my string?

I believe that bytes values from 1 to 256 are valid ( for strings) and a 0 is used for the terminator.

Q2) Should I check for a timeout ( i.e a -1) and abort the rest of routine for creating the string?

Dave M

Mike Green
05-15-2008, 08:53 PM
Strings are byte arrays, so the elements can have values from 0 to 255. The convention is that the value zero is used as a terminator.

1) -1 is the value consisting of all one bits. When you store this in a byte, the value stored is 8 one bits which is also considered to be 255.

2) Whatever makes sense for your program. You could just stop, store a zero terminator and return what you have. You could use the ABORT statement to return to whatever point the caller wants.

05-16-2008, 05:02 AM
HI Mike,


I think you have just solved my problem.

I did not mention the problem I am currently having.

I am displaying these "strings" on an LCD, Sometimes my LCD will display a strange character , but repeatedly the same character and according to the character set of my LCD it is character value 255!!!! ( i.e all 1's for the 8 bits)

When this happens I also get "OVERSPILLS" in my display, meaning the string is returned with the 255 character ( the result of the -1) as you mentioned , but no termination is applied ( when this happens) due to the logic in my code. So I think I MUST be getting TIME-OUT'S and then when I do all hell breaks loose in my display!

So Thanks mike!, I will now refine my routine to check for this timeout value and take appropriate action!

I do make sure that I terminate my strings correctly, but that only happens if I get at least 1 "PROPER" character returned by the serial function.

But now that leaves me with the reason I am getting timeouts in the first place!

Thanks heaps Mike!


Dave M