Something went wrong. Try again.
An experimental port of NetBSD, FreeBSD, OpenBSD, and XNU to unkernel unkernel.dev
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586// SPDX-License-Identifier: MIT// Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>// Serial Monitor: picocom in the terminal on one of the guest's serial// ports, which are this browser's Web Serial devices (serial.ts: Settings >// Serial ports, Connect...). serial.sh starts it on the port named, else on// the first /dev/ttyACM port that has a device, at 115200 8N1 unless told// otherwise; picocom's escape key is Ctrl-B, since Ctrl-A is the page's// prefix. An open of a port without a device fails with ENODEV, which the// page answers with a toast that offers to connect one; an open that// succeeds is a real open of the device (DTR and RTS, which may reset an// ESP32), so the script opens each port at most once. The Terminal button// of a port in Settings > Serial ports runs it on that port// (serialTerminal()).// Checked 2026-11-29 under Node on a loopback port (Debian, picocom 3.1// in a pty: typed bytes come back, Ctrl-B Ctrl-X quits; before -q was// added); not run in a browser or on a board.import type { TerminalApp } from "../types.ts";
const README = `Serial Monitor: picocom on this browser's serial ports.
Connect the board first: plug it in by USB, then in the page open Settings >Serial ports, click Connect... and pick it (or use the Connect button of thenotice this app brings up). It is then /dev/ttyACM0 (or the next free one,up to ttyACM3) in the guest.
./serial.sh the connected board at 115200 8N1 ./serial.sh /dev/ttyACM1 ... on a port by name ./serial.sh /dev/ttyACM0 9600 ... at another speed
In picocom: Ctrl-B Ctrl-X quits, Ctrl-B Ctrl-U and Ctrl-B Ctrl-D change thespeed, Ctrl-B Ctrl-T toggles DTR and Ctrl-B Ctrl-G RTS (an ESP32's resetlines), Ctrl-B Ctrl-\ sends a break, Ctrl-B Ctrl-C toggles local echo.Use the board from one program at a time.`;
// No "${" and no backquote in the script: it is a template literal.const SERIAL_SH = String.raw`#!/bin/sh# picocom on the page's serial ports (/dev/ttyACM0..3). Written by the# unkernel launcher's Serial Monitor app.# ./serial.sh [PORT [SPEED]]cd "$(dirname "$0")"B=$(printf '\033[1m') D=$(printf '\033[90m') N=$(printf '\033[0m')port=$1speed=$2[ -n "$speed" ] || speed=115200# The first port with a device: an open of one without fails (ENODEV).find_port() { for p in /dev/ttyACM[0-9]; do if (exec 3<>"$p") 2>/dev/null; then port=$p; return 0; fi done return 1}if [ -z "$port" ] && ! find_port; then printf '%s%s%s\n' "$B" "No serial device is connected to the guest yet." "$N" echo "Plug the board in by USB, then in the page: Settings > Serial ports," echo "Connect..., and pick it (or the notice's Connect button)." printf '%s%s%s\n' "$D" "Waiting for it. Ctrl-C stops." "$N" until find_port; do sleep 2; donefiprintf '%s%s%s\n' "$B" "picocom on $port at $speed (Ctrl-B Ctrl-X quits)" "$N"exec picocom -q -b "$speed" -e b "$port"`;
const app = { id: "serialmon", title: "Serial Monitor", desc: "A board on this browser's serial ports, in the terminal: its output and typing to it with picocom", // A plug's two pins over a prompt line (crafted). icon: { svg: '<g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 3v4M15 3v4M6.5 7h11v3a5.5 5.5 0 0 1-11 0V7ZM12 15.5v2.5M5 21h14"/></g>' }, colors: ["#14b8a6", "#134e4a"], needs: { net: true, serial: true }, packages: { debian: ["picocom"], alpine: ["picocom"] }, community: true, files: { README, "serial.sh": { content: SERIAL_SH, mode: 0o755 }, }, commands: ["cat README", "./serial.sh"],} satisfies TerminalApp;export default app;
/** The app started on one port (Settings > Serial ports, a port's Terminal button). */export function serialTerminal(device: string): TerminalApp { return { ...app, commands: [`./serial.sh ${device}`] };}