Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serial Port CSV Logger CLI

A lightweight, single-file Python CLI application to record, preview, parse, and log serial port data into a CSV file with local ISO timestamps.

Quick Start

First you need to have Python 3.8 or greater installed on your machine. Then install the requirements:

pip install pyserial

1. Interactive Setup Wizard

Run without arguments to start the step-by-step interactive configuration:

python main.py

2. Run with Saved Configuration

To skip configuration and run directly (serial port selection is always prompted):

python main.py serial_config.json

Features

  • Local ISO 8601 Timestamps: Every CSV row is timestamped with local time and timezone offset (e.g. 2026-08-04T11:26:00.771162+02:00).
  • Parsing Modes:
    • Field Delimiter: Split lines by comma ,, tab \t, space, semicolon ;, or custom string.
    • Regex Named Groups: Optional regex parsing supporting (?'name'...) or (?<name>...) syntax, automatically extracting column names from capture group names.
  • Malformed Line Handling: Choose whether to log raw un-parsed text or discard malformed lines.
  • Smart Adaptive Flushing: Flushes data to disk when serial buffers drain or periodically (every 1s), preventing I/O bottlenecks during high-frequency data streams while preserving real-time output.
  • Robust Error Handling: Catches unexpected serial port disconnections and handles Ctrl+C cleanly without tracebacks.

Development

Testing

Test the logger without physical serial hardware using the built-in PTY simulator:

Terminal 1: Run simulator (creates a virtual serial port like /dev/pts/X)

python test.py --loop --delay 0.5

Terminal 2: Run logger and select the virtual port (/dev/pts/X)

python main.py

Configuration File Example

{
  "baudrate": 115200,
  "bytesize": 8,
  "parity": "N",
  "stopbits": 1.0,
  "timeout": 1.0,
  "encoding": "utf-8",
  "newline": "\n",
  "strip_whitespace": true,
  "use_regex": true,
  "regex_pattern": "^\"(?'volts'[^\"]*)\",(?'amps'\\d+\\.\\d+)$",
  "columns": ["volts", "amps"],
  "mismatch_action": "discard"
}

Created by SZEnergy Team for Shell Eco Marathon

  • Váradi Marcell (varma02@GitHub)

About

Serial port logger for recording anemometer data.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages