CSS-Electronics / api-examples

CANedge API Examples for MDF4/S3
MIT License
103 stars 35 forks source link

Setting index of CAN channel in python API #23

Open mthaitjema opened 1 year ago

mthaitjema commented 1 year ago

Hi,

I am trying to load and decode an MF4 file using the python API. In the MATLAB API, the index of the CAN channel is passed to the read method:

can_idx = 8;
rawTimeTable = read(m,can_idx,m.ChannelNames{can_idx});

I could not find out how to do the same thing when using the python API. Currently my code looks like this:

db = can_decoder.load_dbc(pathToDBC)
df_decoder = can_decoder.DataFrameDecoder(db)

with open(pathToMF4, "rb") as handle:
    mdf_file = mdf_iter.MdfFile(handle)
    df_raw = mdf_file.get_data_frame()

df = df_decoder.decode_frame(df_raw)

This does decode the data, but the dataframe is not ordered in groups like when using MATLAB. Is it possible to do this with the python API?

MatinF commented 1 year ago

You might be able to do something like this with the asammdf Python API. However, our Python API instead converts the MF4 channel-structure to a pandas dataframe structure (similar to a CSV).