otii_tcp_client
Otii TCP Client
arc
- class otii_tcp_client.arc.Arc(device_dict, connection)
- Class to define an Arc or Ace device.
Includes operations that can be run on the Arc or Ace.
- Attributes:
type (str): Device type, “Arc” for Arc devices. id (str): ID of the Arc device. name (str): Name of the Arc device. connection (:obj:OtiiConnection): Object to handle connection to the Otii server.
- add_to_project()
Add device to current project.
- calibrate()
Perform internal calibration of an Arc device.
- enable_5v(enable)
Enable or disable 5V pin.
- Args:
enable (bool): True to enable 5V, False to disable.
- enable_battery_profiling(enable)
This will start the discharge profiling of a connected battery.
- Args:
enable (bool): True to start battery profiling, False to stop.
- enable_channel(channel, enable)
Enable or disable measurement channel.
- Args:
channel (str): Name of the channel to enable or disable. enable (bool): True to enable channel, False to disable.
- enable_exp_port(enable)
Enable expansion port.
- Args:
enable (bool): True to enable expansion port, False to disable.
- enable_uart(enable)
Enable UART.
- Args:
enable (bool): True to enable UART, False to disable.
- firmware_upgrade(filename=None)
Initiate device firmware update.
- Args:
filename (str, optional): Firmware filename.
- get_4wire()
Get the 4-wire measurement state.
- Returns:
str: The current state, “cal_invalid”, “disabled”, “inactive” or “active”.
- get_adc_resistor()
Get adc resistor value.
- Returns:
float: ADC resistor value (Ohm).
- get_channel_samplerate(channel)
Get channel sample rate.
- Args:
channel (str): Name of the channel to get the sample rate for.
- Returns:
int: Sample rate for channel
- get_exp_voltage()
Get the voltage of the expansion port.
- Returns:
float: Voltage value on the expansion port (V).
- get_gpi(pin)
Get the state of one of the GPI pins.
- Args:
pin (int): ID of the GPI pin to get state of, 1 or 2.
- Returns:
bool: State of the GPI pin.
- get_main()
Get the state of the main power.
- Returns:
bool: State of the main power.
- get_main_voltage()
Get main voltage value.
- Returns:
float: Main voltage value (V).
- get_max_current()
Get the max allowed current.
- Returns:
float: Value max current is set to (A).
- get_range()
Get the current measurement range on the main output.
- Returns:
str: Current measurement range mode on main, “low” or “high”.
- get_rx()
The RX pin can be used as a GPI when the UART is disabled.
- Returns:
bool: State of the RX pin.
- get_src_cur_limit_enabled()
Get current state of voltage source current limiting.
- Returns:
bool: True if set to constant current, false if set to cut-off.
- get_supply_mode()
Get current supply mode
- Returns:
string: “power-box” or “battery-emulator”
- get_uart_baudrate()
Get the UART baud rate.
- Returns:
int: Value UART baud rate is set to.
- get_value(channel)
Get value from specified channel. This is not available for the rx channel.
- Args:
channel (str): Name of the channel to get value from.
- Returns:
float: Present value in the channel (A/V/°C/Digital).
- get_version()
Get hardware and firmware versions of device.
- Returns:
dict: Dictionary including keys hw_version (str) and fw_version (str).
- is_connected()
Check if a device is connected.
- Returns:
bool: True if device is connected, False otherwise.
- set_4wire(enable)
Enable/disable 4-wire measurements using Sense+/-.
- Args:
enable (bool): True to enable 4-wire, false to disable
- set_adc_resistor(value)
Set the value of the shunt resistor for the ADC.
- Args:
value (float): Value to set ADC resistor to, value should be between 0.001-22 (Ohm).
- set_battery_profile(value)
Set the battery profile.
- Args:
value (list): The list of battery profile step dicts (max 10). Each dict is of the { “current|resistance|power” : SI value, “duration” : seconds } form.
- set_channel_samplerate(channel, value)
Set the sample rate of a channel
- Args:
channel (str): Name of the channel to set the sample rate for. value (int): The sample rate to set
- set_exp_voltage(value)
Set the voltage of the expansion port.
- Args:
value (float): Value to set expansion port voltage to, value should be between 1.2-5 (V).
- set_gpo(pin, value)
Set the state of one of the GPO pins.
- Args:
pin (int): ID of the GPO pin to set state of, 1 or 2. value (bool): True to enable GPO output, False to disable.
- set_main(enable)
Turn on or off main power on a device.
- Args:
enable (bool): True to turn on main power, False to turn off.
- set_main_current(value)
Set the main current on Arc. Used when the Otii device is set in constant current mode.
- Args:
value (float): Current to set in (A).
- set_main_voltage(value)
Get data entries from a specified channel of a specific recording.
- Args:
value (float): Value to set main voltage to (V).
- set_max_current(value)
When the current exceeds this value, the main power will cut off.
- Args:
value (float): Value to set max current to, value should be between 0.001-5 (A).
- set_power_regulation(mode)
Set power regulation mode.
- Args:
mode (float): One of the following: “voltage”, “current”, “off”.
- set_range(range)
Set the main outputs measurement range.
- Args:
range (str): Current measurement range mode to set on main. “low” enables auto-range, “high” force high-range.
- set_src_cur_limit_enabled(enable)
Enable voltage source current limit (CC) operation.
- Args:
enable (bool): True means enable constant current, false means cut-off.
- set_supply_battery_emulator(battery_profile_id, *, series=1, parallel=1, used_capacity=None, soc=None, soc_tracking=True)
Set power supply to battery emulator.
It is only possible to set one of used_capacity and soc. If neither is set, used_capacity is set to 0, and soc to 100.
- Args:
battery_profile_id (string): Id of battery profile, as returned by otii.get_battery_profiles. series (int, optional): Number of batteries in series, defaults to 1. parallel (int, optional): Number of batteries in parallel, defaults to 1. used_capacity (int, optional): Used capacity, defaults to 0. soc (int, optional): State of Charge, defaults to 100. soc_tracking (bool, optional): State of Charge tracking, defaults to True.
- Returns:
battery_emulator(:obj:BatteryEmulator): Battery emulator
- set_supply_power_box()
Set power supply to power box.
- set_tx(value)
The TX pin can be used as a GPO when the UART is disabled.
- Args:
value (bool): True to enable TX output, False to disable.
- set_uart_baudrate(value)
Set UART baud rate.
- Args:
value (int): Value to set UART baud rate to.
- wait_for_battery_data(timeout)
Wait for battery data.
- Args:
timeout (int): Maximum timeout in ms. May time out earlier if another Arc is returning battery data.
- Returns:
- dict: Battery data dict or None if timeout. The dict will contain “timestamp” in seconds,
“iteration”, “step”, “voltage” at the end of the current step and “discharge” in coulombs accumulating the total discharge of the battery since profiling start.
- write_tx(value)
Write data to TX.
- Args:
value (str): Data to write to TX.
otii
- class otii_tcp_client.otii.Otii(connection=None)
Class to define an Otii object.
- Attributes:
connection (:obj:OtiiConnection): Object to handle connection to the Otii server.
- connect(*, host='127.0.0.1', port=1905, try_for_seconds=10)
Connect to Otii.
- Args:
host (str): Server address. port (int): Connection port number. try_for_seconds (int): Seconds to try to connect.
- Returns:
dict: Decoded JSON connection response.
- create_project()
Create a new project.
- Returns:
int: ID of created project.
- get_active_project()
Returns the active project if there is one.
- Returns:
- obj:Project:
Project object.
- get_battery_profile_info(battery_profile_id)
Returns informatiion about a battery profile.
- Args:
battery_profile_id (string): Battery profile id.
- get_battery_profiles()
Returns a list of available battery profiles.
- Returns:
list: List of battery profile objects
- get_device_id(device_name)
Get device id from device name.
- Args:
device_name (str): Name of device to get ID of.
- Returns:
str: Device ID of requested device.
- get_devices(timeout=10, devicefilter=None)
Get a list of connected devices.
- Args:
timeout (int, optional): Timeout in seconds to wait for avaliable devices. devicefilter (tuple, optional): Override default device filter
- Returns:
list: List of Arc device objects.
- get_licenses()
Return a list of all licenses for logged in user
- Returns:
list: List of licenses
[{ "id":1234, "type":"Pro", "available":true, "reserved_to":"", "hostname":"", "addons":[{ "id":"Automation", "attributes":null }] }]
- login(username, password)
Login user
- Args:
username: Name of Otii user password: Password of Otii user
- logout()
Logout user
- open_project(filename, force=False, progress=False)
Open an existing project.
- Args:
filename (str): Name of project file. force (bool, optional): True to open even if unsaved data exists, False not to. progress (bool, optional): True to receive notifications about progress of opening file, False not to.
- Returns:
int: ID of opened project.
- reserve_license(license_id)
Reserve license
- Args:
license_id (int): The license id to reserve.
- return_license(license_id)
Return license
- Args:
license_id (int): The license id to return.
- set_all_main(enable)
Turn on or off the main power on all connected devices.
- Args:
enable (bool): True to turn on main power, False to turn off.
- shutdown()
Shutdown Otii
otii_connection
- exception otii_tcp_client.otii_connection.DisconnectedException
- class otii_tcp_client.otii_connection.OtiiConnection(address, port)
Class to define the server connection handler
- Attributes:
host_address (str): Server IP address. host_port (int): Connection port number. recv_buffer (int): Size of receive buffer. sock (socket): Communication socket.
- close_connection()
Close connection to server.
- connect_to_server(*, try_for_seconds=0)
Connect to server.
- Args:
try_for_seconds (int): Seconds to try to connect.
- Returns:
dict: Decoded JSON connection response.
- receive_response(timeout_seconds, trans_id)
Receive a JSON formated response from the server.
- Args:
timeout_seconds (int): Transmission timeout (s). trans_id (str): ID of transmission.
- Returns:
dict: Decoded JSON server response.
- send(request)
Send request without waiting for response.
- send_and_receive(request, timeout=3)
Send request and receive response from server.
- Args:
message (str): JSON encoded server request. timeout (int, optional): Transmission timeout (s), default 3s.
- Returns:
dict: Decoded JSON server response.
- send_request(message)
Send request to server.
- Args:
message (str): JSON encoded server request.
otii_exception
- exception otii_tcp_client.otii_exception.Otii_Exception(response)
Class to define an Otii Exception object
- Attributes:
type (str): Error code type. message (str): Human readable error message.
project
- class otii_tcp_client.project.Project(id, connection)
Class to define an Otii Project object.
- Attributes:
id (int): ID of project. connection (:obj:OtiiConnection): Object to handle connection to the Otii server.
- close(force=False)
Close the project.
- Args:
force (bool, optional): True to force close, e.g. ignore unsaved data warning, False to not override warnings.
- crop_data(start, end)
Crop all data before start and after end.
- Args:
start (float): From sample at time start (s). end (float): To sample at time end (s).
- get_last_recording()
Get the latest recording in the project.
- Returns:
- obj:Recording:
Recording Object.
- get_recordings()
List captured recordings.
- Returns:
list: List of recording objects.
- save(progress=False)
Save the project.
- Args:
progress (bool, optional): True to receive notifications about save progress, False to not receive any notifications.
- Returns:
str: Name of saved file.
- save_as(filename, force=False, progress=False)
Save the project as.
- Args:
filename (str): Name of project file. force (bool, optional): True to overwrite existing file, False to not overwrite. progress (bool, optional): True to receive notifications about save progress, False to not receive any notifications.
- Returns:
str: Name of saved file.
- start_recording()
Start a new recording.
- stop_recording()
Stop the running recording.
recording
- class otii_tcp_client.recording.Recording(recording_dict, connection)
Class to define an Otii Recording object.
- Attributes:
id (int): ID of the recording. name (string): Name of the recording. start_time (datetime.datetime): Start of the recording or None if unsupported by TCP server. connection (:obj:OtiiConnection): Object to handle connection to the Otii server.
- delete()
Delete the recording.
- downsample_channel(device_id, channel, factor)
Downsample the recording on a channel.
- Args:
device_id (str): ID of device capturing the data. channel (str): Name of the channel to downsample. factor (int): Factor to downsample with.
- get_channel_data(device_id, channel, index, count, strip=True)
Get data entries from a specified channel of a specific recording.
- Args:
device_id (str): ID of device to get data from. channel (str): Name of the channel to get data from. index (int): Start position for fetching data, first value at index 0. count (int): Number of data entries to fetch. strip (bool): Strip control data from log channel, defaults to True.
- Returns:
- obj:data:
- get_channel_data_count(device_id, channel)
Get number of data entries in a channel for the recording.
- Args:
device_id (str): ID of device to get data from. channel (str): Name of the channel to get data from.
- Returns:
int: Number of data entries in the channel.
- get_channel_data_index(device_id, channel, timestamp)
Get the index of a data entry in a channel for a specific recording for a given timestamp.
- Args:
device_id (str): ID of device to get data from. channel (str): Name of the channel to get data from. timestamp (float): Timestamp to get index of in seconds (s).
- Returns:
int: Index of data entry at the timestamp.
- get_channel_info(device_id, channel)
Get information for a channel in the recording.
- Args:
device_id (str): ID of device to get info from. channel (str): Name of the channel to get info from.
- Returns:
- obj:data:
Info
- get_channel_statistics(device_id, channel, from_time, to_time)
Get statistics for a channel in the recording.
- Args:
device_id (str): ID of device to get data from. channel (str): Name of the channel to get data from. from_time (float): Selection start in seconds. to_time (float): Selection end in seconds.
- Returns:
- obj:data:
Statistics
- get_log_offset(device_id, channel)
Get the offset of an log
- Args:
device_id (str): ID of the capturing device. Set to None for imported logs. channel (str): The channel name. For imported logs, set to log_id returned by import_log.
- Returns:
int: The offset of the log
- get_offset()
Get the offset of the recording
- Returns:
int: The offset of the recording
- import_log(filename, converter)
Import log into recording.
- Args:
filename (str): Path to log to import. converter (str): Name of the llog converter to use.
- Returns:
log_id (str): Id of the log.
- is_running()
Check if recording is ongoing.
- Returns:
bool: True is recording is ongoing, False if stopped.
- log(text, timestamp=0)
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.
- Args:
name (str): Text to add to the log window. timestamp (int): Timestamp in milliseconds since 1970-01-01. If omitted the current time will be used.
- rename(name)
Change the name of the recording.
- Args:
name (str): New name of recording.
- set_log_offset(device_id, channel, offset)
Set the offset of an log
- Args:
device_id (str): ID of the capturing device. Set to None for imported logs. channel (str): The channel name. For imported logs, set to log_id returned by import_log. offset (int): The new offset to apply in microseconds.
- set_offset(offset)
Set the offset of the recording
- Args:
offset (int): The new offset to apply in microseconds.
battery_emulator
- class otii_tcp_client.battery_emulator.BatteryEmulator(battery_emulator_id, connection)
Class to define a Battery Emulator object.
- Attributes:
id (string): Id of the battery emulator. connection (:obj:OtiiConnection): Object to handle connection to the Otii server.
- get_parallel()
Get current number of emulated batteries in parallel.
- Returns:
int: Number of batteries in parallel.
- get_series()
Get current number of simulated batteries in series.
- Returns:
int: Number of batteries in series.
- get_soc()
Get State of Charge.
- Returns:
float: State of charge in percent.
- get_soc_tracking()
Get current state of battery emulator State of Charge tracking.
- Returns:
bool: True if State fo Charge tracking is enabled, False if disabled.
- get_used_capacity()
Get current battery emulator used capacity.
- Returns:
float: Used capacity in coulomb (C).
- set_soc(value)
Set State of Charge.
- Args:
value (float): State of charge in percent
- set_soc_tracking(enable)
Set State of Charge tracking.
- Args:
enable (bool): True to enable State of Charge tracking, False to disable.
- set_used_capacity(value)
Set used capacity.
- Args:
value (float): Capacity used in coulombs (C), multiply mAh by 3.6 to get C.
- update_profile(battery_profile_id, mode)
Update battery profile.
- Args:
battery_profile_id (string): Id of battery profile, as returned by otii.get_battery_profiles. mode (string): “keep_used_capacity” or “keep_soc”