Python scripting

These features require an Automation Toolbox license.

Otii has a build in TCP Server that can be used to control the application from another application, e.g. from a script running in your C.I. environment.

You can write your own TCP client using the Otii TCP Server API, or use one of the clients available at the Qoitech Github.

In this guide we will show you how to control Otii from a Python application using the Otii TCP Client for Python.

You can find out more about how to get started with the TCP server here:

Installing the Python client

You can install the python client using pip:

python3 -m pip install otii_tcp_client

Running the TCP Server

You need to have Otii TCP Server running, either using the Otii desktop client or the Otii command line interface. You can read about it here:

For this example we also expect the server to be logged in, and that an Automation Toolbox licenses is already reserved. You can read more about logging in and reserving licenses here:

Automate measurements

Let us create a python script, e.g. otii_measurement.py. The first thing we need to do is include the Otii python client:

#!/usr/bin/env python3
import time
from otii_tcp_client import otii_client

The next step is to establish a connection with Otii TCP Server. Here we are assuming the TCP Server is running on the same computer and using the default TCP port.

client = otii_client.OtiiClient()
otii = client.connect()

After we are connected, we want to make sure that there is exactly on device connected to Otii, and get the handle to this device. We also make sure the device is added to the current project.

devices = otii.get_devices()
if len(devices) != 1:
    raise Exception(f'Expected to find exactly 1 device, found {len(devices)} devices')
device = devices[0]
device.add_to_project()

For this script we want to make one 10 second recording of the main channels of the Arc connected. We want each run to add the recording to the existing project, so that we later on can compare them.

project = otii.get_active_project()

Next step is to configure the Otii Arc/Ace for our project. In this case the device is normally running on a coin-cell battery, so we set the main voltage to 3.0. We want to use the high accuracy measurement (low range), and we want to measure the main current (mc) and the main voltage (mv).

device.set_main_voltage(3.0)
device.set_max_current(0.5)
device.enable_channel("mc", True)
device.enable_channel("mv", True)

Now we can start a recording, turn on the power and sleep for 10 seconds, and then turn off the power and stop the recording.

project.start_recording()
device.set_main(True)

time.sleep(10.0)

device.set_main(False)
project.stop_recording()

And finally we disconnect from Otii TCP Server.

otii.disconnect()

And that's it, a short script to automate recordings.

You find more examples here:

Last updated