I want to open a blf file using python scripts and print it. I have opened the file on wireshark. But when I open it using script and print it I do not get any output and there are no errors.
These are a few environment details: os: windows, python 3.11.5, appdirs==1.4.4, attrs==23.1.0, canmatrix==1.0, click==8.1.7, colorama==0.4.6,dpkt==1.9.8, future==0.18.3, lxml==4.9.3, numpy==1.25.2, packaging==23.1, pyshark==0.6, python-can==4.2.2, pywin32==306, scapy==2.5.0, six==1.16.0, termcolor==2.3.0, typing_extensions==4.7.1, wrapt==1.15.0, IDE: Visual Studio code,
file:Lines.blf, size: 21.8 MB, contains around 50000 in number
import can
blf_file_path = "C:/Users/sahaanan/Desktop/blf_to_pcap/NewSW_7209_Lines.blf"
try:
with open(blf_file_path, 'rb') as blf_file:
log = can.BLFLogReader(blf_file)
for msg in log:
print(msg)
if log.is_empty:
print("The BLF file is empty.")
except Exception as e:
print(f"Error reading BLF file: {e}")
Where did you get
can.BLFLogReaderfrom? According to the doc, you should be able to Read BLF files withcan.io.BLFReader. Alsois_emptydoesn't seem to be a valid attribute. You can check if the object count is equal to 0 insted: