Ganesh Narasimhan
Ganesh Narasimhan

Reputation: 21

No output when Extracting CAN Bus Logging Data Using DBC Files in asammdf (Closed)

Update 7/12: The issue was the mdf file was not closed. mdf.close() does the trick

I am trying to extract CAN bus logging data from an MDF file using a set of DBC files with the asammdf library in Python. I have verified that the MDF file contains CAN channels and messages. However, after attempting to extract the data, the resulting MDF object does not seem to contain any CAN channels or messages. Here is the code I am using:

from asammdf import MDF

# Load MF4 file
file_path = r'somepath'
mdf = MDF(file_path)

# Define the path for DBC files
pathdbc = r'dbcpath'

# Define the databases dictionary
database_files = {
    "CAN": [
        (pathdbc + "ch1.dbc", 1),
        (pathdbc + "ch2.dbc", 2),
        (pathdbc + "ch3.dbc", 3),
        (pathdbc + "ch4.dbc", 4),
        (pathdbc + "ch5.dbc", 5)
    ],
}

# Extract bus logging data using the DBC files
print("Extracting bus logging data using the provided DBC files...")
try:
    extracted = mdf.extract_bus_logging(database_files=database_files)
    print("Extraction successful.")
except Exception as e:
    print(f"Extraction failed: {e}")

# Function to list messages in a specified CAN network
def list_messages_in_can_network(network_id):
    can_networks = extracted.bus_logging_map.get('CAN', {})
    if network_id in can_networks:
        messages = can_networks[network_id]
        print(f"\nCAN Network {network_id}: {len(messages)} messages")
        for message_id, index in messages.items():
            print(f"Message ID: {message_id}, Index: {index}")
    else:
        print(f"No messages found for CAN Network {network_id}")

# List the names of CAN networks after extraction
def list_can_networks_after_extraction():
    can_networks = extracted.bus_logging_map.get('CAN', {})
    print(f"Number of CAN networks after extraction: {len(can_networks)}")
    for network_id in can_networks.keys():
        print(f"CAN Network ID after extraction: {network_id}")

# List messages in CAN Network 4
network_id = 4

# Run the functions
list_can_networks_after_extraction()
list_messages_in_can_network(network_id)

Output:

Extracting bus logging data using the provided DBC files...

Extraction successful.

Number of CAN networks after extraction: 0

No messages found for CAN Network 4

I have verified that the source MDF file contains messages and channels. Here is what I have tried so far:

  1. Verified the MDF file structure to ensure it contains CAN data.

  2. Checked the DBC files to ensure they are correct and accessible.

  3. Ensured the DBC files contain the expected message definitions.

However, after extraction, the resulting MDF object shows no CAN networks or messages.

Question: What might be causing the extract_bus_logging function to not find any CAN channels or messages in the extracted MDF object, despite the source MDF file containing them? How can I properly extract and map the DBC files to the MDF data?

Upvotes: 1

Views: 118

Answers (0)

Related Questions