{"id":5192,"date":"2019-09-20T14:10:03","date_gmt":"2019-09-20T13:10:03","guid":{"rendered":"https:\/\/www.purplemeanie.co.uk\/?p=5192"},"modified":"2026-05-28T11:50:00","modified_gmt":"2026-05-28T10:50:00","slug":"ecu-diagnostics-part-14-software-framework-mbe-py","status":"publish","type":"post","link":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/20\/ecu-diagnostics-part-14-software-framework-mbe-py\/","title":{"rendered":"ECU Diagnostics &#8211; part 14 : Software Framework mbe.py"},"content":{"rendered":"\n<p>This is hopefully a reasonably short post about the software framework I&#8217;ve developed to help read sensor data from the MBE 9A4 ECU.<\/p>\n\n\n\n<p>The software is written in Python 3 and is available here: <a href=\"https:\/\/github.com\/Purplemeanie\/Caterham-OBD\">Caterham-OBD<\/a>. However, I&#8217;m going to talk about using one file only which is <a href=\"https:\/\/github.com\/Purplemeanie\/Caterham-OBD\/blob\/master\/mbe.py\">mbe.py<\/a>.&nbsp;<\/p>\n\n\n\n<p>The idea behind mbe.py is to &#8220;abstract&#8221; the setup and processing of requests and responses to an MBE 9A4 ECU and to provide a &#8220;human readable&#8221; set of results. The code implements the <a href=\"https:\/\/www.purplemeanie.co.uk\/index.php\/2019\/09\/20\/ecu-diagnostics-part-13-3-mbe-isotp\/\">MBE-ISOTP<\/a> protocol and can create multiple compound CAN bus requests and process multiple compound CAN bus responses.&nbsp;<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>There&#8217;s an example test program <a href=\"https:\/\/github.com\/Purplemeanie\/Caterham-OBD\/blob\/master\/TestECU.py\">here<\/a>.<\/p>\n\n\n\n<p>The Programming Interface (API) to the code is as follows:&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">mbe()<\/h4>\n\n\n\n<p>Creates an mbe class object with no parameters<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">set_options(vars_file, request_id, response_id, interface)<\/h4>\n\n\n\n<p>Sets the mbe options.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>vars_file:<\/strong> 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 <a href=\"https:\/\/github.com\/Purplemeanie\/Caterham-OBD\/blob\/master\/tools\/ec2parse.py\">ec2parse.py<\/a> and the latest version of the JSON vars_file can be found at <a href=\"https:\/\/github.com\/Purplemeanie\/Caterham-OBD\/blob\/master\/ec2\/9A4be52a.ec2.utf8.json\">9A4be52a.ec2.utf8.json<\/a>.<\/li><li><strong>request_id:&nbsp;<\/strong>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&nbsp;<span class=\"pl-c1\"><span class=\"pl-k\">0x<\/span>0cbe1101.<\/span><\/li><li><strong>response_id:<\/strong> 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 <span class=\"pl-c1\"><span class=\"pl-k\">0x<\/span>0cbe0111.<\/span><\/li><li><strong>interface:<\/strong>&nbsp;defaults to can0<\/li><li><strong>RETURN:<\/strong>&nbsp;Returns False is there was a problem setting these options<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">add_variable_list(list)<\/h4>\n\n\n\n<p>Adds a list of variables to the mbe class to be processed later.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>list<\/strong>: an array of strings defining which ECU variables to request and process with process_all_pages()<\/li><li><strong>RETURN<\/strong>: False if there is problem with the list, otherwise returns True<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">bind()<\/h4>\n\n\n\n<p>Opens and binds mbe.py to can-isotp kernel module.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>RETURN<\/strong>: True<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">process_all_pages(results)<\/h4>\n\n\n\n<p>Processes all variables.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>results<\/strong>: A dictionary indexed by the variable name string and supplying results, units, and human readable string for each variable.<\/li><li><strong>RETURN<\/strong>: a dictionary of results, otherwise returns False if there&#8217;s a problem.<\/li><\/ul>\n\n\n\n<p>A simple example might be as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ecu = mbe.mbe()\necu.set_options(\"9A4be52a.ec2.utf8.json\", 0x0cbe1101, 0x0cbe0111, \"can0\")\necu.add_variable_list_to_follow([RT_ENGINESPEED])\necu.bind()&lt;br>ecu.process_all_pages(results)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Introduces the Python mbe.py framework for sending requests to the Caterham MBE 9A4 ECU and formatting diagnostic responses into readable values.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[51,20],"tags":[58,66,34,60,62],"class_list":["post-5192","post","type-post","status-publish","format-standard","hentry","category-caterham-blog","category-ecu-diagnostics","tag-can-bus","tag-caterham","tag-ecu-diagnostics","tag-mbe","tag-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8yl38-1lK","jetpack-related-posts":[{"id":5086,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/16\/ecu-diagnostics-part-12-osi-7-layers-for-caterham-diagnostics\/","url_meta":{"origin":5192,"position":0},"title":"ECU Diagnostics &#8211; part 12 : OSI 7 Layers for Caterham Diagnostics","author":"John Martin","date":"September 16, 2019","format":false,"excerpt":"Maps the Caterham diagnostics stack onto the OSI model, from CAN bus hardware through MBE ISO-TP layers up to Python tooling and applications.","rel":"","context":"In &quot;ECU Diagnostics&quot;","block_context":{"text":"ECU Diagnostics","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/ecu-diagnostics\/"},"img":{"alt_text":"Layered diagram mapping the MBE ECU protocol stack to OSI layers and CAN bus.","src":"https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/ECU-OSI-Layers.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/ECU-OSI-Layers.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/ECU-OSI-Layers.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/ECU-OSI-Layers.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/ECU-OSI-Layers.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":4726,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/08\/31\/ecu-diagnostics-part-1-introduction\/","url_meta":{"origin":5192,"position":1},"title":"ECU Diagnostics &#8211; part 1 : Introduction","author":"John Martin","date":"August 31, 2019","format":false,"excerpt":"Introduction and index for the Caterham ECU diagnostics series, covering MBE ECU traffic, CAN bus, OBD-II, ISO-TP, test setup, protocol decoding, and supporting Python and Wireshark tooling.","rel":"","context":"In &quot;Caterham Blog&quot;","block_context":{"text":"Caterham Blog","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5112,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/20\/ecu-diagnostics-part-13-three-diagnostic-protocols-in-the-mbe-9a4-ecu\/","url_meta":{"origin":5192,"position":2},"title":"ECU Diagnostics &#8211; part 13 : Three Diagnostic Protocols in the MBE 9A4 ECU","author":"John Martin","date":"September 20, 2019","format":false,"excerpt":"Introduces the three diagnostic protocols found on the Caterham MBE 9A4 ECU: MBE-Broadcast, OBD-II, and the MBE ISO-TP protocol used by Easimap.","rel":"","context":"In &quot;Caterham Blog&quot;","block_context":{"text":"Caterham Blog","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4765,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/08\/31\/ecu-diagnostics-part-2-ecu-obd-and-can\/","url_meta":{"origin":5192,"position":3},"title":"ECU Diagnostics \u2013 part 2 : ECU, OBD and CAN","author":"John Martin","date":"August 31, 2019","format":false,"excerpt":"Explains the Caterham MBE 9A4 ECU, how it exposes diagnostic data, and how OBD and CAN bus concepts fit into the ECU diagnostics project.","rel":"","context":"In &quot;Caterham Blog&quot;","block_context":{"text":"Caterham Blog","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/"},"img":{"alt_text":"MBE 9A4 ECU module label on a purple background.","src":"https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/9A4.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":5038,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/15\/ecu-diagnostics-part-10-decoding-ec2-files\/","url_meta":{"origin":5192,"position":4},"title":"ECU Diagnostics &#8211; part 10 : Decoding EC2 Files","author":"John Martin","date":"September 15, 2019","format":false,"excerpt":"Starts decoding Easimap EC2 files so Caterham MBE ECU CAN bus responses can be translated into useful human-readable diagnostic values.","rel":"","context":"In &quot;Caterham Blog&quot;","block_context":{"text":"Caterham Blog","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5050,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/16\/ecu-diagnostics-part-11-logic-analyzer-on-the-can-bus\/","url_meta":{"origin":5192,"position":5},"title":"ECU Diagnostics &#8211; part 11 : Logic Analyzer on the CAN Bus","author":"John Martin","date":"September 16, 2019","format":false,"excerpt":"Uses a Saleae logic analyser on the CAN bus to validate Caterham MBE ECU diagnostic code and compare captured traffic with expected requests and responses.","rel":"","context":"In &quot;Caterham Blog&quot;","block_context":{"text":"Caterham Blog","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/"},"img":{"alt_text":"Saleae logic analyser connected to a Raspberry Pi PiCAN board on a purple mat.","src":"https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/img_2013.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/img_2013.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/img_2013.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/img_2013.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/img_2013.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/img_2013.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/5192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=5192"}],"version-history":[{"count":2,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/5192\/revisions"}],"predecessor-version":[{"id":11517,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/5192\/revisions\/11517"}],"wp:attachment":[{"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=5192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=5192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=5192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}