mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Clean up lua API
Rename modem_send() to send() Rename send to write()
This commit is contained in:
parent
4511d74a9e
commit
c49faa7337
6 changed files with 55 additions and 44 deletions
32
README.md
32
README.md
|
|
@ -401,12 +401,30 @@ expect(string, timeout)
|
|||
|
||||
On successful match it also returns the match string as second return value.
|
||||
|
||||
send(string)
|
||||
Send string.
|
||||
read(size, timeout)
|
||||
Read from serial device. If timeout is 0 or not provided it will wait
|
||||
forever until data is ready to read.
|
||||
|
||||
Returns number of bytes read on success, 0 on timeout, or -1 on error.
|
||||
|
||||
On success, returns read string as second return value.
|
||||
|
||||
read_line(timeout)
|
||||
Read line from serial device. If timeout is 0 or not provided it will
|
||||
wait forever until data is ready to read.
|
||||
|
||||
Returns number of bytes read on success, 0 on timeout, or -1 on error.
|
||||
|
||||
On success, returns the string that was read as second return value.
|
||||
Also emits a single timestamp to stdout and log file per options.timestamp
|
||||
and options.log.
|
||||
|
||||
write(string)
|
||||
Write string to serial device.
|
||||
|
||||
Returns number of bytes written on success or -1 on error.
|
||||
|
||||
modem_send(file, protocol)
|
||||
send(file, protocol)
|
||||
Send file using x/y-modem protocol.
|
||||
|
||||
Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM.
|
||||
|
|
@ -421,14 +439,6 @@ tty_search()
|
|||
|
||||
Returns nil if no serial devices are found.
|
||||
|
||||
read(size, timeout)
|
||||
Read from serial device. If timeout is 0 or not provided it will wait
|
||||
forever until data is ready to read.
|
||||
|
||||
Returns number of bytes read on success, 0 on timeout, or -1 on error.
|
||||
|
||||
On success, returns read string as second return value.
|
||||
|
||||
set{line=state, ...}
|
||||
Set state of one or multiple tty modem lines.
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ if (1 == found) then
|
|||
local hostname = string.match(match_str, "^%w+")
|
||||
local login = logins[hostname]
|
||||
if (nil ~= login) then
|
||||
send(login.username .. "\n")
|
||||
write(login.username .. "\n")
|
||||
expect("Password:")
|
||||
send(login.password .. "\n")
|
||||
write(login.password .. "\n")
|
||||
else
|
||||
io.write("\r\nDon't know login info for " .. hostname .. "\r\n")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
read(1000, 6000) -- initial config
|
||||
send("\n")
|
||||
write("\n")
|
||||
msleep(100)
|
||||
read(650, 60) -- main menu
|
||||
send("S") -- S menu
|
||||
write("S") -- S menu
|
||||
msleep(30)
|
||||
read(650, 60)
|
||||
send("t") -- Parallel Value Table
|
||||
write("t") -- Parallel Value Table
|
||||
read(650, 60)
|
||||
while true do
|
||||
msleep(1000)
|
||||
send("t")
|
||||
write("t")
|
||||
read(650, 50) -- repeat PVT forever
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
read(1000, 8000) -- read initial config
|
||||
send("\n")
|
||||
write("\n")
|
||||
read(650, 100) -- main menu
|
||||
send("S") -- S menu
|
||||
write("S") -- S menu
|
||||
n = 1
|
||||
while n > 0 do -- while not empty, read more
|
||||
n, str = read_line(25)
|
||||
end
|
||||
while true do
|
||||
send("t") -- query PV table
|
||||
write("t") -- query PV table
|
||||
msleep(880)
|
||||
n = 1
|
||||
while n > 0 do -- while not empty, read more
|
||||
|
|
|
|||
43
man/tio.1.in
43
man/tio.1.in
|
|
@ -428,7 +428,8 @@ Send ctrl-t character
|
|||
.PP
|
||||
Tio suppots Lua scripting to easily automate interaction with the tty device.
|
||||
|
||||
In addition to the Lua API tio makes the following functions available:
|
||||
In addition to the standard Lua API tio makes the following functions
|
||||
available:
|
||||
|
||||
.TP 6n
|
||||
|
||||
|
|
@ -441,26 +442,6 @@ Returns 1 on successful match, 0 on timeout, or -1 on error.
|
|||
|
||||
On successful match it also returns the match string as second return value.
|
||||
|
||||
.IP "\fBsend(string)"
|
||||
Send string.
|
||||
|
||||
Returns number of bytes written on success or -1 on error.
|
||||
|
||||
.IP "\fBmodem_send(file, protocol)"
|
||||
Send file using x/y-modem protocol.
|
||||
|
||||
Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM.
|
||||
|
||||
.IP "\fBtty_search()"
|
||||
Search for serial devices.
|
||||
|
||||
Returns a table of number indexed tables, one for each serial device found.
|
||||
Each of these tables contains the serial device information accessible via the
|
||||
following string indexed elements "path", "tid", "uptime", "driver",
|
||||
"description".
|
||||
|
||||
Returns nil if no serial devices are found.
|
||||
|
||||
.IP "\fBread(size, timeout)"
|
||||
Read from serial device. If timeout is 0 or not provided it will wait forever
|
||||
until data is ready to read.
|
||||
|
|
@ -480,6 +461,26 @@ On success, returns the string that was read as second return value. Also
|
|||
emits a single timestamp to stdout and log file per options.timestamp
|
||||
and options.log.
|
||||
|
||||
.IP "\fBwrite(string)"
|
||||
Write string to serial device.
|
||||
|
||||
Returns number of bytes written on success or -1 on error.
|
||||
|
||||
.IP "\fBsend(file, protocol)"
|
||||
Send file using x/y-modem protocol.
|
||||
|
||||
Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM.
|
||||
|
||||
.IP "\fBtty_search()"
|
||||
Search for serial devices.
|
||||
|
||||
Returns a table of number indexed tables, one for each serial device found.
|
||||
Each of these tables contains the serial device information accessible via the
|
||||
following string indexed elements "path", "tid", "uptime", "driver",
|
||||
"description".
|
||||
|
||||
Returns nil if no serial devices are found.
|
||||
|
||||
.IP "\fBset{line=state, ...}"
|
||||
Set state of one or multiple tty modem lines.
|
||||
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ static int modem_send(lua_State *L)
|
|||
}
|
||||
|
||||
// lua: send(string)
|
||||
static int send_(lua_State *L)
|
||||
static int write_(lua_State *L)
|
||||
{
|
||||
const char *string = lua_tostring(L, 1);
|
||||
int ret;
|
||||
|
|
@ -550,8 +550,8 @@ static const struct luaL_Reg tio_lib[] =
|
|||
{ "sleep", sleep_},
|
||||
{ "msleep", msleep},
|
||||
{ "line_set", line_set},
|
||||
{ "modem_send", modem_send},
|
||||
{ "send", send_},
|
||||
{ "send", modem_send},
|
||||
{ "write", write_},
|
||||
{ "read", read_string},
|
||||
{ "read_line", read_line},
|
||||
{ "expect", expect},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue