Shop OBEX P1 Docs P2 Docs Learn Events
Timeout feature of FullDuplexSerial & Extended_FDSerial objects — Parallax Forums

Timeout feature of FullDuplexSerial & Extended_FDSerial objects

DavidMDavidM Posts: 626
edited 2008-05-15 22:02 in Propeller 1
Hi,

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[noparse][[/noparse]@mystring][noparse][[/noparse]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?


Regards
Dave M

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-15 13:53
    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.
  • DavidMDavidM Posts: 626
    edited 2008-05-15 22:02
    HI Mike,

    EUREKA!

    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!

    regards

    Dave M
Sign In or Register to comment.