lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


First, you might need to send it a \r instead of a \n. I forget how modems work, it's been a while. Also, there's probably something you need to do to set the TTY speed. Also, if you don't actually have a modem hooked up, it will block forever waiting to read something. For something low-level like this, why not do it in C where you have all the tcgetattr(), tcsetattr(), cfsetispeed(), cfsetospeed(), et cetera.


Brendan Dowling





Matthew Percival wrote:

G'Day,

	I was trying to write a simple Lua script to check modem status; for a
test script, I simply wanted to send `AT' and check if I receive `OK' in
return. I have been doing it like this:

tty = io.open("/dev/ttyS0", "rw")
tty:write("AT\n")
if (tty:read("*line") ~= "OK") then
	print "Modem Failed!\n"
else
	print "Modem OK!\n"
end
tty:close()

	However, it just blocks at the read, never receiving anything back.  My
first thought is that it is missing the OK, but I was also wondering if
it were because io.open were not compatible with device nodes: when I
checked liolib.c, I saw that it uses fopen() (and thereby everything
uses FILE*), when I need it to use open().

	Does anyone know if it is possible to do this in Lua?  I would imagine
I would would need to write a different io library set for file
descriptors (in place of the FILE* library currently used), but even if
I did this I am not sure whether that would be enough or not.

	-- Matthew