CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (2024)

  • Report this article

Gurajapu Raja Sumant CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (1)

Gurajapu Raja Sumant

Works in development of embedded systesms software using C/C++ for products such as PTC HVAC,EV chargers, etc. ISO26262,UDS, OBD. Located in South Korea

Published Mar 9, 2023

+ Follow

What is an MF4 file (aka MDF4) - and why is it key to CAN bus data logging?

The ASAM MDF (Measurement Data Format) is a binary file format for recording e.g. CAN, CAN FD, and LIN bus data. Today, the MDF format is the industry standard - ensuring interoperability across many CAN tools. If you work in the automobile industry, companies share CAN/LIN debug logs in the form of mf4 files.

There are 6 benefits behind using the mf4 format. They are:

1) It can be used across various CAN tools.

2) It can support lossless recording at faster data rates e.g. CAN FD.

3) Reading from the file iaster since it is index based.

4) It is compressible which means large amount of data can be stored with a minimal space.

5) It supports both RAW and physical values. Hence it is quite useful.

6) Supported by python and matlab.

The following is the hierarchy and physical order of mdf4 file format -

https://i.stack.imgur.com/giolp.png

If you have a license for CANalyzer then you can be using it to read the mf4 files.

This article discusses the use of a python based package to read and analyze mf4 files.

Installation:

pip install asammdf[gui] 

Using the python API, you can read and analyze the mf4 files. Here is an example of how it is done.

Recommended by LinkedIn

Effortless Insights: Exploring Automatic EDA with… Venugopal Adep 9 months ago
Python Data Structure and Algorithm (DSA), Big O… Belayet Hossain 📈 1 year ago
How to Speed Up PTV Visum Models by Running… David Aspital 3 years ago

API usage

from asammdf import MDF, Signal #import asammdf f_in = input ("Enter Input MDF4 FIle :") mdf = MDF(f_in) #read mf4 data f_out = f_in.replace(".MF4", ".csv") mdf.export(fmt='csv', filename= f_out) #write to csv 

GUI tool

Here I have downloaded an example CAN DBC file (sourced from openly available sources of the internet) of electric vehicles to decode the information of battery SoC percentage of popular EV's like Hyundai Kona and Kia.

CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (5)
CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (6)

This is quite useful in achieving things that target improving the quality of our automotive product or building a new one from the data that is collected.

CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (7)
CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (8)

You can also use cantools python package to read the DBC file-

https://cantools.readthedocs.io/en/latest/pip install cantools 
import cantoolsfrom pprint import pprintdb = cantools.database.load_file(r'C:...dbc',strict=False) 
db.message[message('Battery', 0x7ec, False, 62, None), message('Temperature', 0x7bb, False, 54, None), message('Tire', 0x7a8, False, 64, None), message('gnss_pos', 0x3, False, 8, {None: 'GNSS position'}), message('gnss_time', 0x2, False, 6, {None: 'GNSS time'}), message('gnss_attitude', 0x5, False, 8, {None: 'GNSS attitude'}), message('gnss_odo', 0x6, False, 8, {None: 'GNSS odometer'}), message('gnss_status', 0x1, False, 1, {None: 'GNSS information'}), message('gnss_altitude', 0x4, False, 4, {None: 'GNSS altitude'}), message('gnss_geofence', 0x8, False, 2, {None: 'GNSS geofence(s)'}), message('gnss_speed', 0x7, False, 5, {None: 'GNSS speed'}), message('gnss_imu', 0x9, False, 8, {None: 'GNSS IMU'}), message('gnss_pos', 0x13, False, 8, {None: 'GNSS position'}), message('gnss_time', 0x12, False, 6, {None: 'GNSS time'}), message('gnss_attitude', 0x15, False, 8, {None: 'GNSS attitude'}), message('gnss_odo', 0x16, False, 8, {None: 'GNSS odometer'}), message('gnss_status', 0x11, False, 1, {None: 'GNSS information'}), message('gnss_altitude', 0x14, False, 4, {None: 'GNSS altitude'}), message('gnss_geofence', 0x18, False, 2, {None: 'GNSS geofence(s)'}), message('gnss_speed', 0x17, False, 5, {None: 'GNSS speed'}), message('gnss_imu', 0x19, False, 8, {None: 'GNSS IMU'})]s 

However, this can be done with a free 3rd party tool, Vector CANdb++ editor:

Vector CANdb++ editor is installed with the demo version of CANalyzer / CANoe, which can be downloaded from the Vector website:

Like
Comment

23

1 Comment

Patrick Wijnen

Experienced Engineer at Signify

8mo

  • Report this comment

very usefull, thanks for sharing!

Like Reply

1Reaction 2Reactions

To view or add a comment, sign in

More articles by Gurajapu Raja Sumant

  • What is the difference between QM and ASIL A/B in ISO26262 functional safety?

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (17)

    Aug 17, 2024

    What is the difference between QM and ASIL A/B in ISO26262 functional safety?

    ISO26262 is a standard for passenger vehicles which addresses possible hazards caused by malfunctioning behaviour of…

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (18) 5

  • Embedded Linux: Start an executable as a service using daemon

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (19)

    Aug 13, 2024

    Embedded Linux: Start an executable as a service using daemon

    Embedded linux usually has code running in the application space apart from Kernel space. As an embedded developer…

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (20) 10

  • Reed-solomon codes and its use in (automotive) ethernet for error correction.

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (21)

    Jun 23, 2024

    Reed-solomon codes and its use in (automotive) ethernet for error correction.

    It is common for digital signals to encounter noise and get corrupted. An automobile is a very noisy environment…

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (22) 9

  • History and basics of vision guided autonomous vehicles (ADAS and ALVINN)

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (23)

    Apr 17, 2024

    History and basics of vision guided autonomous vehicles (ADAS and ALVINN)

    SAE(Society of Automotive Engineers) classifies self driving vehicles as per the standard J3016. According to this…

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (24) CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (25) 16

    1 Comment

  • Quick sort algorithm in C++ [Tested on STM32 freertos]

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (26)

    Mar 24, 2024

    Quick sort algorithm in C++ [Tested on STM32 freertos]

    In one of my previous articles, I have proposed to build a quick sort library in c++ that can be used in embedded…

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (27) CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (28) 8

    1 Comment

  • EV battery - Why charging a Li ion battery is quite different from Ni-Cd battery?

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (29)

    Mar 5, 2024

    EV battery - Why charging a Li ion battery is quite different from Ni-Cd battery?

    Understanding trickle charging of both the battery technologies.

    The technology of Li - ion battery…

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (30) 16

  • Websockets development in C++ using concepts of ASIO, networking TS and Boost beast library.

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (31)

    Feb 20, 2024

    Websockets development in C++ using concepts of ASIO, networking TS and Boost beast library.

    Introduction

    OCPP is usually implemented using a component known as websockets. It is basically an extension…

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (32) CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (33) CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (34) 15

    3 Comments

  • Threadsafe Memory allocations in FreeRTOS: Static and dynamic

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (35)

    Feb 7, 2024

    Threadsafe Memory allocations in FreeRTOS: Static and dynamic

    Dynamic memory allocation in C/C++ can be done using malloc/calloc functions.

    When we are done using the…

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (36) CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (37) 12

  • Sorting in embedded systems: Why "Quick sort" is not the perfect algorithm for an embedded system?

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (38)

    Jan 28, 2024

    Sorting in embedded systems: Why "Quick sort" is not the perfect algorithm for an embedded system?

    In my previous articles,…

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (39) 9

    2 Comments

  • Copy of CAN/LIN power supply (KL-30/31) cable wiring as per Automotive standard DIN 72552

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (40)

    Dec 30, 2023

    Copy of CAN/LIN power supply (KL-30/31) cable wiring as per Automotive standard DIN 72552

    DIN 72552 is a standard used by component(Tier 1/2) and vehicle manufacturers(OEM's) when creating an automotive…

    CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (41) 5

See all articles

Sign in

Stay updated on your professional world

Sign in

By clicking Continue to join or sign in, you agree to LinkedIn’s User Agreement, Privacy Policy, and Cookie Policy.

New to LinkedIn? Join now

Insights from the community

  • Programming What are the most effective algorithms for real-world problems?
  • Data Visualization How can you clean negative values in a logarithmic scale bar chart?
  • Statistical Data Analysis How do you implement hierarchical and multilevel models in Stan and what are the benefits and challenges?
  • Data Science What are the most effective methods for network analysis?
  • Machine Learning What are the most effective methods to smooth time series data?
  • Data Engineering How can you implement a trie for efficient string search?
  • Critical Thinking How can R help you analyze data more effectively?
  • Multithreading What are some examples of lock-free and wait-free data structures and algorithms in multithreading?
  • Statistics How do you optimize your statistical code for efficiency and performance?
  • Machine Learning How can you remove outliers from a dataset using z-score?

Others also viewed

  • Getting Trendlines from Time Series Gonzalo Sanchez Pla 5y
  • How to Speed Up PTV Visum Models by Running Assignments in Parallel David Aspital 3y
  • Running a tidal simulation John Maskell 7y
  • Stack Overflows….Oversimplified. Roberto Eger 6y
  • Creating a graph with Gephi and scrapy Mihály Minkó 8y
  • Visualize CO2 Time Series with Python Chonghua Yin 6y
  • Floating point Issue faced practically !!! Jithendrian Sundaravaradan 11mo
  • Cluster/Node/machine downtime prediction- Survival Analysis Kinshuk Sengupta 8y
  • Use Joblib to Speed up Loops in Python Chonghua Yin 5y

Explore topics

  • Sales
  • Marketing
  • Business Administration
  • HR Management
  • Content Management
  • Engineering
  • Soft Skills
  • See All
CAN/LIN: How to read and parse MF4/MDF4 (Measurement data format files) in python when you do not have vector tools. Read SoC battery percentage of EV (2024)

FAQs

How to read MF4 files in Python? ›

  1. pip install asammdf[gui]
  2. from asammdf import MDF, Signal #import asammdf f_in = input ("Enter Input MDF4 FIle :") mdf = MDF(f_in) #read mf4 data f_out = f_in.replace(".MF4", ".csv") mdf.export(fmt='csv', filename= f_out) #write to csv.
  3. https://cantools.readthedocs.io/en/latest/ pip install cantools.
Mar 9, 2023

What is the format of MDF4 data? ›

What is an MF4/MDF4 file? Measurement Data Format version 4 (MDF 4) is a standard file format by ASAM used by the automotive industry for storing measurement data in binary file format. It records CAN, CAN FD, LIN bus data, sensor data from an engine control unit (ECU), offering interoperability across many CAN tools.

What format is MDF logging? ›

MDF Logging Files (MF4, MDF)

Stores the data in binary format in a very efficient way in terms of file size and read/write performance. Supports CAN, LIN, FlexRay and Ethernet in standard ASAM format.

What is the structure of ASAM MDF file? ›

An ASAM MDF file (file extension: *. mf4) is organized in binary blocks where each block consists of a number of contiguous bytes that can be seen as a record or structure of data fields. There are different types of blocks, and the block type defines the block's purpose and content.

How do I read a file format in Python? ›

The open() method in Python can be used to read files and accepts two parameters: the file path and the file access mode. The file access mode for reading a text file is "r." Below, I've listed the additional access methods: 'w' – writing to a file. 'r+' – read to a file.

How do I open an MF4 file? ›

Remember, different programs may use MF4 files for different purposes , so you may need to try out a few of them to be able to open your specific file. Try a universal file viewer like Bitberry File Opener. It can open 410 different types of files - and most likely yours too.

What is the MDF file format? ›

MDF (Measurement Data Format) is a binary file format to store recorded or calculated data for post-measurement processing, off-line evaluation or long-term storage. The format has become a de-facto standard for measurement & calibration systems (MC-systems), but is also used in many other application areas.

How to use a MDF file? ›

How to Open SQL MDF File Using SQL Server Management Studio
  1. Launch SQL Server Management Studio and connect to the SQL Server Instance.
  2. Once connected, you will see the SQL Server Instance.
  3. Now go to the Object Explorer >> right click on the Databases >> Attach.
  4. Click on Add button in the Attach Databases window.
Mar 31, 2024

How to run MDF file games? ›

DAEMON Tools Lite
  1. Right-click your MDF file and select “Open with.”
  2. Select Daemon tools from the options and the image will mount as a DVD.
  3. Windows Explorer will pick it up and you will be able to run or explore the disk just as you would if it were a real DVD.
Jun 12, 2019

How to read data from MDF file? ›

SSMS Method to Learn How to Extract MDF File & View All Data
  1. Open SSMS in system & connect with SQL instance.
  2. Navigate to Object Explorer & right-click on databases.
  3. Now, Go to Attach & Click on Add button in the window.
  4. Browse to Select the MDF file from the system & Click Ok.
Jan 18, 2024

What is LDF vs MDF file? ›

MDF stands for Main Database File and contains all the information in a database. LDF records all the transactions and changes to the database. The ldf is critical for disaster recovery.

What is the primary data file MDF? ›

The recommended file name extension for primary data files is . mdf . Optional user-defined data files. Data can be spread across multiple disks by putting each file on a different disk drive.

What is MDF structure? ›

MDF is a composite wood product traditionally formed by breaking down softwood into wood fibers, often in a defibrator, combining it with wax and a synthetic resin binder such as urea formaldehyde resins (UF) or other suitable bonding system, and forming panels by applying high temperature and pressure.

Where is the master MDF file? ›

The msdb database file (msdb. mdf) and msdb log files (msdb. ldf) are located in the Program Files\Microsoft SQL Server\Mssql\Data directory. Due to the amount of configuration information stored in the msdb database, the database should be routinely backed up.

How do I open an MDF ISO file? ›

Opening an MDF File
  1. Launch SQL Server Management Studio (or your system's MDF file opener).
  2. Connect to the SQL server on your device.
  3. Right-click the “Database” folder in the right panel.
  4. Select Attach → Add.
  5. Select the MDF file you want to open and click Ok.
Jun 7, 2024

How to read M4F files? ›

If you cannot open your M4F file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a M4F file directly in the browser: Just drag the file onto this browser window and drop it.

How to read FTP file in Python? ›

Then prints them out.
  1. import ftplib ftp = ftplib. FTP("ftp.nluug.nl") ftp. login("anonymous", "ftplib-example-1") data = [] ftp. ...
  2. import ftplib ftp = ftplib. FTP("ftp.nluug.nl") ftp. ...
  3. import ftplib import sys def getFile(ftp, filename): try: ftp. retrbinary("RETR " + filename ,open(filename, 'wb').

How to read data from MDB file in Python? ›

“how to open mdb file in python” Code Answer
  1. import pyodbc.
  2. conn = pyodbc. connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=path where you stored the Access file\file name.accdb;')
  3. cursor = conn. cursor()
  4. cursor. execute('select * from table name')
  5. for row in cursor. fetchall():
  6. print (row)

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Jamar Nader

Last Updated:

Views: 5855

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Jamar Nader

Birthday: 1995-02-28

Address: Apt. 536 6162 Reichel Greens, Port Zackaryside, CT 22682-9804

Phone: +9958384818317

Job: IT Representative

Hobby: Scrapbooking, Hiking, Hunting, Kite flying, Blacksmithing, Video gaming, Foraging

Introduction: My name is Jamar Nader, I am a fine, shiny, colorful, bright, nice, perfect, curious person who loves writing and wants to share my knowledge and understanding with you.