gpt4 book ai didi

vbscript - 有没有办法在 Vector CANoe 中自动将 BLF 转换为 CSV?

转载 作者:行者123 更新时间:2023-12-02 19:26:31 29 4
gpt4 key购买 nike

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

import can

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

但这导致了我向开发人员报告的错误。 BLF 格式是专有的并且有些 secret ,因此我知道在开源库中支持它可能会出现问题。

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

(下面的代码片段位于 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 对象中,并且我可以读取其所有 Symbol 的 FullName 属性Message 对象,而且我确信添加到其 Destinations 集合中的路径是可以的(至少我可以在添加后读取它),但随后它最后一行全部失败,错误如下:

COM server error message

这条消息被证明相当神秘,所以除了编写文件时遇到一些问题之外,我不知道到底出了什么问题。问题是,只要我能够以某种方式获取 BLF 中包含的数据,我实际上并不需要 CANoe 为我编写代码。

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

我有一种感觉应该有一些更简单的方法来做到这一点。毕竟,CANoe 中有日志文件转换 对话框,逻辑方法是使用 COM 接口(interface)以某种方式访问​​该对话框。我似乎无法在文档中的任何地方看到这样的内容。

任何帮助将不胜感激。

最佳答案

您可以使用以下脚本通过 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 自动化。整个转换过程可能需要一些时间时间,请在此期间不要打扰您的电脑,并且不要执行其他任务。

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

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

关于vbscript - 有没有办法在 Vector CANoe 中自动将 BLF 转换为 CSV?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50600080/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com