[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua and Serial Port
- From: Philipp Janda <siffiejoe@...>
- Date: Fri, 29 Mar 2013 14:38:43 +0100
Am 29.03.2013 12:04 schröbte Helen Fornazier:
I am new in Lua and I just start developing for OpenWRT in a Dragino
I want to develop an application that reads data from Uart and print it in
a Luci based web page.
But I am having a problem that I described here :
When I execute the code :
print("Dragino Uart Test started\n")while 1 do
print(serialin:read()) --print the data
I read the serial port but I receive an echo too and the read() waits
until a new line character to return.
Apart from the wrong call to read() which is already mentioned in lhf's
stackoverflow answer, it seems you need to set some terminal attributes
via tcsetattr. Unfortunately neither nixio nor luaposix has support
for this function. Typically you could execute the stty program to set
those attributes from the commandline, but unfortunately busybox (at
least on my openwrt) is compiled without support for stty. There is this
module and as Thijs already mentioned a version of luasocket which
supports serial connections, but you would need to compile those
yourself as well.
There is any other way to read from a serial port ?
If you don't want to touch a compiler I suggest the ser2net daemon
which can be installed via opkg. It handles mappings between terminal
files and tcp sockets and forwards data between them. A quick glance at
the source shows that it does "the right thing" in its terminal
configuration, which is to disable echo and line buffering. You could
then use the default nixio (which comes bundled with luci) or
luasocket modules to connect to the tcp port and read/write data ...
Thank you for your help, I appreciate it.