Metadata-Version: 2.4
Name: vserial
Version: 2.1.0
Summary: Professional Linux Virtual Serial Port & Silicon Hardware UART Emulator Suite with Dedicated Protocol Sniffers and PulseView/Sigrok Logic Analyzer Bridge
Author: Francisco Betancourt
License: MIT
Project-URL: Homepage, https://github.com/fbetancourt-dev/vserial
Project-URL: Repository, https://github.com/fbetancourt-dev/vserial.git
Project-URL: Issues, https://github.com/fbetancourt-dev/vserial/issues
Keywords: serial,uart,virtual-serial,com0com,sniffer,modbus,sigrok,pulseview,saleae,vcd,esp32,stm32,embedded
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: X11 Applications :: Qt
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Manufacturing
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator
Classifier: Topic :: Software Development :: Embedded Systems
Classifier: Topic :: System :: Emulators
Classifier: Topic :: System :: Hardware :: Hardware Drivers
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PySide6>=6.5.0
Requires-Dist: pyserial>=3.5
Dynamic: license-file

# vSerial: Silicon Virtual Serial Port & Protocol Analyzer Suite

[![Python Version](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue.svg)](https://www.python.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Platform](https://img.shields.io/badge/platform-Linux%20%28POSIX%20PTY%29-orange.svg)](https://kernel.org/)
[![GUI](https://img.shields.io/badge/GUI-PySide6%20%28Qt6%29-green.svg)](https://pypi.org/project/PySide6/)
[![Logic Analyzer](https://img.shields.io/badge/Logic%20Analyzer-Sigrok%20%2F%20PulseView%20%2F%20Saleae-purple.svg)](https://sigrok.org/)

**vSerial** is an enterprise-grade, modular Linux virtual serial port suite and silicon hardware UART emulator designed for embedded firmware developers, IoT engineers, and hardware-in-the-loop (HIL) testing.

It combines **hardware-accurate UART simulation** (physical bit timing, FIFO depth, baudrate drift, framing and parity fault injection), a **dedicated multi-visualizer protocol sniffer** inspired by *Eltima* and *HHD Software*, and a **virtual 8-channel logic analyzer bridge** with IEEE 1364 VCD synthesis natively compatible with **Sigrok**, **PulseView**, and **Saleae Logic**.

---

## 📸 Desktop Suite in Action

![vSerial Suite Architecture](docs/screenshots/vserial_suite.png)
*Left: `vSerial Manager` with dynamic pinout crossover and probe badges. Top Right: `vSerial Sniffer` with live Modbus RTU telemetry. Bottom Right: `PulseView` decoding bit-accurate UART waveforms.*

---

## 🏛️ Modular Layered Architecture

The project is decoupled into clear, specialized subsystems:

```text
 ┌─────────────────────────────────────────────────────────────────────────────┐
 │                         vSerial Architectural Layers                        │
 └─────────────────────────────────────────────────────────────────────────────┘

    [ CLI & Desktop UI ]       [ System Tray ]          [ External Tools ]
       vserial-gui            vserial-indicator        PulseView / Sigrok-cli
       vserial-sniffer                                      Saleae Logic
             │                        │                          │
 ┌───────────▼────────────────────────▼──────────────────────────▼────────────┐
 │  Frontend & Logic Bridges                                                   │
 │    • vserial.frontend: PySide6 dark UI, crossover diagram, probe badges     │
 │    • vserial.logic: 10 MHz IEEE 1364 VCD waveform synthesis, probe routing  │
 │    • vserial.sniffers: 5-view protocol analyzer, Modbus RTU/ASCII parser    │
 └────────────────────────────────────┬───────────────────────────────────────┘
                                      │
 ┌────────────────────────────────────▼───────────────────────────────────────┐
 │  Daemons & IPC Broadcasting                                                │
 │    • vserial.daemons: UNIX Domain Socket broadcaster (/tmp/vserial_traffic)│
 │    • Service Manager: state.json, PID tracking, systemd user services      │
 └────────────────────────────────────┬───────────────────────────────────────┘
                                      │
 ┌────────────────────────────────────▼───────────────────────────────────────┐
 │  Engine & Hardware Simulation                                               │
 │    • vserial.engine.silicon_profiles: STM32, ESP32, PIC32, AVR, CH340, etc.│
 │    • vserial.engine.timing: Bit-time rate limiting & baudrate clock drift   │
 │    • vserial.engine.fault_injection: Parity error, framing error, FIFO ORE │
 │    • vserial.engine.flow_control: Hardware RTS/CTS, DTR/DSR, virtual relay │
 │    • vserial.engine.pty_pair: Linux master/slave pseudo-terminals (PTY)    │
 └─────────────────────────────────────────────────────────────────────────────┘
```

---

## ⚡ Core Features

### 1. Silicon Hardware UART Emulation
Unlike standard virtual COM port tools (`socat` or raw PTYs) that transfer data instantly in memory without rate limits, **vSerial** accurately emulates the physical constraints of real silicon UART controllers:
- **Bit-Time Rate Limiting:** Enforces physical transmission delays character-by-character based on baud rate (300 to 12,000,000 baud), data bits (5 to 9 bits), parity, and stop bits.
- **Hardware FIFO Capacities:** Accurate RX/TX FIFO buffer depths (e.g., STM32 1B/2B, ESP32 128B, PIC32 8B, CP2102 576B, FT232R 256B/128B).
- **Overrun Error (ORE) Emulation:** Triggers Overrun Errors and drops bytes when receiver processing stalls, identical to real hardware.
- **Fault Injection:** Programmable probability for parity errors, framing errors, and baud mismatch corruption.
- **Supported Silicon Profiles:**
  - **Microcontrollers:** STM32 (ARM Cortex-M), ESP32 / ESP32-S3, Microchip PIC32 (MIPS), PIC16F/18F, Atmel ATmega328P/2560 (Arduino AVR), ATxmega.
  - **USB-Serial Bridges:** WCH CH340 / CH341, Silicon Labs CP2102 / CP2104, FTDI FT232R, FTDI FT2232H High-Speed, Prolific PL2303, Standard USB CDC-ACM.

### 2. Dedicated Multi-Visualizer Protocol Sniffer (`vserial-sniffer`)
Inspired by professional tools like *Eltima Serial Port Monitor* and *HHD Free Serial Port Monitor*:
- **5 Simultaneous Visualizers:**
  1. **Table View:** Complete chronological packet logs with timestamps, direction, byte count, hex dump, ASCII preview, and error flags.
  2. **Line View (Dialogue):** Grouped *Request ➔ Response* conversations with relative delta timing (`+0.0500s`), ideal for ISP programming protocols (`avrdude 30 20 -> 14 10`).
  3. **Dump View:** Split *Read Requests* (RX) and *Write Requests* (TX) panels with 16-byte offset hex views.
  4. **Terminal View:** Interactive raw bidirectional ASCII terminal.
  5. **Modbus View:** Real-time Modbus RTU / ASCII frame decoder: Slave ID, Function Codes (`0x01`, `0x02`, `0x03`, `0x04`, `0x05`, `0x06`, `0x10`), register addresses, and CRC-16 validation.
- **Hardware Status LEDs:** Live indicator lights for `RTS`, `CTS`, `DSR`, `DCD`, `DTR`, `RI`.
- **Interactive Packet Injector:** Transmit custom payloads (String, Hex, Dec, Bin) with single-shot or recurring loop timers (*Send every N ms*).
- **Session Export:** One-click export to CSV and structured JSON.

### 3. Virtual Logic Analyzer Bridge (PulseView / Sigrok / Saleae)
- **10 MHz IEEE 1364 VCD Synthesis:** Synthesizes digital waveform transitions down to 100 ns resolution directly from virtual UART traffic.
- **Official Probe Colors:** Matches Saleae Logic and PulseView standard color palettes:
  - `D0` Teal / Green (`#26a69a`) - `TX`
  - `D1` Red (`#ef5350`) - `RX`
  - `D2` Blue (`#42a5f5`) - `RTS`
  - `D3` Orange (`#ffa726`) - `CTS`
  - `D4` Purple (`#ab47bc`) - `DTR`
  - `D5` Yellow (`#ffee58`) - `DSR`
  - `D6` Cyan (`#26c6da`) - `RELAY`
  - `D7` Pink (`#ec407a`) - `ESP32_BOOT`
- **Interactive Crossover Schematic:** Renders color badges clipped directly onto schematic wires.
- **Single-Click PulseView Launch:** Automatically writes `/tmp/vserial_logic.vcd` and launches `/usr/local/bin/pulseview -i /tmp/vserial_logic.vcd`.

---

## 🚀 Quick Start

### Installation

Clone the repository and install in editable development mode or standard Python package:

```bash
git clone https://github.com/fbetancourt-dev/vserial.git
cd vserial
pip install -e .
```

Or run the native setup script:
```bash
./rebuild.sh
```

### CLI Usage

```bash
# Start an emulated pair with ESP32 UART profile at 115200 baud
vserial pair --profile esp32 --baud 115200

# Start an emulated pair with STM32 profile and RTS/CTS flow control in background
vserial pair --profile stm32 --baud 921600 --rtscts --daemon

# Check running daemon status
vserial status

# List all supported silicon hardware profiles
vserial profiles

# Stop running daemon
vserial stop
```

### GUI Applications

```bash
# Launch the full Virtual Serial Port Manager GUI
vserial-gui

# Launch a dedicated sniffer for port /tmp/ttyV0
vserial-sniffer /tmp/ttyV0

# Launch sniffer for the global bus
vserial-sniffer

# Export waveform and open PulseView
vserial-vcd
```

---

## 🧪 Testing

Run the automated test suite with Python's standard `unittest`:

```bash
python3 -m unittest discover -s tests -p "test_*.py" -v
```

---

## 📄 License

Distributed under the **MIT License**. See [LICENSE](LICENSE) for details.

Developed with passion by **Francisco Betancourt** for the embedded systems community.
