[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua, and accessing nodes in /dev/ (Lua in Linux)...
- From: Brendan Dowling <bdowling@...>
- Date: Wed, 08 Feb 2006 15:59:46 -0800
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.
Matthew Percival wrote:
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")
if (tty:read("*line") ~= "OK") then
print "Modem Failed!\n"
print "Modem OK!\n"
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.