LuaTerminal and it allows easy connection to a socket terminal opened by LuaTerminal by any Lua script.
LuaTerminalRemote module just do:
This creates the module table in remote.
LuaTerminalRemote.lua file to a place in the package.path directories or just install it using LuaRocks like:
- 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")
- 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 = IP of the socket terminal and remote.Connected = port of the socket terminal