Skip to main content

PySerialPortLogger

PySerialPortLogger is a utility that makes it easy to log text output in a complex environment on a POSIX system. Let's say you're trying to debug an open-source application with many components and tens of thousands of lines of code: You might try inserting logging commands at strategic points in the code. Or you've injected a module into a closed-source application, and need to log the information it finds there. Then you discover your output is redirected light years away, or to /dev/null. If you're doing this in a POSIX environment, PySerialPortLogger is for you.

Use the following command to install PySerialPortLogger:

pip3 install PySerialPortLogger

Then run serialportlogger in a terminal window, and you'll see output like the following:

% serialportlogger
Ctrl-C to exit
/dev/ttys002

All text output written to /dev/ttys002 will get written to your terminal window. Each line of output needs to end with a newline character (\n).

Here are code fragments, in C and Python, which you can use to write to this serial port:

#include <stdio.h>
#include <fcntl.h>

int virtual_serial_port_fd = -1;
FILE *virtual_serial_port_FILE = NULL;

virtual_serial_port_fd =
  open("/dev/ttys002", O_WRONLY | O_NONBLOCK | O_NOCTTY);
if (virtual_serial_port_fd >= 0) {
  virtual_serial_port_FILE = fdopen(virtual_serial_port_fd, "w");
}

while([have lines of text to log]) {
  if (virtual_serial_port_FILE) {
    fputs([newline-terminated line of text], virtual_serial_port_FILE);
  }
}

if (virtual_serial_port_FILE) {
  fclose(virtual_serial_port_FILE);
}
if (virtual_serial_port_fd) {
  close(virtual_serial_port_fd);
}
from contextlib import ExitStack

serial_port = open('/dev/ttys002', mode='wt', buffering=1)
ExitStack().enter_context(serial_port)
while [have lines of text to log]:
    serial_port.write([newline-terminated line of text])

PySerialPortLogger is based on another Github project named PyVirtualSerialPorts

Metadata

Release files for PySerialPortLogger 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PySerialPortLogger 2.0.0
File Size Uploaded
PySerialPortLogger-2.0.0.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PySerialPortLogger 2.0.0
File Interpreter ABI Platform
PySerialPortLogger-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / PySerialPortLogger-2.0.0.tar.gz

Download URL PySerialPortLogger-2.0.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9bfb288bd26bec4156f6295b37d4932b6cc8b37ca0c1081625bb66bd9030604e
BLAKE2b-256 checksum
How to use checksums
88f658737b5cc88cd7a8f19cbd55f3f371c22098438e361b951c03583bce4b62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.8

Release files / PySerialPortLogger-2.0.0-py3-none-any.whl

Download URL PySerialPortLogger-2.0.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07547bec6deb0f534a5b35f9e05b06fac2c9fd080f3db551e0cb9da01ffffbd2
BLAKE2b-256 checksum
How to use checksums
ec8cfad9feab82bb7bfc58d8c840d2aeae270b11683475342fac62aa47e9f215
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.8

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page