Module otii

An API for automating Otii measurements.

Core

clear() Clear output.
create_filter(filtertype, samples) Create a filter.
get_args() Get command line arguments.
get_otii_dir(folder_id) Get the path of special folders.
log(text, timestamp) Write text to time synchronized log window.
mkdir(path) Make a directory.
msleep(msec) Suspend execution for a given time.
on_stop(function) Add on stop handler
run() Run an event based application.
set_message_handler(function) Set message handler.
stop() Stop the event loop.
timestamp(format) Get timestamp
write(text) Write text to output.
writeln(text) Write newline terminated text to output.

Timer

create_timer(interval, callback) Create a timer.
timer:delete() Delete a timer.

Local Server

create_local_server(servername, callback) Create local server

The provided callback will be called when data is available.

server:close() Close local server.

Project

create_project() Create a new project.
get_active_project() Return the active project.
project:close() Close an open project.
project:crop_data(start, end) Crop all data.
project:downsample_channel(device, channel, factor) Downsample a channel.
project:enable_main_power(enable) Enable main power.
project:get_channel_count(device, recording_id, channel) Get channel count.
project:get_channel_data(device, recording_id, channel, index, count, strip) Get channel data.
project:get_last_recording_id() Get last recording id
project:get_log_offset(device, recording_id, channel) Get log offset in microseconds.
project:get_recording_offset(recording_id) Get recording offset in microseconds.
project:import_log(recording_id, filename, converter) Import a log.
project:remove_recording(recording_id) Remove a recording.
project:rename_recording(recording_id, name) Rename a recording.
project:save(filename) Save an open project.
project:set_log_offset(device, recording_id, channel, offset) Set log offset in microseconds.
project:set_recording_offset(recording_id, offset) Set recording offset in microseconds.
project:start() Start a new recording.
project:stop() Stop the current recording.

Otii Device

waitfor_device_added() Wait for a new device to be connected.
waitfor_device_available() Wait for any Otii device to be available.
get_devices(type, timeout) Get a list of available devices.
get_id(name) Get id from name.
open_device(id) Get a handle to an Otii device.
format_value(channel, value) Converts a raw SI value into appropriate suffixed value.
device:add_channel_filter(channel, filter) Add a filter to a channel.
device:calibrate() Calibrate Otii device.
device:calibrate_sense(pin) Calibrate Arc Sense+/Sense-.
device:commit() Commit Arc settings to non-volaile storage.
device:close() Close handle to Otii device.
device:enable_4wire(enable) Enable/disable 4-wire measurements using Sense+/-.
device:enable_battery_profiling(enable) Enable battery profiling.
device:enable_channel(channel, enable) Enable channel.
device:enable_exp_port(enable) Enable expansion port.
device:enable_main(enable) Enable/disable the main power of the device.
device:enable_5v(enable) Enable +5V pin.
device:enable_uart(enable) Enable UART.
device:get_4wire() Get the 4-wire measurement state.
device:get_adc_resistor() Get ADC resistor.
device:get_calibration(calibration_id) Get calibration.
device:get_exp_voltage() Get the voltage of the expansion port.
device:get_gpi(Id) Get the state of a GPI pin.
device:get_main_resistance() Get the main internal resistance.
device:get_main_voltage() Get the main voltage.
device:get_max_current() Get the max allowed current.
device:get_range() Get the current range.
device:get_rx() Get the state of the RX pin.
device:get_uart_baudrate() Get the baudrate of the UART.
device:get_value(channel) Get a value.
device:get_version() Get the version of the device.
device:init() Initialize the device.
device:led(ontime, offtime) Set the LED.
device:reset() Enter DFU mode.
device:set_adc_resistor(resistor) Set the value of the shunt resistor for the ADC.
device:set_battery_profile(profile) Set the battery profile.
device:set_calibration(calibration_id, calibration_data) Set calibration values.
device:set_exp_voltage(voltage) Set the voltage of the expansion port.
device:set_gpo(port, enable) Set the state of a GPO.
device:set_main_current(current) Set the main current.
device:set_main_resistance(Ohm) Set the main internal resistance.
device:set_main_voltage(voltage) Set the main voltage.
device:set_max_current(current) Set the max allowed current.
device:src_cur_limit_enable(enable) Enable voltage source current limit (CC) operation.
device:get_src_cur_limit_enabled() Get current state of voltage source current limiting.
device:set_power_regulation(mode) Set power regulation mode
device:set_range(range) Set measurement range.
device:set_tx(enabled) Set TX pin high or low.
device:set_uart_baudrate(baudrate) Set UART baudrate.
device:wait_for_battery_data(timeout) Wait for battery data.
device:write_tx(data) Write data to TX.
device:get_supplies() Get a list of available supplies.
device:set_supply(id, series, parallel) Set power supply type.
device:get_supply() Get current power supply id.
device:get_supply_series() Get current number of simulated batteries in series.
device:get_supply_parallel() Get current number of simulated batteries in parallel.
device:set_supply_used_capacity(capacity) Set power supply used capacity.
device:get_supply_used_capacity() Get current power supply used capacity.
device:set_supply_soc_tracking(enable) Enable/disable power supply State of Charge tracking.
device:get_supply_soc_tracking() Get current state of power supply State of Charge tracking.

LXI

lxi_connect(address) Connect to LXI device.
lxi:read() Read current value from LXI device.
lxi:set(command) Send a LXI command to device, without expecting a response.
lxi:get(command) Send a LXI command to device, and return the result.
lxi:disconnect(LXI) Disconnect from a LXI device.


Core

clear()
Clear output.

This clears the output pane of the scripting window in the desktop application. In the console application this function does nothing.

See also:

create_filter(filtertype, samples)
Create a filter.

The filter can be applied to a channel with device:add_channel_filter. The filter must be applied before selecting the channel with device:enable_channel.

Parameters:

  • filtertype string The type of filter, "averaging" is the only available at this time.
  • samples int The number of samples to average or downsample by.

Returns:

    Filter object.

See also:

get_args()
Get command line arguments.

The first argument is the filename of the running script.

Returns:

    A list of command line arguments.

See also:

get_otii_dir(folder_id)

Get the path of special folders.

If no folder_id is specified, it returns the root of the Otii directory. folder_id:

  • "scripts" Returns the folder of the script being executed.
  • "batteries" Returns the folder containing the battery profiles.

Parameters:

Returns:

    string The path to the folder.

See also:

log(text, timestamp)
Write text to time synchronized log window.

This function will add a timestamped text to a log. The first time it is called, it will create a new log.

Note that a recording has to be running for this to produce any output.

Parameters:

  • text string Text to add to the log window.
  • timestamp int Optional timestamp in milliseconds since 1970-01-01. If omitted the current time will be used.

See also:

mkdir(path)
Make a directory.

Create a new directory.

Parameters:

  • path string The path to the folder to create
msleep(msec)
Suspend execution for a given time.

Wait for at least msec milliseconds before resuming.

Parameters:

  • msec int Time in milliseconds.

See also:

on_stop(function)
Add on stop handler The handler is called when the stop button is pressed (or CTRL-C is pressed when running otiicli), right before the script is terminated.

Parameters:

  • function The function to use as On Stop handler

See also:

run()
Run an event based application.

The application will enter an event loop, and will be running until stop is called. Before calling run, you need to add one or more event handlers.

See also:

set_message_handler(function)
Set message handler.

All application traces will be sent to this handler.

Parameters:

  • function The function to call.
stop()
Stop the event loop.

See also:

timestamp(format)
Get timestamp

Parameters:

  • format Optional argument to format the timestamp as a string. See the QDateTime documentation for information about the format string.

Returns:

    The current time as a string according to the format paramter. If no format parameters is given, milliseconds since 1970-01-01 is returned as an integer.
write(text)
Write text to output.

In the desktop app the text is shown in the scripting window, and in the console app it is printed to the standard output.

Parameters:

  • text string Text to write to the output.

See also:

writeln(text)
Write newline terminated text to output.

In the desktop app the text is shown in the scripting window, and in the console app it is printed to the standard output.

Parameters:

  • text string Text to write with a newline termination to the output.

See also:

Timer

create_timer(interval, callback)
Create a timer.

The provided callback will be called at the given interval. This requires that the application at some stage enters the event loop by calling run.

Parameters:

  • interval int Interval in milliseconds.
  • callback Timer callback.

Returns:

    Timer object.

See also:

timer:delete()
Delete a timer.

See also:

Local Server

create_local_server(servername, callback)
Create local server

The provided callback will be called when data is available. This requires that the application at some stage enters the event loop by calling run.

Parameters:

  • servername string The name of the local server
  • callback Data callback in the format function(data), where data is a string.

Returns:

    Server object, nil if unsuccessful.

See also:

server:close()
Close local server.

See also:

Project

create_project()
Create a new project.

Returns:

    project handle

See also:

get_active_project()
Return the active project.

If there is no active project, this function will return nil.

Returns:

    project handle

See also:

project:close()
Close an open project.

See also:

project:crop_data(start, end)
Crop all data.

Parameters:

  • start number From sample time in seconds.
  • end number To sample time in seconds.

Returns:

    Returns true if successful, otherwise (false, errormsg).
project:downsample_channel(device, channel, factor)
Downsample a channel.

Parameters:

  • device The capturing device.
  • channel string The channel name.
  • factor int Factor to downsample channel with.

Returns:

    Returns true if successful, otherwise (false, errormsg).
project:enable_main_power(enable)
Enable main power.

Enable or disable the power of all connected devices.

Parameters:

  • enable bool

See also:

project:get_channel_count(device, recording_id, channel)
Get channel count.

Get number of samples in a channel of a specified recording.

Parameters:

  • device The capturing device.
  • recording_id The id of the recording.
  • channel string The channel name.

Returns:

    int The number of samples for the specified channel.

See also:

project:get_channel_data(device, recording_id, channel, index, count, strip)
Get channel data.

Get samples from a specified channel of a specified recording.

Parameters:

  • device The capturing device.
  • recording_id The id of the recording.
  • channel string The channel name.
  • index int The index of the first sample to get.
  • count int The number of samples to get.
  • strip bool Optional argument to strip control codes from rx data, defaults to true. Set to false if you are getting any form of binary data.

Returns:

    A table of samples in the format {timestamp = xxx, sample = yyy). Timestamp is in seconds. Returns nil if index or count is less than 1. Returns an empty table if there isn't any data.

See also:

project:get_last_recording_id()
Get last recording id

Returns:

    Recording id

See also:

project:get_log_offset(device, recording_id, channel)
Get log offset in microseconds.

Parameters:

  • device The capturing device. Set to nil for imported logs.
  • recording_id The id of the recording.
  • channel string The channel name. For imported logs, use the log_id returned by import_log.

Returns:

    Returns {true, offset_in_us} if log exists, otherwise {false, undefined}
project:get_recording_offset(recording_id)
Get recording offset in microseconds.

Parameters:

  • recording_id The id of the recording.

Returns:

    Returns {true, offset_in_us} if recording exists, otherwise {false, undefined}
project:import_log(recording_id, filename, converter)
Import a log.

Parameters:

  • recording_id The id of the recording.
  • filename The path of the log to import.
  • converter The filename of the log converter to use, e.g. "adb.lua".

Returns:

    Returns {true, log_id} if recording exists, otherwise {false, undefined}
project:remove_recording(recording_id)
Remove a recording.

Parameters:

  • recording_id int Recording id

Returns:

    bool true if recording was deleted, false otherwise (invalid recording id)

See also:

project:rename_recording(recording_id, name)
Rename a recording.

Parameters:

  • recording_id int Recording id
  • name string The new name for the recording

Returns:

    bool true if recording was renamed, false otherwise (invalid recording id)
project:save(filename)
Save an open project.

Parameters:

Returns:

    Returns true if successful, otherwise false.

See also:

project:set_log_offset(device, recording_id, channel, offset)
Set log offset in microseconds.

Parameters:

  • device The capturing device. Set to nil for imported logs.
  • recording_id The id of the recording.
  • channel string The channel name. For imported logs, use the log_id returned by import_log.
  • offset The new offset to apply in microseconds.

Returns:

    bool Returns true if log exists, otherwise false.
project:set_recording_offset(recording_id, offset)
Set recording offset in microseconds.

Parameters:

  • recording_id The id of the recording.
  • offset The new offset to apply in microseconds.

Returns:

    bool Returns true if recording exists, otherwise false.
project:start()
Start a new recording.

See also:

project:stop()
Stop the current recording.

See also:

Otii Device

waitfor_device_added()
Wait for a new device to be connected.
waitfor_device_available()
Wait for any Otii device to be available.
get_devices(type, timeout)

Get a list of available devices.

Each device is a table with an id, name and type:

 {{
     id = "4523489B502348A55023489E85234033",
     name = "Arc-lab",
     type = "Arc",
 }, {
     id = "2223489B5023BB0454540E9E84526A54",
     name = "Arc-office 1",
     type = "Arc",
 }}

Parameters:

  • type string Type of device, typically "Arc"
  • timeout number Timeout for waiting for available devices in seconds

Returns:

    A list of available devices.
get_id(name)
Get id from name.

Parameters:

Returns:

    The id of the device
open_device(id)
Get a handle to an Otii device.

Parameters:

  • id string The id of the device

Returns:

    A handle to an Otii device

See also:

format_value(channel, value)
Converts a raw SI value into appropriate suffixed value. E.g. 0.00123 for the "mc" channel into 1.23mA.

Parameters:

  • channel string Channel to format. See device:enable_channel for a list of available channels.
  • value number Value to format, expected as a SI value (A, V, J etc.).

Returns:

    String with formatted value and unit. Or nil if arguments were invalid.
device:add_channel_filter(channel, filter)
Add a filter to a channel.

Parameters:

See also:

device:calibrate()
Calibrate Otii device.

Performs an internal calibration of the device.

Note that the output will be turned off while calibration is running.

device:calibrate_sense(pin)
Calibrate Arc Sense+/Sense-.

Performs calibration of the Arc Sense+/Sense- pins.

This will calibrate the Sense pin(s) to enable remote sensing (4wire). Make sure the main + terminal is connected to the pin(s) to be calibrated.

See the documentation for more information.

Parameters:

  • pin string "p" for + pin, "n" for - pin, "b" for both

Returns:

    string "ok" if successful, error string if not.
device:commit()
Commit Arc settings to non-volaile storage.

Commit calibration data and settings to non-volatile storage.

device:close()
Close handle to Otii device.

See also:

device:enable_4wire(enable)
Enable/disable 4-wire measurements using Sense+/-.

Parameters:

  • enable bool

See also:

device:enable_battery_profiling(enable)
Enable battery profiling.

This will start the discharge profiling of a connected battery.

Note: This request requires a battery toolbox license.

Parameters:

  • enable bool

See also:

device:enable_channel(channel, enable)

Enable channel.

The following channels are available:

  • mc: Main Current (A)
  • mv: Main Voltage (V)
  • ac: ADC Current (A)
  • av: ADC Voltage (V)
  • sp: Sense+ Voltage (V)
  • sn: Sense- Voltage (V)
  • vb: VBUS (V)
  • vj: DC Jack (V)
  • tp: Temperature (°C)
  • rx: UART logs (text)
  • i1: GPI1 (Digital)
  • i2: GPI2 (Digital)

In addition to above channels, two more channels are enabled automatically when their respective current channel is enabled:

  • me: Main Energy (J)
  • ae: ADC Energy (J)

Parameters:

See also:

device:enable_exp_port(enable)
Enable expansion port.

Parameters:

  • enable bool

See also:

device:enable_main(enable)
Enable/disable the main power of the device.

To enable/disable the main power of all devices use project:enable_main_power

Parameters:

  • enable bool
device:enable_5v(enable)
Enable +5V pin.

This command is not supported on 1.0 hardware revision.

Parameters:

  • enable bool

Returns:

    bool True if +5V pin was enabled successfully, false otherwise.

See also:

device:enable_uart(enable)
Enable UART.

Parameters:

  • enable bool

See also:

device:get_4wire()
Get the 4-wire measurement state.

Returns:

    string The current state, "cal_invalid", "disabled", "inactive" or "active".

See also:

device:get_adc_resistor()
Get ADC resistor.

Returns:

    number Resistor of the ADC port in Ω.

See also:

device:get_calibration(calibration_id)
Get calibration.

Parameters:

  • calibration_id string Which calibration value to return

Returns:

    string Calibration data

See also:

device:get_exp_voltage()
Get the voltage of the expansion port.

Returns:

    number Expansion port voltage in V.

See also:

device:get_gpi(Id)
Get the state of a GPI pin.

Parameters:

  • Id int of the GPI pin, 1 or 2.

Returns:

    bool The state of the GPI pin.

See also:

device:get_main_resistance()
Get the main internal resistance.

Returns:

    number The main internal resistance in Ω.

See also:

device:get_main_voltage()
Get the main voltage.

Returns:

    number The main voltage in V.

See also:

device:get_max_current()
Get the max allowed current.

Returns:

    number The max current in A.

See also:

device:get_range()
Get the current range.

Returns:

    string The current range, "low" or "high".

See also:

device:get_rx()
Get the state of the RX pin.

Returns:

    bool The state of the RX pin.
device:get_uart_baudrate()
Get the baudrate of the UART.

Returns:

    int The baudrate.

See also:

device:get_value(channel)
Get a value.

See device:enable_channel for a list of available channels.

Parameters:

Returns:

    int The value in A, V, °C.
device:get_version()
Get the version of the device.

Returns:

  1. string The hardware version.
  2. string The firmware version.
device:init()
Initialize the device.
device:led(ontime, offtime)
Set the LED.

If the offtime is omitted, the led will be turned on if ontime is anything but 0.

Parameters:

  • ontime int On-time in milliseconds.
  • offtime int Off-time in milliseconds (optional)

See also:

device:reset()
Enter DFU mode.

Caution, the only way to exit DFU mode is to upgrade the firmware. (a power cycle will not exit DFU)

device:set_adc_resistor(resistor)
Set the value of the shunt resistor for the ADC.

Parameters:

  • resistor number The ADC resistor in Ω (0.001 to 22Ω).

See also:

device:set_battery_profile(profile)
Set the battery profile.

Note: This request requires a battery toolbox license.

Parameters:

  • profile The battery profile as a list of {current = current in A or resistance = resistance in Ω or power = power in W, duration = duration in seconds}. Current range is 0 - 2.5A with a setting resolution of ~30uA Resistance range is 1mΩ - 1MΩ Power range is 1µW - 12.5W Duration range is 0.001 - 2Ms (24 days)
device:set_calibration(calibration_id, calibration_data)
Set calibration values.

Parameters:

  • calibration_id string Which calibration value to set
  • calibration_data string Calibration value to set

See also:

device:set_exp_voltage(voltage)
Set the voltage of the expansion port.

Parameters:

  • voltage number Voltage in V (1.2 - 5V)

See also:

device:set_gpo(port, enable)
Set the state of a GPO.

Parameters:

  • port int The index of the port, 1 or 2.
  • enable bool

See also:

device:set_main_current(current)
Set the main current.

Used when the Otii device is set in constant current mode.

Parameters:

  • current number Current in A, set to a negative value when profiling batteries.
device:set_main_resistance(Ohm)
Set the main internal resistance.

Parameters:

  • Ohm number Resistance in Ω (0.001 - 500Ω).

See also:

device:set_main_voltage(voltage)
Set the main voltage.

Used when the Otii device is set in constant voltage mode.

Parameters:

  • voltage number Voltage in V.

See also:

device:set_max_current(current)
Set the max allowed current.

When the current exceeds this value, the main power will cut off.

Parameters:

  • current number Max current in A.

See also:

device:src_cur_limit_enable(enable)
Enable voltage source current limit (CC) operation.

Parameters:

  • enable bool

Returns:

    bool True if operation was supported (Arc firmware dependent), false otherwise.

See also:

device:get_src_cur_limit_enabled()
Get current state of voltage source current limiting.

Returns:

    enabled

See also:

device:set_power_regulation(mode)
Set power regulation mode

Parameters:

  • mode string One of the following: "voltage", "current", "off"
device:set_range(range)
Set measurement range.

Parameters:

  • range string "low" or "high". "low" will enable auto-range, "high" will force the use of high-range.

See also:

device:set_tx(enabled)
Set TX pin high or low.

The TX pin can be used as a GPO when the UART is disabled.

Parameters:

  • enabled bool
device:set_uart_baudrate(baudrate)
Set UART baudrate.

Parameters:

  • baudrate int

See also:

device:wait_for_battery_data(timeout)
Wait for battery data.

Note: This request requires a battery toolbox license.

Parameters:

  • timeout Maximum timeout in ms. May time out earlier if an other Arc is returning battery data.

Returns:

    Battery data table, or nil if timed out. The table will contain "timestamp" in seconds, "iteration", "step", "voltage" at end of the current step and "discharge" in coulombs accumulating the total discharge of the battery since profiling start.
device:write_tx(data)
Write data to TX.

Parameters:

See also:

device:get_supplies()
Get a list of available supplies.

Returns a table where each entry key is the supply id and the value is a a table with a name and optional manufacturer + model:

{

 1 = {
     name = "Power box"
 },
 2 = {
     name = "CR2032-NoName",
     manufacturer = "NoName",
     model = "CR2032"
 }

}

Note: This request requires a battery toolbox license.

Returns:

    A list of available supplies.
device:set_supply(id, series, parallel)
Set power supply type.

Note: This request requires a battery toolbox license.

Parameters:

  • id
  • series Number of batteries in series (optional, defaults to 1)
  • parallel Number of batteries in parallel (optional, defaults to 1)

See also:

device:get_supply()
Get current power supply id.

Note: This request requires a battery toolbox license.

Returns:

    id

See also:

device:get_supply_series()
Get current number of simulated batteries in series.

Note: This request requires a battery toolbox license.

Returns:

    number of batteries
device:get_supply_parallel()
Get current number of simulated batteries in parallel.

Note: This request requires a battery toolbox license.

Returns:

    number of batteries
device:set_supply_used_capacity(capacity)
Set power supply used capacity.

Note: This request requires a battery toolbox license.

Parameters:

  • capacity in coulombs (multiply mAh by 3.6 to get C)
device:get_supply_used_capacity()
Get current power supply used capacity.

Note: This request requires a battery toolbox license.

Returns:

    capacity in coulombs (divide by 3.6 to get mAh)

See also:

device:set_supply_soc_tracking(enable)
Enable/disable power supply State of Charge tracking.

This will enable or disable whether the state of charge (used capacity) of the simulated battery will be updated when current is flowing in or out of it or if the state of charge will remain at the set level.

Note: This request requires a battery toolbox license.

Parameters:

  • enable bool
device:get_supply_soc_tracking()
Get current state of power supply State of Charge tracking.

Note: This request requires a battery toolbox license.

Returns:

    enabled

See also:

LXI

lxi_connect(address)
Connect to LXI device.

Parameters:

  • address string Address to LXI device.

Returns:

    LXI handle if successful, otherwise (nil, errormsg).

See also:

lxi:read()
Read current value from LXI device.

Returns:

    number Current value.

See also:

lxi:set(command)
Send a LXI command to device, without expecting a response.

Parameters:

  • command string The command to send.

Returns:

    bool True if successful, otherwise false.

See also:

lxi:get(command)
Send a LXI command to device, and return the result.

Parameters:

  • command string The command to send.

Returns:

    string The result from the command.

See also:

lxi:disconnect(LXI)
Disconnect from a LXI device.

Parameters:

See also:

generated by LDoc 1.4.6 Last updated 2021-10-13 21:46:39