hardbyte / python-can

The can package provides controller area network support for Python developers
https://python-can.readthedocs.io
GNU Lesser General Public License v3.0
1.3k stars 605 forks source link

Logged .asc file can't open in CANoe 14 #1315

Closed tienlocnguyen closed 2 years ago

tienlocnguyen commented 2 years ago

Describe the bug

Logged .asc file by python-can is not able to open in CANoe 14

To Reproduce

Expected behavior

Can replay log by CANoe 14

Additional context

OS and version: Window 10 Python version: 3.8 python-can version: 4.0.0(https://github.com/hardbyte/python-can/releases/download/4.0.0/python_can-4.0.0-py3-none-any.whl) python-can interface/s (if applicable):

Root cause

Date information in header of .asc file contain 6 digits of milisecond and somehow violate CANoe 14 rule. 3 digits is accepted Not work: date Mon May 23 03:29:03.103xxx PM 2022 Worked: date Mon May 23 03:29:03.103 PM 2022

Propose fix

Use same logic to get datetime when write begin trigger block File asc.py, line 368-369 Change from

        now = datetime.now().strftime(self.FORMAT_START_OF_FILE_DATE)
        self.file.write(f"date {now}\n")

to

        now = datetime.now().timestamp()
        mlsec = repr(now).split(".")[1][:-3]
        formatted_date = time.strftime(
            self.FORMAT_DATE.format(mlsec), time.localtime(now)
        )
        self.file.write(f"date {formatted_date}\n")

Tested and can open in CANoe

zariiii9003 commented 2 years ago

Would you like to create a PR?

Tian-Jionglu commented 2 years ago

Thanks to @tienlocnguyen , this solution solved my issue. I created a PR #1357 to fix this issue. Sightly difference, since can_logconvert should also be fixed.