Is there a way to automate BLF to CSV conversion in Vector CANoe?

眉间皱痕 提交于 2020-01-13 16:56:52

问题


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:\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

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 head 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.


回答1:


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:\windows\system32\wscript.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.



来源:https://stackoverflow.com/questions/50600080/is-there-a-way-to-automate-blf-to-csv-conversion-in-vector-canoe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!