control_interface

class turboctl.ui.control_interface.Status(frequency: Optional[float] = None, temperature: Optional[float] = None, current: Optional[float] = None, voltage: Optional[float] = None, pump_on: Optional[bool] = None, status_bits: Optional[list] = None, callback: Optional[Callable] = None)

This class stores information about the current status of the pump.

The values are based on those reported by the pump; if a command is sent to the pump to set a value to X, the value stored here should only be changed once the pump has reported the new changed value.

Values of None indicate unknown values that the pump hasn’t reported yet.

frequency: Optional[float] = None

The stator frequency in Hz.

temperature: Optional[float] = None

The frequency converter temperature in °C.

current: Optional[float] = None

The motor current in A.

voltage: Optional[float] = None

The intermediate circuit voltage in V.

pump_on: Optional[bool] = None

Indicates whether the pump is on or off.

status_bits: Optional[list] = None

A list of the status conditions (StatusBits members) affecting the pump.

callback: Optional[Callable] = None

A function that is called every time the contents of this object are changed. Its signature should be

callback(status: Status) -> None

so that it can be called with

self.callback(self)

Note that since this isn’t a bound method, the self argument must be explicitly passed to the function.

__setattr__(name, value)

Call callback(self) whenever an attribute is set.

__eq__(other)

Return self==value.

__hash__ = None
__init__(frequency: Optional[float] = None, temperature: Optional[float] = None, current: Optional[float] = None, voltage: Optional[float] = None, pump_on: Optional[bool] = None, status_bits: Optional[list] = None, callback: Optional[Callable] = None) None
__repr__()

Return repr(self).

turboctl.ui.control_interface.SERIAL_KWARGS = {'baudrate': 19200, 'bytesize': 8, 'parity': 'E', 'port': '/dev/ttyACM0', 'stopbits': 1, 'timeout': 1}

Keyword arguments for creating a serial.Serial instance.

class turboctl.ui.control_interface.ControlInterface(port=None, auto_update=False)

This class represents a connection to the pump and can be used to send commands to it.

All methods that send commands to the pump return both the query sent to the pump and the reply received back as TelegramReader instances.

status

An object that stores the current state of the pump. Its attributes are updated every time the pump sends back a reply.

Type:

Status

timestep

If self was initialized with auto_update=True, this determines the time (in seconds) between automatic telegrams. The default value is 1.

Type:

int or float

on_command

If this is True, automatic telegrams send the pump_on() command to the pump instead of get_status().

See the auto_update argument of __init__() for further details.

The default value is None, which gets updated by the status() method to match the current state of the pump.

Type:

bool

__init__(port=None, auto_update=False)

Initialize a new ControlInterface.

Parameters:
  • port (str) – The device name for the serial port through which the connection is formed. If no value is given, the one defined in SERIAL_KWARGS is used.

  • auto_update (bool) –

    If this is True, this object will automatically send a telegram to the pump every timestep seconds and update status accordingly. Otherwise status will only be updated whenever a command is sent by the user calling a method of this class.

    If status.pump_on is True, the automatic telegram will be pump_on() instead of get_status(). This is to prevent the pump from automatically switching off, which it does if it hasn’t received a pump_on() command for 10 seconds.

__enter__()

Called upon entering a with block; returns self.

__exit__(exc_type, exc_value, traceback)

Called upon exiting a with block; calls close().

The arguments are ignored.

close()

Close the connection to the pump. If this object was created with auto_update=False, the parallel thread sending the update telegrams is also closed.

pump_on()

Turn the pump on.

This sets on_command to True.

pump_off()

Turn the pump off.

This sets on_command to False.

get_status(pump_on=None)

Ask pump status by sending an empty telegram.

If on_command is None, this updates its value to status.pump_on. This means that a pump that is on when TurboCtl is started stays on, and a pump that is off stays off.

reset_error()

Reset the error status of the pump.

read_parameter(number, index=0)

Read the value of an index of a parameter.

Parameters:
  • number – The number of the parameter.

  • index – The index of the parameter (0 for unindexed parameters).

Raises:

ValueError – If number or index have invalid values.

write_parameter(number, value, index=0)

Write a value to an index of a parameter.

Parameters:
  • number – The number of the parameter.

  • value – The value to be written.

  • index – The index of the parameter (0 for unindexed parameters).

Raises:

ValueError – If number, value or index have invalid values.