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:

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 python
import sys
from otii_tcp_client import otii_connection, otii as otii_application

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.

HOSTNAME = '127.0.0.1'
PORT = 1905

connection = otii_connection.OtiiConnection(HOSTNAME, PORT)
connect_response = connection.connect_to_server()

if connect_response["type"] == "error":
    print("Exit! Error code: " + connect_response["errorcode"] + ", Description: " + connect_response["payload"]["message"])
    sys.exit()

otii = otii_application.Otii(connection)

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.

devices = otii.get_devices()
if len(devices) != 1:
    print("Expected to find exactly 1 device named {0}, found {1} devices".format(ARC_NAME, len(devices)))
    sys.exit()
arc = devices[0]

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 Arc 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).

arc.set_main_voltage(3.0)
arc.set_max_current(0.5)
arc.enable_channel("mc", True)
arc.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();
arc.set_main(True)

time.sleep(10.0)

arc.set_main(False)
project.stop_recording();

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

You find more examples here:

Last updated