import { For, Show, createSignal } from "solid-js"; import { Connection, baudRates, defaultSettings, type Parity, type PortSettings } from "../serial/connection"; import Devices from "./Devices"; import Monitor from "./Monitor"; /** * Settings that make a device answer at all. * * The RadiCal manual recommends 19200 8E1 and `fan-controller` is built for it; both the relay and * the temperature sensor default to 9600 with no parity. A port speaks one of these at a time, so * a bus carrying both kinds of device has to be visited twice */ const presets: readonly { label: string; settings: PortSettings }[] = [ { label: "RadiCal fans — 19200 8E1", settings: defaultSettings }, { label: "Relay / temperature sensor — 9600 8N1", settings: { baudRate: 9600, parity: "none", dataBits: 8, stopBits: 1 }, }, ]; type Mode = "monitor" | "devices"; export default function PortPanel(props: { port: SerialPort; info: Partial }) { const connection = new Connection(props.port); const [settings, setSettings] = createSignal(defaultSettings); const [isOpen, setIsOpen] = createSignal(false); const [mode, setMode] = createSignal("monitor"); const [error, setError] = createSignal(); async function toggle() { setError(undefined); try { if (isOpen()) { await connection.close(); setIsOpen(false); return; } await connection.open(settings()); setIsOpen(true); } catch (cause) { setError(cause instanceof Error ? cause.message : String(cause)); } } function update(key: K, value: PortSettings[K]) { setSettings((current) => ({ ...current, [key]: value })); } return (

Serial port {" "} USB {props.info.usbVendorId?.toString(16)}:{props.info.usbProductId?.toString(16)}

{(message) =>

{message()}

}
Port settings
Open the port to watch the bus or read a device.

} > }>
); }