{"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":"2025-01-31T13:08:06","modified_gmt":"2025-01-31T13:08:06","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>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. The software is written in Python 3 and is available here: Caterham-OBD. However, I&#8217;m going to talk about using one file only which is mbe.py.&nbsp; The idea behind mbe.py is to &#8220;abstract&#8221; [&hellip;]<\/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_post_was_ever_published":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}},"categories":[51,20],"tags":[34],"class_list":["post-5192","post","type-post","status-publish","format-standard","hentry","category-caterham-blog","category-ecu-diagnostics","tag-ecu-diagnostics"],"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":"Communications protocols are often called protocol stacks... they're layers, or stacks, of different protocols... one layered on top of the other from lowest level (hardware\/physical) to highest level (software application). This is where the OSI 7 Layer model comes in... it standardises how we think about the layers and allows\u2026","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":"","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":"So here we go for a marathon series of posts. I'll update this page with links to the completed posts as they come along... IntroductionECUs, OBD and CANTest SetupWireshark Patching and OBD-II ResultsThe Correlator Dead-EndReading MaterialECU Maps and MappingEasimap uses ISOTP (sort of)The Easimap Protocol TheoryDecoding EC2 FilesLogic Analyzer on\u2026","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":"This one's just a short post to introduce the next three posts. In our investigations of the MBE 9A4 ECU we've found three different diagnostics protocols supported on the OBD port. The following three posts will summarise what we've learnt about each protocol and will be updated with new information\u2026","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":"ECU Caterhams, like all modern cars, have an Engine Control Unit (ECU) - a black box full of electronics, controlled by a microprocessor that manages how the engine runs. \u00a0And because it has a microprocessor it means it runs some software to control everything. It also connects to a bunch\u2026","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":"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":5155,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/20\/ecu-diagnostics-part-13-3-mbe-isotp\/","url_meta":{"origin":5192,"position":4},"title":"ECU Diagnostics &#8211; part 13.3 : MBE-ISOTP","author":"John Martin","date":"September 20, 2019","format":false,"excerpt":"SUMMARY We now understand the communications protocol used by Easimap (the Windows software supplied by the ECU manufacturer) and can use it to ask the ECU for whatever data the car has to offer. We can then manipulate the responses we get back from the car and format them to\u2026","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":4769,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/01\/ecu-diagnostics-part-3-test-setup\/","url_meta":{"origin":5192,"position":5},"title":"ECU Diagnostics &#8211; part 3 : Test Setup","author":"John Martin","date":"September 1, 2019","format":false,"excerpt":"Ok, so we have an OBD port\/connector on our cars that connects directly to the ECU. How are we going to figure out how to talk the right communications protocols to the car to get at its internal data? We need a test rig to do some experiments with. If\u2026","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":"https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/Test-Setup-Diagram.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/Test-Setup-Diagram.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/Test-Setup-Diagram.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/Test-Setup-Diagram.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/Test-Setup-Diagram.png?resize=1050%2C600&ssl=1 3x"},"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":1,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/5192\/revisions"}],"predecessor-version":[{"id":10692,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/5192\/revisions\/10692"}],"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}]}}