【问题标题】:Is there a way to automate BLF to CSV conversion in Vector CANoe?有没有办法在 Vector CANoe 中自动将 BLF 转换为 CSV?
【发布时间】:2018-11-09 00:53:36
【问题描述】:

我的第一种方法是使用python-can(因为它增加了对解析 2.0.0 版本的 BLF 文件的支持),如下所示:

import can

filename = "logfile.blf"
logging = can.BLFReader(filename)
for msg in logging:
    print(msg)

但这导致我向开发人员报告了一个错误。 BLF 格式是专有的并且有些秘密,所以我知道在开源库中支持它可能会有问题。

然后我考虑使用 Vector 提供的解决方案COM,但到目前为止还没有提出解决方案。

(下面的代码 sn-p 在 vbscript 中,因为这就是 CANoe 文档中使用的代码,但我也有 Python 脚本使用 win32com 执行完全相同的操作)

所以我首先尝试了这个:

Dim app, measurement, loggings, logging, exporter, expfilter
Set app = CreateObject("CANoe.Application")
Set loggings = app.Configuration.OfflineSetup.LoggingCollection
loggings.Add("D:\path\dummy3.blf")
Set logging = loggings(1)
Set exporter = logging.Exporter
Set expfilter = exporter.Filter
exporter.Load

For Each symbol In exporter.Symbols
  expfilter.Add(symbol.FullName)
Next

For Each message In exporter.Messages
  expfilter.Add(Message.FullName)
Next

expfilter.Enabled = True

Dim dests
Set dests = exporter.Destinations
dests.Clear
dests.Add("D:\path\dummy3.csv")

exporter.Save True

至少因为BLF 被加载到Exporter 对象中并且我可以读取其所有SymbolMessage 对象的FullName 属性并且我确定添加到它的路径Destinations 集合还可以(至少我可以在添加后阅读它),但是在最后一行中一切都变平了,错误如下:

这条消息被证明是相当神秘的,所以我真的不知道出了什么问题,除了写文件有一些问题。问题是我真的不需要CANoe 来为我写作,只要我能以某种方式获得BLF 中包含的数据。

所以我的另一个想法是将BLF 作为离线源附加到CANoe'a Configuration 窗口中,保存配置并从脚本开始测量。这样我就可以在Trace 窗口中获得数据(默认情况下限制为 4000 个事件,但我认为应该是可编辑的),但到目前为止还没有找到使用 COM 接口获取它的方法。

我觉得应该有一些更简单的方法来做到这一点。毕竟CANoe 中有Logging File Conversion 对话框,合乎逻辑的方法是使用COM 接口以某种方式访问​​它。我只是似乎无法在文档中的任何地方看到它。

任何帮助将不胜感激。

【问题讨论】:

    标签: vbscript com pywin32 win32com canoe


    【解决方案1】:

    您可以使用以下脚本通过 CANoe 或 CANalyzer 的自动化来自动化文件格式转换。该解决方案由一个 Windows 批处理文件和一个 VisualBasicScript 文件组成。 批处理文件convert_this_folder.bat 必须通过双击启动。它包含以下行,它为批处理文件所在文件夹中的所有 BLF 日志文件调用另一个脚本:

    for /F %%x in ('cd') do for %%i in (*.blf) do c:\windows\system32\wscript.exe canoe_convert.vbs %%i %%x
    

    VBS 脚本canoe_convert.vbs 包含以下几行:

    '-----------------------------------------------------------------------------
    ' converts the filenames which are passed via startup parameter to ASC files with the help of CANoe
    '-----------------------------------------------------------------------------
    Dim src_file, dst_file, pos
    
    Set App         = CreateObject("CANoe.Application")
      Set Measurement = App.Measurement
      Set args        = WScript.Arguments
    
      ' read first command line parameter
      arg0=args.Item(0)
      arg1=args.Item(1)
    
      If Measurement.Running Then
        Measurement.Stop
      End If
    
      Wscript.Sleep 500
    
      '---------------------------------------------------------------------------
    '  you have to create an empty CANoe configuration and specify the path and file name below
    '-----------------------------------------------------------------------------
      App.Open("d:awayawayempty_config.cfg")
    '-----------------------------------------------------------------------------
    ' create destination file name and append .asc   -- you could change this to different file format that is supported by CANoe
      src_file=arg1 & "" & arg0
      dst_file=src_file & ".asc"
    
      Set Logging  = App.Configuration.OnlineSetup.LoggingCollection(1)
      Set Exporter = Logging.Exporter
    
      With Exporter.Sources
        .Clear
        .Add(src_file)
      End With
    
      ' Load file
      Exporter.Load
    
      With Exporter.Destinations
        .Clear
        .Add(dst_file)
      End With    
    
      Exporter.Save True
    
      App.Quit
      Set Exporter = Nothing
      Set Logging  = Nothing
      Set App      = Nothing
      Set args     = Nothing
      Set Measurement = Nothing
    

    你必须做什么:

    1. 创建一个空的 CANoe 配置并保存。
    2. 将这个空配置的路径和文件名输入到VBS文件中(插入的地方有视觉标记)
    3. 将所有要转换的日志文件复制到2个脚本文件所在的同一目录中。
    4. 如果打开,请关闭 CANoe。
    5. 双击 convert_this_folder.bat 开始批量转换。对于每个文件 CANoe 启动,文件被转换并且 CANoe 被关闭。这个做完了 通过 COM 自动化。整个转换过程可能需要一些时间 时间,请在此期间将您的 PC 单独放置,不要执行 其他任务。

    脚本文件附在下面。 您可以通过将 VBS 文件中的“CANoe.Application”替换为“CANalyzer.Application”来将脚本调整为 CANalyzer。必须另外创建空的 CANalyzer 配置。

    转换类型可以调整如下: .BAT 文件中的源文件类型:将 .BLF 更改为支持的请求源文件格式 .VBS 文件中的目标文件类型:将 .ASC 更改为支持的请求目标文件格式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-10
      • 2020-03-08
      • 2019-03-31
      相关资源
      最近更新 更多