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.- 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:
- timestep¶
If self was initialized with
auto_update=True
, this determines the time (in seconds) between automatic telegrams. The default value is1
.
- on_command¶
If this is
True
, automatic telegrams send thepump_on()
command to the pump instead ofget_status()
.See the auto_update argument of
__init__()
for further details.The default value is
None
, which gets updated by thestatus()
method to match the current state of the pump.- Type:
- __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 everytimestep
seconds and updatestatus
accordingly. Otherwisestatus
will only be updated whenever a command is sent by the user calling a method of this class.If
status.pump_on
isTrue
, the automatic telegram will bepump_on()
instead ofget_status()
. This is to prevent the pump from automatically switching off, which it does if it hasn’t received apump_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; callsclose()
.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
toTrue
.
- pump_off()¶
Turn the pump off.
This sets
on_command
toFalse
.
- get_status(pump_on=None)¶
Ask pump status by sending an empty telegram.
If
on_command
isNone
, this updates its value tostatus.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.