serialControlString timeout to=on off on all platforms

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

serialControlString timeout to=on off on all platforms

Post by n.allan » Tue Dec 16, 2008 10:19 am

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?

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Post by hamlynart » Fri Dec 19, 2008 11:11 am

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

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Post by n.allan » Sat Dec 20, 2008 2:06 pm

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.

Post Reply