LuaTerminalRemote

20 August 2019 Link


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:
  1. remote = require("LuaTerminalRemote")

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:
>luarocks install luaterminalremote

API

The following variables and functions are accessible in the module to interface with a socket terminal.

Functions

  1. 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.
  2. sendData(data) - Sends a string to a connected socket terminal.
    returns index of last byte sent if successful otherwise returns nil and error message
  3. 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.
  4. sendCMD(cmd) - function to send a command cmd to the socket terminal. It returns the response to the command.
  5. sendUP() - same as writing sendCMD("UP")
  6. sendDOWN() - same as writing sendCMD("DOWN")
  7. sendLEFT() - same as writing sendCMD("LEFT")
  8. sendRIGHT() - same as writing sendCMD("RIGHT")

Variables

  1. remote._VERSION - returns the version of the LuaTerminalRemote Module
  2. 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

Repository

The source code can be downloaded from the github repository here

See Also