Introduction
This is a companion Lua module provided with LuaTerminal and it allows easy connection to a socket terminal opened by LuaTerminal by any Lua script.Usage
To use the LuaTerminalRemote module just do:This creates the module table in remote.
Installation
Just copy the LuaTerminalRemote.lua file to a place in the package.path directories or just install it using LuaRocks like:API
The following variables and functions are accessible in the module to interface with a socket terminal.Functions
- tryConnect(timeout,socketTimeout) - Tries to detect for an open socket terminal and if found connects to it.
- If timeout given it tries to detect only for timeout seconds otherwise it tries to detect for 10ms
- If socketTimeout given the when connected the socket timeout is set to this otherwise it is set to 100ms
- returns nil and error message if connection not made else returns the remote.Connected table.
- sendData(data) - Sends a string to a connected socket terminal.
- returns index of last byte sent if successful otherwise returns nil and error message
- receiveData() - Receives response strings from the socket terminal
- returns the received string or nil if nothing received. If an error occurs then returns nil with an error message.
- sendCMD(cmd) - function to send a command cmd to the socket terminal. It returns the response to the command.
- sendUP() - same as writing sendCMD("UP")
- sendDOWN() - same as writing sendCMD("DOWN")
- sendLEFT() - same as writing sendCMD("LEFT")
- sendRIGHT() - same as writing sendCMD("RIGHT")
Variables
- remote._VERSION - returns the version of the LuaTerminalRemote Module
- remote.Connected - returns the current connection status. False if not connected to a socket terminal. If connected then this is a table with remote.Connected[1] = IP of the socket terminal and remote.Connected[2] = port of the socket terminal