Search code examples
pythoncan-buspython-can

Python CAN Log Converter for the following log types (ASC, BLF, CSV, LOG)


Bear with me as I'm new to Python and coding in general. I was looking to create a script that is able to convert the following common CAN logging formats (ASC, BLF, txt, csv, MF4) to another format (ASC, BLF, txt, csv, MF4). I've already installed the python-can module. As I understand it, there in one already built into that module. When I run the script "can_logconvert.py" I am greeted by the following message:

PS C:\Users\BE\Documents\Python> & C:/Users/BE/AppData/Local/Programs/Python/Python310/python.exe c:/Users/BE/AppData/Local/Programs/Python/Python310/Scripts/can_logconvert.py usage: can_logconvert.py [-h] [-s FILE_SIZE] INFILE OUTFILE

Convert a log file from one format to another.

positional arguments: INFILE Input filename. The type is dependent on the suffix, see can.LogReader.
OUTFILE Output filename. The type is dependent on the suffix, see can.Logger.

options: -h, --help show this help message and exit -s FILE_SIZE, --file_size FILE_SIZE Maximum file size in bytes. Rotate log file when size threshold is reached. can_logconvert.py: error: the following arguments are required: INFILE, OUTFILE

Here's what the script contains:

"""
See :mod:`can.logconvert`.
"""

from can.logconvert import main

if __name__ == "__main__":
    main()

Given I have (for example) an input file named "input.asc" where would I direct his to? Would it be something I'd put in the console? If so, with what syntax?

Thanks for the time and sorry for my noobness!


Solution

  • The help message tells you than you should pass input and output files to the script as positional arguments. In your case:

    python C:/Users/.../Python310/Scripts/can_logconvert.py input.asc output.blf
    

    This supposes input.asc is in your current folder and python is in your PATH. (replace with absolute paths if it's not the case)

    The script will infer the output type from the extension. Here are all supported formats:

    • .asc: :class:can.ASCWriter
    • .blf :class:can.BLFWriter
    • .csv: :class:can.CSVWriter
    • .db: :class:can.SqliteWriter
    • .log :class:can.CanutilsLogWriter
    • .txt :class:can.Printer