------------------------------------------------------------------------------

                             lxi-tools Lua API

------------------------------------------------------------------------------

Both the lxi tool and lxi-gui tool add the following lua functions in addition
to the standard lua library functions.

------------------------------------------------------------------------------

  Function
    device = connect(address, port, name, timeout, protocol)

  Description
    Connect to LXI compatible device

  Parameters
     address: Address of remote device to connect [string]
        port: Port of remote device [integer] (only used for RAW connections)
        name: Name of remote device [string] (only used for VXI11 connection,
              best use nil to default to "inst0")
     timeout: Timeout in miliseconds [integer]
    protocol: Communications protocol to use [VXI11, RAW]

  Returns
      device: Handle of device

------------------------------------------------------------------------------

  Function
    response = scpi(device, command, timeout)

  Description
    Send SCPI command and receive response if expected

  Parameters
      device: Handle of connected device
     command: SCPI command to send [string]. A response is expected if the
              command ends with "?".
     timeout: Timeout in miliseconds [integer]

  Returns
    response: Returns response [string] if command string ended with "?". If an
              error (timeout etc.) occurs the response is nil.

------------------------------------------------------------------------------

  Function
    disconnect(device)

  Description
    Disconnect connected device

  Paramters
    device: Handle of device

------------------------------------------------------------------------------

  Function
    sleep(time)

  Description
    Sleep for specified amount of time

  Parameters
    time: Time to sleep in seconds [integer]

------------------------------------------------------------------------------

  Function
    msleep(time)

  Description
    Sleep for specified amount of time

  Parameters
    time: Time to sleep in miliseconds [integer]

------------------------------------------------------------------------------

  Function
    clock = clock_new()

  Description
    Create new clock resource

  Returns
    clock: Handle of new clock

------------------------------------------------------------------------------

  Function
    time = clock_read(clock)

  Description
    Read out the elapsed time of the clock since first clock_read() call

  Paramters
    clock: Handle of clock
  
  Returns
     time: Time in seconds since last call [double]. If first call it will
           return 0 and the clock will start ticking.

------------------------------------------------------------------------------

  Function
    clock_reset(clock)

  Description
    Reset clock so that it stops ticking. First clock_read() will make the
    clock tick again.

  Paramters
    clock: Handle of clock

------------------------------------------------------------------------------

  Function
    clock_free(clock)

  Desription
    Release clock resource

  Parameters
    clock: Handle of clock

------------------------------------------------------------------------------

  Function
    log = log_new()

  Description
    Create new log resource

  Returns
    log: Handle of new log

------------------------------------------------------------------------------

  Function
    log_add(log, ...)

  Description
    Log data to log.

    This is a variadic function which means that it can take a variable number
    of arguments and log them. Each log argument can be of any type.

    Example:
      log_add(log, 42, "hello", 4242).

    The resulting line in the CSV output file will look like this:
      42,"hello",4242

  Parameters
    log: Handle of log

------------------------------------------------------------------------------

  Function
    log_save_csv(log, filename)

  Description
    Save log data to CSV formatted (RFC 4180) log file.

  Parameters
         log: Handle of log
    filename: Name of CSV file [string]

------------------------------------------------------------------------------

  Function
    log_free(log)

  Desription
    Release log resource

  Parameters
    log: Handle of log

------------------------------------------------------------------------------







Additionally, the lxi-gui tool adds the following lua functions to present and
manage data via the GUI.

NOTE: These functions can only be used when running scripts via lxi-gui.

------------------------------------------------------------------------------

  Function
    chart = chart_new(type, ...)

  Description
    Create and present a new chart. The chart is opened in a new window.

  Parameters
    type: Chart type [string]

          The type can be any of the following:
            "line"
            "scatter"
            "number"
            "angular-gauge"
            "linear-gauge"

          The number of parameters following the first parameter depends on
          which type of chart is requested:

                "line", "scatter":

                      title: Title [string]
                    x_label: Label of x-axis [string]
                    y_label: Label of y-axis [string]
                      x_max: Maximum value of x-axis [double]
                      y_max: Maximum value of y-axis [double]
                      width: Width of window in pixels [integer]

                "number":

                      title: Title [string]
                      label: Label [string]
                      width: Width of window in pixels [integer]

                "angular-gauge", "linear-gauge":

                      title: Title [string]
                      label: Label [string]
                  value_min: Minimum value [double]
                  value_max: Maximum value [double]
                      width: Width of window in pixels [integer]

  Returns
    chart: Handle of chart

------------------------------------------------------------------------------

  Function
    chart_plot(chart, x, y)

  Description
    Plot x and y value to chart

  Paramters
    chart: Handle of chart
        x: X value [double]
        y: Y value [double]

------------------------------------------------------------------------------

  Function
    chart_save_csv(chart, filename)

  Description
    Save plotted data to CSV file

  Paramters
       chart: Handle of chart
    filename: Name of CSV file [string]

------------------------------------------------------------------------------

  Function
    chart_save_png(chart, filename)

  Description
    Save image of plotted chart to PNG file

  Paramters
       chart: Handle of chart
    filename: Name of PNG file [string]

------------------------------------------------------------------------------

  Function
    chart_close(chart)

  Description
    Close chart window

  Paramters
    chart: Handle of chart

------------------------------------------------------------------------------

  Function
    version = version()

  Description
    Get version of lxi-tools

  Returns
    version: Version of lxi-tools [string]

------------------------------------------------------------------------------

  Function
    ip = selected_ip()

  Description
    Get IP of device selected in GUI

  Returns
    ip: IP of device selected in GUI [string]. Returns nil if none selected.

------------------------------------------------------------------------------

  Function
    id = selected_id()

  Description
    Get ID of device selected in GUI

  Returns
    id: ID of device selected in GUI [string]. Returns nil if none selected.

------------------------------------------------------------------------------

  Function
    chart_save_csv(chart, filename)

  Description
    Save plotted data to CSV file

  Paramters
       chart: Handle of chart
    filename: Name of CSV file [string]

------------------------------------------------------------------------------

  Function
    chart_save_png(chart, filename)

  Description
    Save image of plotted chart to PNG file

  Paramters
       chart: Handle of chart
    filename: Name of PNG file [string]

------------------------------------------------------------------------------
