简体   繁体   English

如何在 Python 中使用 asammdf 列出 .mdf4 文件中的所有通道?

[英]How to list all the channels in .mdf4 file using asammdf in Python?

How to get a list of all the channel names in a .mdf4 file while using asammdf?如何在使用 asammdf 时获取 .mdf4 文件中所有通道名称的列表? I read the description here but am unable to figure out the exact code.我在这里阅读了描述,但无法找出确切的代码。

According to https://asammdf.readthedocs.io/en/latest/api.html#mdf4 :根据https://asammdf.readthedocs.io/en/latest/api.html#mdf4

The groups attribute is a list of dicts, each one with the following keys: groups属性是一个字典列表,每个字典都有以下键:

  • […] […]
  • channels - list of Channel objects with the same order as found in the mdf file channels - 与 mdf 文件中的顺序相同的通道对象列表

And according to https://asammdf.readthedocs.io/en/latest/v4blocks.html#channel-class a Channel object has attributes根据https://asammdf.readthedocs.io/en/latest/v4blocks.html#channel-class一个 Channel 对象具有属性

  • display_name - str : channel display name; display_name - str : 频道显示名称; this is extracted from the XML channel comment这是从 XML 通道注释中提取的
  • name - str : channel name name - str : 频道名称

So you should be able to use:所以你应该能够使用:

mdf4 = MDF4(name_of_mdf4_file)

all_channels = []
for group in mdf4.groups:
    for channel in group['channels']:
        all_channels.append(channel.display_name)

Or use .name instead of .display_name , depending on what exactly you need.或使用.name而不是.display_name ,具体取决于您的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM