How to run automated measurements using Command Line Lua Interpreter
Lua scripting, an Otii premium feature, is very useful for automating iterative and time consuming power consumption measurements. It can be run through the Otii GUI, as which was showcased in this video. However, it can also be run through the command line Lua interpreter, otiicli, which is the topic of this blog post.
Let´s start with a simple, straightforward set-up of Otii and a Device Under Test (DUT). The only connections needed for this exercise are a USB cable from the PC to the Otii Arc, and power cables from Otii Arc to the DUT.
Down below you can find a Lua script that demonstrates basic usage of the Lua language, as well as some Otii specific techniques, e.g:
- passing command line arguments to the script
- setting parameters for the Otii device, like voltage, measurement channels etc
- printing messages to stdout
- starting and stopping a recording
- turning main power on and off
- delaying
- saving project
- exiting the script in a nice and clean manner
To run the script you should first make sure that you have your Premium license reserved, and that the Otii client SW is not running (else the Otii SW will lock out the script). Then invoke the script as follows:
$ otiicli otiicli_example.lua <iterations> <duration> <delay>
So what does the script do? When started, the Lua script checks for command line parameters and assigns them in the following order: 1st parameter is the number of iterations; 2nd parameter is duration of a recording in milliseconds; 3rd parameter is delay after each recording in milliseconds.
local iterations = tonumber(args[2]) local duration = tonumber(args[3]) local delay = tonumber(args[4])
Main voltage, maximal current, enabled channels and other important settings are also specified in Params section of the script. It is always a good idea to check these before starting.
local range = "low" local vmain = 3300 local imax = 700 local channels = {"mc", "mv"} local onoffdelay = 500
Then the script searches for the Otii device and sets its parameters.
local devices = otii.get_devices() assert(#devices > 0, "No Otii devices") local arc = otii.open_device(devices[1].id) assert(arc ~= nil, "No available Otii") arc:set_range(range) arc:set_main_voltage(vmain) arc:set_max_current(imax) for _, channel in ipairs(channels) do arc:enable_channel(channel, true) end
A new project is created each time a script runs, so copy your previously created project file otiicli_example.otii if you want to save it.
project = otii.create_project() assert(project ~= nil, "Unable to create project")
A small header is printed after that it displays the Otii version, the title of your test session and the parameters with their assigned values.
The main loop is rather self-explanatory but it is worth noting that good practice is to have recording mode already running at the moments when power is turned on or off. If you don’t, you’ll lose transitional processes that generate high spikes.
for i = 1, iterations do otii.writeln("Starting iteration " .. tostring(i)) otii.writeln("Will run for " .. tostring(duration) .. " msec") project:start() otii.msleep(onoffdelay) project:enable_main_power(true) otii.msleep(duration) project:enable_main_power(false) otii.msleep(onoffdelay) project:stop() otii.writeln("Delaying for " .. tostring(delay) .. " msec...") otii.msleep(delay) end
The script shown here can be used as a base to be modified for your own use, and there is more information to be found in the help section of the Otii SW, and in discussions on our forum.
The Qoitech Team
Downloads
Don’t want to miss any new tech content? Subscribe to our monthly newsletter!