ECU Diagnostics – part 14 : Software Framework mbe.py

This is hopefully a reasonably short post about the software framework I’ve developed to help read sensor data from the MBE 9A4 ECU.

The software is written in Python 3 and is available here: Caterham-OBD., however, I’m going to talk about using one file only which is mbe.py

The idea behind mbe.py is to “abstract” the setup and processing of requests and responses to an MBE 9A4 ECU and to provide a “human readable” set of results. The code implements the MBE-ISOTP protocol and can create multiple compound CAN bus requests and process multiple compound CAN bus responses. 

The code is implemented as a Python class with a few member functions to initialise the class and then send and process messages to the ECU.

There’s an example test program here.

The Programming Interface (API) to the code is as follows: 

mbe()

Creates an mbe class object with no parameters

set_options(vars_file, request_id, response_id, interface)

Sets the mbe options.

  • vars_file: A JSON encoded representation of the Easimap EC2 file. This is used to define all the variables the ECU can process. It also sets offset and scaling configurations for each of the variables. This file is created using ec2parse.py and the latest version of the JSON vars_file can be found at 9A4be52a.ec2.utf8.json.
  • request_id: This is the CAN bus ID needed to tell mbe.py what ID to use when making requests to the ECU. This parameter may be ignored and mbe.py will use the default 0x0cbe1101.
  • response_id: This is the CAN bus ID needed to tell mbe.py what ID to look for when receiving responses for the ECU. This parameter may be ignored and mbe.py will use the default 0x0cbe0111.
  • interface: defaults to can0
  • RETURN: Returns False is there was a problem setting these options

add_variable_list(list)

Adds a list of variables to the mbe class to be processed later.

  • list: an array of strings defining which ECU variables to request and process with process_all_pages()
  • RETURN: False if there is problem with the list, otherwise returns True

bind()

Opens and binds mbe.py to can-isotp kernel module.

  • RETURN: True

process_all_pages(results)

Processes all variables.

  • results: A dictionary indexed by the variable name string and supplying results, units, and human readable string for each variable.
  • RETURN: a dictionary of results, otherwise returns False if there’s a problem.

A simple example might be as follows:

ecu = mbe.mbe()
ecu.set_options("9A4be52a.ec2.utf8.json", 0x0cbe1101, 0x0cbe0111, "can0")
ecu.add_variable_list_to_follow([RT_ENGINESPEED])
ecu.bind()
ecu.process_all_pages(results)

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.