ECU
- class ecu.ECU(interface, retry=2, timeout=0.05, receive_timeout=75, i2c_address=20, custom_hardware=[])
Connect to an ECU.
- Parameters:
interface (Serial, str or SMBus) – the communication interface to use. If interface is of type Serial or str, communication via USB is used. If interface is of type ‘SMBus’, communication via I2C is used.
retry (int) – how many times a command should be resent if a transmission fails.
timeout (float) – how long to wait for a response to commands in seconds
receive_timeout (int) – delay between receiving ECU-P response and transmitting it over USB.
i2c_address (int) – the address to use for I2C communication.
custom_hardware (list of dicts) – definitions of additional custom hardware variants
- Raises:
ConnectionError – if communication with ECU fails
Attributes:
The UUID (serial number) of this ECU.
Same as
uuid
, legacy name for the 8 character long UUID.Product ID of this ECU.
The name of the firmware.
The version of the firmware.
The version of the firmware as tuple (major, minor).
Name of the serial port this ECU is connected to.
Is the device in bootloader mode?
The number of output current channels.
The minimum allowed output current.
The maximum allowed output current.
Get the current that is currently drawn from the power input.
Get the maximum allowed current that can be drawn from the power input.
Get the mode the ECU is currently in.
Should the ECU be measureing the resistance of disabled output channels?
Set the variable voltage source.
I2C transfer speed in kbit/s.
Methods:
reset
()Reset ECU.
enable
(channel)Enable a specific output current channel.
disable
(channel)Disable a specific output current channel.
Enable all output current channels.
Disable all output current channels.
toggle
(channel)Toggle a specific output current channel.
set_enabled
(channel, enabled)Set a specific output current channel to either enabled or disabled.
is_enabled
(channel)Get wether a specific output current channel is enabled or disabled.
get_setpoint
(channel)Get the current a specific output channel is set to.
set_setpoint
(channel, current)Set the current for a specific output channel.
get_current
(channel)Get the output current of a specific channel that is currently flowing.
get_voltage
(channel)Get the output voltage on the specific channel.
get_voltage_raw
(channel)Get the high and low side voltage of the specific output channel
get_resistance
(channel)Get the resistance value connected to a specicif channel.
get_channel_info
(channel)Get all changing values for this channel in one transaction.
get_digitaloutput
(channel)Get the value of a specific digital output channel.
set_digitaloutput
(channel, value)Set the value for a specific digital output channel.
get_analoginput
(channel)Get the voltage of a specific analog input channel.
get_digitalinput
(channel)Get the state of all associated digital inputs of a channel.
i2c_transfer
(address[, write_data, read_length])Write bytes (if any) and then read back bytes (if any) from an I2C peripheral.
Get a SMBus compatible object to be used for I2C communication.
- property uuid
The UUID (serial number) of this ECU. The UUID can also be found printed on the actual hardware.
- Type:
str
- property uuid_short
Same as
uuid
, legacy name for the 8 character long UUID.- Type:
str
- property product_id
Product ID of this ECU.
- Type:
int
- property firmware_name
The name of the firmware.
- Type:
str
- property firmware_version
The version of the firmware.
- Type:
str
- property firmware_version_tuple
The version of the firmware as tuple (major, minor).
- Type:
tuple(int, int)
- property serial_port
Name of the serial port this ECU is connected to. Empty if connected over I2C.
- Type:
str
- property bootloader_active
Is the device in bootloader mode?
- Type:
bool
- property channels
The number of output current channels.
- Type:
int
- property current_min
The minimum allowed output current.
- Type:
int
- property current_max
The maximum allowed output current.
- Type:
int
- reset()
Reset ECU. This is equal to turning the power off and on again.
- Returns:
None
- Raises:
ConnectionError – if communication with ECU fails
- enable(channel)
Enable a specific output current channel.
- Parameters:
channel (int) – channel number to enable
- Returns:
None
- Raises:
ConnectionError – if communication with ECU fails
If the ECU is in manual mode, the channel will stay enabled until manually disabled again.
If manual mode is not active, enableing a channel, triggers actions that are configured by the state machines.
- disable(channel)
Disable a specific output current channel.
- Parameters:
channel (int) – channel number to disable
- Returns:
None
- Raises:
ConnectionError – if communication with ECU fails
If the ECU is in manual mode, the channel will stay disabled until manually enabled again.
If manual mode is not active, disableing a channel, triggers actions that are configured by the state machines.
- enable_all()
Enable all output current channels.
- Returns:
None
- Raises:
ConnectionError – if communication with ECU fails
- disable_all()
Disable all output current channels.
- Returns:
None
- Raises:
ConnectionError – if communication with ECU fails
- toggle(channel)
Toggle a specific output current channel. If it is enabled, it will be disabled and vice versa.
- Parameters:
channel (int) – channel number to toggle
- Returns:
None
- Raises:
ConnectionError – if communication with ECU fails
- set_enabled(channel, enabled)
Set a specific output current channel to either enabled or disabled.
- Parameters:
channel (int) – channel number to set
enabled (bool) – value to set the channel to
- Returns:
None
- Raises:
ConnectionError – if communication with ECU fails
If the ECU is in manual mode, the channel will stay enabled/disabled until changed again.
If manual mode is not active, setting a channel to enabled/disabled, triggers actions that are configured by the state machines.
- is_enabled(channel)
Get wether a specific output current channel is enabled or disabled.
- Parameters:
channel (int) – channel number to get status from
- Returns:
status of the specific channel
- Return type:
bool
- Raises:
ConnectionError – if communication with ECU fails
- get_setpoint(channel)
Get the current a specific output channel is set to.
- Parameters:
channel (int) – channel number to get current for
- Returns:
current setpoint in mA of the specific channel
- Return type:
float
- Raises:
ConnectionError – if communication with ECU fails
- set_setpoint(channel, current)
Set the current for a specific output channel. This is only possible in manual mode.
- Parameters:
channel (int) – channel number to set current for
current (float) – current in mA to set the output channel to
- Returns:
None
- Raises:
ConnectionError – if communication with ECU fails
- get_current(channel)
Get the output current of a specific channel that is currently flowing.
- Parameters:
channel (int) – channel number to get current for
- Returns:
output current in mA of the specific channel
- Return type:
float
- Raises:
ConnectionError – if communication with ECU fails
- get_voltage(channel)
Get the output voltage on the specific channel.
- Parameters:
channel (int) – channel number to get voltage for
- Returns:
output voltage in V of the specific channel
- Return type:
float
- Raises:
ConnectionError – if communication with ECU fails
- get_voltage_raw(channel)
Get the high and low side voltage of the specific output channel
- Parameters:
channel (int) – channel number to get voltage for
- Returns:
high and low side voltage in V of the specific channel
- Return type:
tuple(float, float)
- Raises:
ConnectionError – if communication with ECU fails
- get_resistance(channel)
Get the resistance value connected to a specicif channel.
- Parameters:
channel (int) – channel number to get voltage for
- Returns:
resistance in Ohm on the specific channel
- Return type:
float
- Raises:
ConnectionError – if communication with ECU fails
- get_channel_info(channel)
Get all changing values for this channel in one transaction.
- Parameters:
channel (int) – channel number to get info for
- Returns:
Dictionary with the following keys:
enabled
(bool): True if the channel is enabled.setpoint
(float): Setpoint in mA.current
(float): Momentary output current in mA.voltage
(float): Momentary output voltage in V.voltage_p
(float): Momentary high sideoutput voltage in V.voltage_n
(float): Momentary log sideoutput voltage in V.resistance
(float): Momentary resistance on output in Ω.
- Return type:
dict
- Raises:
ConnectionError – if communication with ECU fails
- property input_current
Get the current that is currently drawn from the power input.
- Returns:
current in mA
- Return type:
float
- Raises:
ConnectionError – if communication with ECU fails
- property input_current_max
Get the maximum allowed current that can be drawn from the power input.
On ECUs powered from USB, this depends on the device (computer/wall plug) the ECU is connected to (value is set by the USB host).
- Returns:
maximum allowed current in mA
- Return type:
float
- Raises:
ConnectionError – if communication with ECU fails
- property manual_mode
Get the mode the ECU is currently in.
- Returns:
True if the ECU is in manual mode, False if not
- Return type:
bool
- Raises:
ConnectionError – if communication with ECU fails
- property always_measure_resistance
Should the ECU be measureing the resistance of disabled output channels?
- Returns:
True if the ECU is measuring the resistance of disabled channels, False if not
- Return type:
bool
- Raises:
ConnectionError – if communication with ECU fails
- get_digitaloutput(channel)
Get the value of a specific digital output channel.
- Parameters:
channel (int) – channel number to get digital output value for
- Returns:
value of the specific channel
- Return type:
int
- Raises:
ConnectionError – if communication with ECU fails
- set_digitaloutput(channel, value)
Set the value for a specific digital output channel. This is only possible in manual mode.
- Parameters:
channel (int) – channel number to set the digital output for
value – value (0 - 65535) to set the dgital output channel to
- Returns:
None
- Raises:
ConnectionError – if communication with ECU fails
- property voltagesource
Set the variable voltage source. If the voltage is set to 0, the voltage source will be disabled.
- Returns:
The output voltage of the voltage source in V.
- Return type:
float
- Raises:
ConnectionError – if communication with ECU fails
- get_analoginput(channel)
Get the voltage of a specific analog input channel.
- Parameters:
channel (int) – channel number to read
- Returns:
voltage in V of the specific channel
- Return type:
float
- Raises:
ConnectionError – if communication with ECU fails
- get_digitalinput(channel)
Get the state of all associated digital inputs of a channel.
- Parameters:
channel (int) – channel number to read
- Returns:
state of the digital inputs
- Return type:
int
- Raises:
ConnectionError – if communication with ECU fails
- property i2c_speed
I2C transfer speed in kbit/s.
- i2c_transfer(address, write_data=b'', read_length=0)
Write bytes (if any) and then read back bytes (if any) from an I2C peripheral.
- Parameters:
address (int) – I2C peripheral address
write_data (bytes or bytearray) – bytes to be written to I2C peripheral
read_length (int) – number of bytes to be read from the I2C peripheral
- Returns:
read bytes from I2C peripheral
- Return type:
bytes
- Raises:
ConnectionError – if communication with ECU fails
- i2c_get_smbus()
Get a SMBus compatible object to be used for I2C communication.
- Returns:
SMBus equivilant object for I2C communication
- Return type:
SMBus
- Raises:
ConnectionError – if communication with ECU fails