[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua and Serial Port
- From: Steve Litt <slitt@...>
- Date: Sat, 30 Mar 2013 09:27:50 -0400
On Fri, 29 Mar 2013 12:04:20 +0100
Helen Fornazier <firstname.lastname@example.org> wrote:
> 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.
> There is any other way to read from a serial port ?
> Thank you for your help, I appreciate it.
You didn't say what OS, but I'm betting it's Linux, because that's the
default way all Linux reads act. Here's the way I switched the keyboard
(stdin) to read a character at a time:
os.execute("stty cbreak </dev/tty >/dev/tty 2>&1")
local key = io.read(1)
os.execute("stty -cbreak </dev/tty >/dev/tty 2>&1");
So in your case, instead of doing the stty commands and read on file
number 1, you'll do it on the file number for your serial port. And you
might need to change /dev/tty to whatever device the serial port is.
There's a BSD style one that's a little different, so if mine doesn't
work I'll try to dig that up for you.
Steve Litt * http://www.troubleshooters.com/
Troubleshooting Training * Human Performance