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