neovi.ecu module

Provides the ECU class that represents an individual ECU.

Below is an example of reading values from an ECU. Note that it requires a network spec such as the one created in the example on the spec module page.

import neovi.neodevice as neodevice
import neovi.ecu as ecu
import neovi.spec as spec
import neovi.neovi as neovi
import json


neodevice.init_api()
dev = neodevice.find_devices(neovi.NEODEVICE_FIRE)[0]
dev.open()


input_file = open('vehicle.spec', 'rt')
data = json.load(input_file, object_hook=spec.from_json)

hvac = ecu.ECU(data['ECUs']['HVAC'], dev)

wanted_values = ['Blower Speed Output', 'External Ambient Temperature', 'Left Solar Radiation Sensor', 'Cabin Temperature']

for value_name in wanted_values:
    result = hvac.read_data_by_id(value_name)['value']
    print("%s = %.1f %s" % (value_name, result[0], result[1]))

dev.close()
exception CommandError(code)

Bases: Exception

An error response was received after sending a message on the bus.

exception NoResponseError

Bases: Exception

No response was received after sending a message on the bus.

class ECU(ecu_info, interface, auto_tester_present_on_auth=True, log_unhandled_messages=False)

Bases: object

Represents a vehicle ECU.

Parameters:
  • ecu_info (spec.ECU) – Details of the ECU (network, address…).
  • interface (neodevice.NeoDevice) – The neoVI device to use for communication.
  • auto_tester_present_on_auth (bool) – Should a “tester present” message be sent at a regular interval if successful authentication (by an external tool) is detected?
  • log_unhandled_messages (bool) – Should messages to this ECU that have no associated subscription be logged?
read_data_by_id(identifier)

Send a “Read Data By ID” message and return the response value(s). The return value will be a dictionary of decoded values if an identifier name or an identifier object is passed in, or the raw message bytes if an integer array is passed in.

Parameters:identifier – This may be one of three types of object/value: 1) the name of an identifier known to the spec.ECU that was passed to the constructor, 2) a spec.Identifier object, or 3) an array of integers specifying the identifier to read (e.g. [0x98, 0x05]).
io_control_by_id(identifier, value=0, control_type=<ControlType.ShortTermAdjustment: 3>)

Send a “IO Control By ID” message.

Parameters:
  • identifier – This may be one of three types of object/value: 1) the name of an identifier known to the spec.ECU that was passed to the constructor, 2) a spec.Identifier object, or 3) an array of integers specifying the identifier to read (e.g. [0x98, 0x05]). Note that due to limitations of the current implementation, the value will be assumed to correspond to the first signal defined for the identifier.
  • value (int) – The value to set the output to. Conversion of the value into the form required by the underlying signal will be performed here. Default = 0x00.
  • control_type (can.ControlType) – The type of control to apply. Default = SHORT_TERM_ADJUSTMENT.
diagnostic_session_control(session_type)

Send a “Diagnostic Session Control” message.

Parameters:session_type (can.SessionType) – The type of session to switch to.
security_access(subfunction, key=None)
send_tester_present()

Send a “Tester Present” message to avoid a diagnostic session timing out.

send_periodic_tester_present(interval=2)

Start sending a periodic “tester present” message to avoid a diagnostic session timing out. :param int interval: Period in seconds between messages.

stop_periodic_tester_present()

Stop sending the periodic “tester present” message.