I second (third?) what Goeytex and lbenson have requested above. The timeout feature is of no benefit if a qualifier is used since a lockup can still occur. The only workaround would be to manually process the data searching for the "start" string instead of using a qualifier, which would be a huge step backwards.
I have Picaxe-18x code in place at present to test for a pin fluctuating (high/low) before I do a Serin (see below). Crude but effective. I was going to convert to 18M2+ and use a timeout so I could delete that code, but the new code would end up being just as long, searching for the start value instead if I want it to be lock-up-proof.
The way it is at present the Programming Editor might as well reject as invalid any Serin statement containing both a timeout and also a qualifier, since the result is NOT going to be what the majority of users would expect. (I was about to convert my code to use it, until I read this post.)
At the very least Manual 2 needs to spell out clearly the limitation. At present it says: "Timeout is an optional variables/constants which sets the timeout period in milliseconds."
And further down: "The timeout value, set in milliseconds, is the length of time the serin command will wait for a serial command to be detected."
What is a "serial command"??? I took it to mean "serial data containing the qualifier".
The command needs two timeouts to work properly, one for no serial data at all and a second for qualifier not found. One might typically set the first to say 2 seconds and the second to say 10 seconds.
Here is my current code. It will still hang if the serial data does not contain the qualifier, so I guess I should still convert to use the timeout and save a few precious lines of code:
' First check GPS input pin to determine if changing data is present.
' If we just do a serin and there is no data (eg. GPS dead or not present)
' then the program hangs forever.
' Pin is held low with a 10k resistor for when no GPS present.
w1 = 0
w2 = 0
for w0 = 1 to 500 ; check pin for about 1 second
if gpspin = 1 then
w1 = w1 + 1
else
w2 = w2 + 1
endif
pause 1
next
if w1 < 10 or w2 < 10 then gpsbad ; No gps serial data present
' Read GPS data and check if data valid.
' If GPS data-valid flag is "A" (good fix) then accept time and date.
' NB. At 8MHz you have to specify 2400bps on serin to read 4800bps data
' Serial data from GPS is True logic (0v=logic 0, 5v=logic 1) so specify T2400
' Read time hhmmss in b1-b6, valid or invalid flag in b7 and date ddmmyy in b8-b13
setfreq m8 ; run at 8MHz to allow reading serial data at 4800bps
serin gps,t2400,("$GPRMC,"),b1,b2,b3,b4,b5,b6,#w6,b7,#w6,#w6,b0,#w6,#w6,b0,#w6,#w6,#w6,#w6,b8,b9,b10,b11,b12,b13
setfreq m4
if b7 <> "A" then gpsnolock ; GPS not yet locked on to satellites
...
etc