Page 1 of 1

serialControlString timeout to=on off on all platforms

Posted: Tue Dec 16, 2008 10:19 am
by n.allan
Could anyone explain how I can get a timeout to work when reading the serial port?

I have tried setting the serialcontrolstring to "to=on" or "to=off"

along with the command

read from [file or driver] ["COM1:" or "/dev/ttyUSB0"] until empty [in 5 seconds]

hoping it would timeout after 5 seconds of no data.

But I can never seem to get it to timeout. If there is no data, the program just waits for an input. I need my app to terminate if there is no input on the com port.

I can get something to work using:

read from file "COM1:" until lf

but this only reads one line, and only works if there's data present. There can be bursts of data from 0 up to 10 lines at a time. ending in crlf.

Also once I have set the serialControlString with all parameters then change 1 parameter such as "BAUD=19200" does this affect the rest of the parameters?

Posted: Fri Dec 19, 2008 11:11 am
by hamlynart
Yeah, I can't control the "read from driver" with "until" either but why not simply disconnect after a set period?:

Code: Select all

    close driver thePort
HTH

Jim H

Posted: Sat Dec 20, 2008 2:06 pm
by n.allan
I'll give the follwoing a try but I rather think that the script halts until data is read from the com port:

global tPortClosed
global tData

on ClosePort
put "true" into tPortClosed
close driver "/dev/ttyS0"
end ClosePort

on ReadPort
put "false" into tPortClosed
send ClosePort to this stack in 5 seconds --or whatever time I need

repeat while tPortClosed is not "true"
read from driver "/dev/ttyS0" until empty
put it into tData
if tData is empty
then send ReadPort to me in 5 ticks
else exit repeat
end repeat

put tData --see what we've got
quit
end ReadPort

I'm sure it will need a bit of twaeking but I'll see what happens.

Thanks for the reply.