LogoLogo
qoitech.com
  • Welcome
  • Otii PRODUCT SUITE
    • Overview
      • What’s included
    • Otii hardware
      • Otii Arc Pro
      • Otii Ace Pro
    • Otii software
      • Otii 3 Desktop App
      • Otii Toolbox
        • Otii Battery Toolbox [BT]
        • Otii Automation Toolbox [AT]
  • Otii SETUP
    • Connecting Otii hardware
      • Otii hardware overview
        • Otii Arc Pro overview
        • Otii Ace Pro overview
      • Wiring up
        • Expansion Port
        • Measuring DUT
        • Measuring a subsystem
        • External power source
        • Capture UART logs
    • Installing Otii software
      • Windows 10/11 setup
      • macOS setup
      • Ubuntu setup
      • Raspberry Pi setup
    • Getting started
      • Account & licensing
        • Activation & Licensing
        • Managing Licenses
      • User interface overview
        • Main window layout
        • Keyboard navigation
      • Support resources
  • Otii 3
    • Settings overview
    • Working with projects
      • Project storage
      • Create a new project
      • Save & open a project
      • Import an Otii 2.0 project
      • Export recordings as CSV
    • Control
      • Otii Arc/Ace setup
      • General settings
      • Channels
      • UART
      • Firmware management
      • Calibration
    • Recordings
      • Recording management
      • Recording tools
      • Recording viewers
        • Analog
        • Digital
        • Log
    • Measurements
    • Battery life estimator
    • Otii Battery Toolbox
      • Battery emulation
      • Battery profiler
        • Getting started with battery profiling
      • Battery validation
      • Battery Model Parameters
    • Otii Automation Toolbox
      • Otii TCP Server
      • Otii 3 Desktop App
      • Otii Server
      • User management
    • Additional features
      • User management
      • Show monitor
      • Notifications
    • Online account manager
  • Advanced guides
    • Python scripting
    • C# scripting
    • Jenkins integration
  • HELP & FAQ
    • FAQ
      • Otii Arc Pro
      • Otii Ace Pro
    • Revision history
  • Legal information
    • Product safety
    • Liability disclaimer
Powered by GitBook
On this page
  • Installing the C# client
  • Start the TCP Server
  • Getting started
  • Handling projects
  • Configuring the project
  • Do a timed recording

Was this helpful?

Export as PDF
  1. Advanced guides

C# scripting

PreviousPython scriptingNextJenkins integration

Last updated 12 months ago

Was this helpful?

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 , or use one of the clients available at the Qoitech .

In this guide we will show you how to control Otii from a C# application using the .

Installing the C# client

The Otii TCP Client for C# is avaliable as a NuGet package from .

In Visual Studio, create a C#/.NET Framework project, right click on References in the Solution Explorer, and select Manage NuGet Packages....

In the NuGet Package Manager install OtiiTcpClient from the package source nuget.org. (If nuget.org not is listed as a package source, .

Start the TCP Server

You need to start the Otii TCP server before connecting to it.

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

Getting started

Make sure you have Otii running with the TCP server started, and an Arc connected to the computer without any devices connected to its main output.

We start with adding code to turn on and off the power of the Arc.

using System;
using System.Threading;
using Otii;

namespace Test {
    class Program {
        static void Main(string[] args) {
            // Calling Connect without parameters will connect to a local instance of Otii
            var client = new OtiiClient();
            client.Connect();

            // Create a local reference to the Otii property for convenience
            var otii = client.Otii;

            // Get a list of all Otii devices available
            var devices = otii.GetDevices();
            if (devices.Length == 0) {
                throw new Exception("No available devices");
            }

            // Get a reference to the first device in the list
            var arc = devices[0];

            // Turn on and off the power
            arc.SetMain(true);
            Thread.Sleep(2000);
            arc.SetMain(false);

            // Close the connection
            client.Close();
        }
    }
}

Run the program, and the Arc connected to your computer should turn on the power, and after a second turn it off again.

Handling projects

Before starting a measurement tou need to either create a project, connect to an already opened project, or open a previously saved project.

Here we connect to an open project if it exists, otherwise we create a new one.

            ...

            // Get a reference to the first device in the list
            var arc = devices[0];

            var project = otii.GetActiveProject();
            if (project == null) {
                project = otii.CreateProject();
            }

            ...

Configuring the project

Before measuring, we set the main output voltage, overcurrent protection., and we confiure and enable the UART.

Then we add the channels we want to records. In this case we enable Main Current (mc), Main Voltage (mv), UART logs (rx) and the digital input GPI1 (i1).

If you hover above the EnableChannel method in Visual Studio you can see what channels are available.

            ...

            var project = otii.GetActiveProject();
            if (project == null) {
                project = otii.CreateProject();
            }

            // Configuration
            arc.SetMainVoltage(3.3);
            arc.SetMaxCurrent(0.5);
            arc.EnableUart(true);
            arc.SetUartBaudrate(115200);
            arc.EnableChannel("mc", true);
            arc.EnableChannel("mv", true);
            arc.EnableChannel("rx", true);
            arc.EnableChannel("i1", true);

            ...

Do a timed recording

Replace the code in the section "Turn on and off the power" with the section Record shown below. You also need to add an constant in the main class defining the recording time.

        private const int RecordingTime = 30000;

        static void Main(string[] args)
        {
            ...

            // Record
            project.StartRecording();
            arc.SetMain(true);
            Thread.Sleep(RecordingTime);
            arc.SetMain(false);
            project.StopRecording();

            // Close the connection
            client.Close();
        }

You can find the at the Qoitech GitHub.

TCP Server API
Github
Otii TCP Client for C#
nuget.org
see here how to fix it
Automation Toolbox
Basic Measurment example