有没有办法在 Vector CANoe 中自动将 BLF 转换为 CSV? [英] Is there a way to automate BLF to CSV conversion in Vector CANoe?

查看:504
本文介绍了有没有办法在 Vector CANoe 中自动将 BLF 转换为 CSV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一种方法是使用

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

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

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

任何帮助将不胜感激.

解决方案

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

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

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

'------------------------------------------------------------------------------' 借助 CANoe 将通过启动参数传递的文件名转换为 ASC 文件'--------------------------------------------------------------------------------暗淡 src_file、dst_file、pos设置 App = CreateObject("CANoe.Application")设置测量 = App.Measurement设置 args = WScript.Arguments' 读取第一个命令行参数arg0=args.Item(0)arg1=args.Item(1)If Measurement.Running Then测量.停止万一Wscript.Sleep 500'------------------------------------------------------------------------------' 你必须创建一个空的 CANoe 配置并在下面指定路径和文件名'--------------------------------------------------------------------------------App.Open("d:awayawayempty_config.cfg")'--------------------------------------------------------------------------------' 创建目标文件名并附加 .asc - 您可以将其更改为 CANoe 支持的不同文件格式src_file=arg1 &"" &参数0dst_file=src_file &.asc"设置日志记录 = App.Configuration.OnlineSetup.LoggingCollection(1)设置 Exporter = Logging.Exporter使用 Exporter.Sources.清除.Add(src_file)结束于' 加载文件导出器.Load使用 Exporter.Destinations.清除.Add(dst_file)结束于Exporter.Save True应用程序退出设置出口商 = 无设置日志记录 = 无设置应用程序 = 无设置 args = 无设置测量 = 无

你必须做什么:

  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 更改为支持的请求目标文件格式.

My first approach was using python-can (as it added support for parsing BLF files with 2.0.0 release) like this:

import can

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

but that resulted in an error that I reported to the developer. BLF format is proprietary and somewhat secret so I understand supporting it in an open-source library can be problematic.

So then I looked into doing it using a solution provided by Vector: COM, but so far haven't been able to come up with a solution.

(The code snippet below is in vbscript as that's what used in CANoe docs, but I also have Python scripts doing exactly the same using win32com)

So first I tried with this:

Dim app, measurement, loggings, logging, exporter, expfilter
Set app = CreateObject("CANoe.Application")
Set loggings = app.Configuration.OfflineSetup.LoggingCollection
loggings.Add("D:pathdummy3.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:pathdummy3.csv")

exporter.Save True

And that works at least inasmuch that BLF is loaded into Exporter object and I can read FullName property of all its Symbol and Message objects and also I'm sure the path added to its Destinations collection is OK (at least I can read it after adding), but then it all falls flat at the last line with the error below:

This message proves to be rather cryptic so I don't know really what's wrong apart from that there's some trouble with writing a file. The thing is I don't really need CANoe to do the writing for me as long as I can get my hands on the data contained in BLF somehow.

So the other idea I had was to attach the BLF as an offline source in CANoe'a Configuration window, save the config and start a measurement from a script. That way I have the data in a Trace window (limited to 4000 events by default, but I believe that should be editable), but so far haven't found a way to get to it using the COM interface.

I have a feeling there should be some easier way to do this. After all there's Logging File Conversion dialog in CANoe and the logical way would be to access that somehow using COM interface. I just don't seem to able to see that written anywhere in the docs.

Any help would be much appreciated.

解决方案

You can use the following scripts to automate the file format conversion with the automation of your CANoe or CANalyzer. The solution consists of a Windows batch file and a VisualBasicScript file. The batch file convert_this_folder.bat has to be started by double-click. It contains the following line which calls the other script for all BLF log files in the folder where the batch file is located:

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

The VBS script canoe_convert.vbs contains the following lines:

'-----------------------------------------------------------------------------
' 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

What you have to do:

  1. Create an empty CANoe configuration and save it.
  2. Enter the path and file name of this empty configuration into the VBS file (the place of insertion is marked visually)
  3. Copy all the log files to be converted into the same directory where the 2 script files are located.
  4. If opened, close CANoe.
  5. Start the batch conversion by double-clicking on the convert_this_folder.bat. For each file CANoe is started, the file is converted and CANoe is closed. This is done via COM automation. The whole conversion process might take some time, please leave your PC alone during that time and do not perform other tasks.

The script files are attached below. You can adjust the scripts to CANalyzer by replacing "CANoe.Application" with "CANalyzer.Application" in the VBS file. The empty CANalyzer configuration has to be created additionally.

The conversion types can be adjusted as follows: Source file type in the .BAT file: change .BLF to the supported requested source file format Destination file type in the .VBS file: change .ASC to the supported requested destination file format.

这篇关于有没有办法在 Vector CANoe 中自动将 BLF 转换为 CSV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆