From 465795d6072e8e740aed8b37e156ee0b67e7fe60 Mon Sep 17 00:00:00 2001 From: Michael Graves Date: Tue, 12 May 2026 16:29:11 -0400 Subject: [PATCH 1/2] Added support for multiple channels in CSV write/read --- can/io/csv.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/can/io/csv.py b/can/io/csv.py index 0c8ba02a4..e240df96c 100644 --- a/can/io/csv.py +++ b/can/io/csv.py @@ -49,9 +49,15 @@ def __iter__(self) -> Generator[Message, None, None]: return for line in self.file: - timestamp, arbitration_id, extended, remote, error, dlc, data = line.split( - "," - ) + parts = line.strip().split(",") + if len(parts) < 7: + continue + + # Unpack the standard 7 columns + timestamp, arbitration_id, extended, remote, error, dlc, data = parts[:7] + + # Handle the optional 8th column (channel) + channel = parts[7] if len(parts) > 7 else 0 yield Message( timestamp=float(timestamp), @@ -61,6 +67,7 @@ def __iter__(self) -> Generator[Message, None, None]: arbitration_id=int(arbitration_id, base=16), dlc=int(dlc), data=b64decode(data), + channel=int(channel), # <--- Pass the channel here ) self.stop() @@ -82,6 +89,7 @@ class CSVWriter(TextIOMessageWriter): error 1 == True, 0 == False 0 dlc int 6 data base64 encoded WzQyLCA5XQ== + channel int or string 0 ================ ======================= =============== Each line is terminated with a platform specific line separator. @@ -106,19 +114,21 @@ def __init__( # Write a header row if not append: - self.file.write("timestamp,arbitration_id,extended,remote,error,dlc,data\n") + self.file.write( + "timestamp,arbitration_id,extended,remote,error,dlc,data,channel\n" + ) def on_message_received(self, msg: Message) -> None: row = ",".join( [ - repr(msg.timestamp), # cannot use str() here because that is rounding + repr(msg.timestamp), hex(msg.arbitration_id), "1" if msg.is_extended_id else "0", "1" if msg.is_remote_frame else "0", "1" if msg.is_error_frame else "0", str(msg.dlc), b64encode(msg.data).decode("utf8"), + str(msg.channel), # <--- Add this line ] ) - self.file.write(row) - self.file.write("\n") + self.file.write(row + "\n") From e5e3db4b1776fb34148131132d31d3caedf2c662 Mon Sep 17 00:00:00 2001 From: Michael Graves Date: Tue, 12 May 2026 16:31:15 -0400 Subject: [PATCH 2/2] Updated documentation --- doc/changelog.d/2059.changed.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/2059.changed.rst diff --git a/doc/changelog.d/2059.changed.rst b/doc/changelog.d/2059.changed.rst new file mode 100644 index 000000000..2626b39be --- /dev/null +++ b/doc/changelog.d/2059.changed.rst @@ -0,0 +1 @@ +Added support for multiple channels in CSVReader and CSVWriter. \ No newline at end of file