Skip to content

BLFWriter append messages to an existing log file does not take effect #1751

@tocatch

Description

@tocatch

Describe the bug

when i use BLFWriter to append messages to an existing log file,it does not take effect

To Reproduce

  1. I use the following code to append data to the output.blf file
import can

def generate_blf_file(messages, file): 
   
    blf_writer = can.BLFWriter(file=file, append=True)

    
    for message in messages:
        
        blf_writer.on_message_received(message)

   
    blf_writer.stop()



can_messages = [
    can.Message(
        timestamp=2.5010,
        arbitration_id=0xC8,
        is_extended_id=False,
        is_rx=False,
        channel=1,
        dlc=8,
        data=[9, 8, 7, 6, 5, 4, 3, 2],
    ),
    can.Message(
        timestamp=3.876708,
        arbitration_id=0x6F9,
        is_extended_id=False,
        channel=0,
        dlc=0x8,
        data=[5, 0xC, 0, 0, 0, 0, 0, 0],
    )
]

can_messages_append = [
    can.Message(
        timestamp=4.5010,
        arbitration_id=0xC8,
        is_extended_id=False,
        is_rx=False,
        channel=1,
        dlc=8,
        data=[9, 8, 7, 6, 5, 4, 3, 2],
    ),
    can.Message(
        timestamp=5.876708,
        arbitration_id=0x6F9,
        is_extended_id=False,
        channel=0,
        dlc=0x8,
        data=[5, 0xC, 0, 0, 0, 0, 0, 0],
    )
]

blf_output_file = 'blf-files/output.blf' 

generate_blf_file(can_messages, blf_output_file)

generate_blf_file(can_messages_append, blf_output_file)
  1. the result is only two pieces of data in the file in output.blf, The two pieces of data are two pieces of data in can_messages_append, It means that the file content is overwritten instead of appended.

Expected behavior

  1. What I expected is that there are four pieces of data in the output.blf file. That is to say, I wrote 2 pieces of data to the file twice, which should be the effect of appending data.

Additional context

OS and version: windows 10
Python version:3.9
python-can version:4.3.1
python-can interface/s (if applicable):

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions