Web Serial for Rig Control
How the WA5PB browser programs talk to the radio
Technical brief, version 1.3.0 - October 12, 2026 - Bill, WA5PB
← The WA5PB Ham Radio AI Project | WA5PB home page
1. Purpose
This brief explains how two of my browser-based ham radio programs use the Web Serial API to control a transceiver: DigiMode, a digital-mode program (PSK31, PSK63, Olivia, MFSK, RTTY) that now transmits as well as receives and controls eleven Elecraft and Kenwood rigs, and the K2 CAT Terminal, a small command console for the radio. Both run entirely in the browser page; nothing on the web server touches the radio.
My station uses an Elecraft K2 through a Digirig Mobile interface, so those appear as the worked example. The ideas apply to any rig with a serial CAT port and any USB-serial interface: an FTDI or CH340 cable, a SignaLink-style box with a serial line, or a radio with its own USB port.
On an Android phone the picture changes: there, Web Serial cannot see a USB-serial adapter at all, and both programs reach its chip directly over WebUSB instead - the Digirig's Silicon Labs CP210x, an FTDI FT232R or an MCT U232. That is written up as lesson 5.9.
2. What Web Serial Is
Web Serial is a browser API (navigator.serial) that lets a web page open a serial
port the operating system already knows about - a Windows COM port, or a Linux or macOS tty
device - and read and write bytes on it. It is the browser equivalent of opening COM3 in a desktop
program. A USB-serial adapter that shows up as a COM port is exactly what it is meant for.
2.1 Browser support
| Browser | Status | Notes |
|---|---|---|
| Chrome, Edge (desktop) | Supported since version 89 (2021) | My programs are built and tested here (a Windows laptop, Chromium on a Raspberry Pi 4B, and Chrome on a Debian 13 laptop). |
| Opera, Vivaldi, other Chromium | Supported | Same engine as Chrome; not tested by me. |
| Firefox (desktop) | Supported from version 151 (2026) | New. Mozilla gates the permission behind a site-permission add-on prompt before the port chooser. Tested by me: DigiMode worked in Firefox 153.0 on the Raspberry Pi 4B, and both programs in current Firefox on Windows and in Firefox 153.4 on a Debian 13 laptop, through its built-in serial port. |
| Safari, all iOS browsers | Not supported | Apple has stated it opposes the API on privacy and security grounds. |
| Chrome on Android | Shipped in Chrome 148 (2026) | Lists only USB CDC-ACM devices and Bluetooth (RFCOMM) serial ports; vendor bridge chips - CP210x, CH340, FTDI - are not listed. Tested by me on a Pixel 8a (Android 17, Chrome 154): the Digirig's CP2102N, an FTDI and a Belkin adapter did not appear. My programs use WebUSB there instead (lesson 5.9). |
2.2 The security model
- Secure context only. The page must be served over HTTPS (or from localhost
during development). A plain http:// page sees no
navigator.serialat all. - The user picks the port.
navigator.serial.requestPort()opens the browser's own port chooser, and it may only be called from a user action such as a button click. A page cannot open a port silently or on page load. - A filter narrows the chooser - and can hide the right port. The page can pass a
USB vendor ID (and optionally product ID) so that only matching adapters are listed. But Chrome's
filters match only USB or Bluetooth IDs, so any filter hides a computer's built-in COM port, and a
filter for one chip hides every other adapter. My programs began with a Digirig-only filter and
dropped it: they now pass no filter, list every port, and confirm the radio by asking it to
identify itself (
ID;). A wrong pick does no harm; the link simply reports that no rig answered. Without a filter, a built-in COM port is listed too: both programs have since reached the K2 through a Debian 13 laptop's own DE-9 port. - Per-site permission. Once granted, the site can find that port again with
navigator.serial.getPorts(); the operator can revoke it in the browser's site settings. - Client side only. All serial traffic stays between the browser and the local USB port. The web server that delivered the page never sees it.
3. How the Programs Are Built Around It
The most useful design decision was to keep Web Serial at the very edge of the program. The page does only three things with the port: open it, write bytes to it, and hand every byte it reads to a separate CAT module. All radio knowledge lives in that module, which has no idea it is in a browser.
| Layer | Responsibility |
|---|---|
| Page (browser) | Port chooser, open and close, the read loop, the user interface. The only code that
calls navigator.serial. |
| CAT module (pure JavaScript) | Splits the byte stream into frames, parses rig replies, builds commands, applies the
safety policy, and runs set-and-confirm. It is given a write(text) function
and is fed received text through feed(text). |
| Simulated rig (tests) | A software K2 that answers commands the way the real radio does, including its quirks. Lets the whole CAT module be tested in Node.js with no radio and no browser. |
Because the module only sees write() and feed(), it can be exercised
thousands of times in automated tests against the simulated rig, and both programs share one copy
of it. A fix in one program is a fix in the other, and the test suites of both are run whenever it
changes.
4. The Connection Lifecycle
- Check for the API. If
navigator.serialis missing, say so plainly (wrong browser, or not HTTPS) rather than failing later. - Request the port from a button click. A vendor-ID filter is optional, and has a cost (see 2.2).
- Open it with the rig's line settings. The K2 runs 4800 baud, 8 data bits, no parity, 2 stop bits, no flow control; DigiMode's other rigs open at their own rates, from 38400 to 115200 baud, 8N1, and every one with flow control off (lesson 5.12). Your rig's manual gives its own settings; they must match exactly.
- Immediately drop RTS and DTR. On many interfaces, the Digirig included, RTS is the hardware PTT line. Holding both lines low the moment the port opens is the safe default, not a nicety; a program that transmits raises its chosen line only for a deliberate transmission (lesson 5.13).
- Start a read loop that takes raw bytes, converts them byte-for-byte to characters, and feeds them to the frame splitter. Kenwood-style and Elecraft rigs end every reply with a semicolon.
- Ask the rig what state it is in before changing anything: identity, frequency and mode, and any reporting mode.
- Disconnect cleanly: put the rig back in a known quiet state, cancel the reader, release the writer, and close the port. Also listen for the browser's disconnect event, which fires when the USB cable is pulled.
4.1 A minimal skeleton
The following is a generic illustration for a Kenwood-style (semicolon-terminated) rig. It is not
production code: it has no safety policy and minimal error handling, and the vendor ID and line
settings must be changed for your interface and radio. To list every port instead, call
requestPort() with no filter.
// Change the filter and line settings for your cable and rig.
const FILTERS = [{ usbVendorId: 0x10C4 }]; // Silicon Labs CP210x
const LINE = { baudRate: 4800, dataBits: 8, stopBits: 2,
parity: "none", flowControl: "none" };
let port = null, reader = null, keepReading = false, buf = "";
async function connect() { // call from a button click
if (!("serial" in navigator)) throw new Error("No Web Serial here");
port = await navigator.serial.requestPort({ filters: FILTERS });
await port.open(LINE);
await port.setSignals({ requestToSend: false,
dataTerminalReady: false }); // PTT off
keepReading = true;
readLoop();
await send("ID;"); // who are you?
await send("IF;"); // what state are you in?
}
async function send(text) {
const w = port.writable.getWriter();
try { await w.write(new TextEncoder().encode(text)); }
finally { w.releaseLock(); }
}
async function readLoop() {
while (keepReading && port && port.readable) {
reader = port.readable.getReader();
try {
for (;;) {
const { value, done } = await reader.read();
if (done) break;
for (const b of value) buf += String.fromCharCode(b); // raw bytes
let i;
while ((i = buf.indexOf(";")) >= 0) {
onFrame(buf.slice(0, i)); // e.g. "FA00014070000"
buf = buf.slice(i + 1);
}
}
} catch (e) { /* framing or parity error: loop and retry */ }
finally { reader.releaseLock(); }
}
}
async function disconnect() {
keepReading = false;
if (reader) await reader.cancel().catch(() => {});
await port.close();
port = null;
}
navigator.serial.addEventListener("disconnect", (e) => {
if (e.target === port) { keepReading = false; port = null; }
});
5. Lessons Learned on the Air
Each of these cost real bench time to find. They are the main reason I would encourage anyone writing rig control in the browser to build a simulated radio and a test suite from the start.
5.1 One owner per port
A serial port can be held by only one program at a time - one browser tab, or one desktop application such as a logger or fldigi. If the open fails with a "failed to open" error, something else almost always has the port. Close it there first. (On Linux, the same error can mean you lack permission to open the port at all - see lesson 5.10.) This also means two pages cannot share a radio, which turned out to simplify the safety rules.
5.2 Read bytes, not text
Do not run received data through TextDecoder. Some rig replies carry bytes above
0x7F; the K2's display-read reply uses bit 7 for decimal points and status flags. UTF-8 decoding
turns those bytes into replacement characters, and Windows-1252 quietly remaps some of them, which
is worse because it looks as if it worked. Map each byte to the character with the same code, as in
the skeleton, and parse from there.
5.3 Hold the control lines down
RTS and often DTR are wired to PTT or CW keying on many interfaces. Set both low the moment the port opens and keep them there unless the program means to transmit. Be aware that some operating systems and drivers pulse these lines briefly while a port is opening, before your code runs; check that behaviour with a dummy load before trusting it on the air. Measured at my bench, on Windows and on Linux alike, opening the port raised RTS until the page forced it off - a few milliseconds, but enough for a rig to click into transmit and out again (lesson 5.13).
5.4 Serial traffic can show up in the receive audio
My first version asked the radio for its status about three times a second. At 4800 baud that traffic coupled into the interface's audio side and drew fine horizontal stripes across the whole waterfall. Even a single short query every five seconds showed as a click. The cure was to send as little as possible: the rig is put in a mode where it reports frequency and mode changes on its own (Auto-Info on Elecraft and Kenwood rigs), and the page sends only a slow keep-alive query. If your waterfall changes when the CAT link connects, suspect polling first.
5.5 Ask, never assume
The radio may have been power-cycled, retuned at the front panel, or left in an odd mode by another program since the page last looked. The connect sequence therefore reads the rig's state before setting anything, and the disconnect sequence always returns the rig to its quiet power-on reporting mode so the next program finds it in a known state.
5.6 Confirm by the rig's reply, not by a timer
After a set command the program waits for the rig to report the new value, with a generous timeout, rather than assuming success after a fixed delay. That approach also exposed a real defect: the K2 ignores the last digit of a frequency command and tunes in 10 Hz steps, so a request for 14.071.002 MHz was correctly tuned to 14.071.000 and a strict confirm waited forever. Frequencies are now rounded to the rig's step before sending, and confirmation allows one step of tolerance.
5.7 Put a gate in front of every write
Every byte bound for the port passes through one write function that classifies the command against a table of verified commands. Unknown commands are refused, transmit commands are refused unless the page has explicitly been permitted to transmit, and the transmit state is checked immediately before each command. Putting the rule in the shared module, rather than in each page, means no page can bypass it by accident. Now that DigiMode transmits, the commands that can key a rig - its transmit command, a tuner start, VOX - are still refused: the rig is keyed by a line instead (lesson 5.13).
5.8 Make the read loop robust
Unplugging the cable, cancelling a reader, or a driver reset can each leave the loop spinning on an empty stream if it is not written carefully. Use a flag to stop the loop, yield between passes, and route the browser's disconnect event through the same tidy-up path as the Disconnect button.
5.9 On Android, Web Serial may not see your interface - WebUSB can
Chrome on Android has Web Serial, but it lists only USB CDC-ACM devices and Bluetooth serial
ports. A vendor bridge chip - the Digirig's Silicon Labs CP2102N, an FTDI, a CH340 - is not
offered at all: on my Pixel 8a, Chrome asked for permission and then showed an empty list. Android
also leaves such a chip unclaimed, with no driver bound to it, and that is the opening: a page can
claim the chip itself over WebUSB (navigator.usb) and talk to it in
the chip maker's own language. What that took:
- The vendor protocol. The CP210x is set up with Silicon Labs' AN571 requests: enable the UART, switch RTS and DTR both off at once, set the baud rate (4800) and the line format (8N2), then purge. The control lines go off straight after enable, before a single byte is sent.
- Endpoints from the descriptor. The Digirig's bulk endpoints are 2 in and 2 out. Code that assumed endpoint 1 would have failed; read them from the device's interface descriptor.
- Replies in small pieces. The K2's replies arrived in 3-byte chunks about 10 ms apart, so a read loop that buffers until the semicolon, as in the skeleton, matters even more.
- One driver per chip family. Every bridge chip speaks its own vendor protocol, so WebUSB support is written chip by chip, and the program picks the driver by the device's USB vendor and product IDs - refusing any chip it has no driver for rather than guessing. My programs now carry three: the Silicon Labs CP210x (the Digirig), the FTDI FT232R (0403:6001, for example FTDI's US232R cable) and the MCT U232 (050D:0109, the Belkin F5U109/F5U409). CH340, CP2105 and PL2303 are not done yet. A phone whose maker binds its own driver to the chip would block this path, and only one phone has been tried.
- Each chip has its quirks. The FTDI puts two status bytes at the front of every packet it sends, which must be stripped before the data reaches the frame splitter; it takes a baud divisor (625 from a 48 MHz base for 4800). The MCT takes a baud code instead (0x06 for 4800), delivers its received data on an interrupt endpoint rather than a bulk one, and accepts at most 16 bytes per write. Data arrives in different-sized pieces from each - 3 characters about every 10 ms from the CP210x, 4 or 5 about every 16 ms from the FTDI, one about every 3.5 ms from the MCT - so, again, buffer until the semicolon.
- Where the protocol facts came from. For the CP210x, Silicon Labs' AN571. For
the FTDI and MCT, which publish no equivalent for this purpose, the Linux kernel's own USB-serial
drivers (
ftdi_sioandmct_u232) were read as protocol references - which request does what, and in what order. No kernel code was copied. - The bench first. Each new driver was worked out on a separate test page before it went near the programs, and proven there on the phone with the K2: connect, a 60-second CAT soak, an RTS-to-CTS loopback through the cable (which proves the line control with no RF), keying, and transmit audio into a dummy load at 0.1 W. Only then was it built in.
- Serial and audio may be two devices. The Digirig carries rig control and audio on one cable. An FTDI or Belkin adapter carries only the serial link, so for receive audio it and a Digirig (or another USB sound interface) go on a USB hub between the phone and the rig - the phone has one USB port. Pulling the serial adapter then stops rig control only; the audio stops only if its own input goes away.
- The same gate, and no way to key. The WebUSB transports only move bytes: no driver, on any of the three chips, has a method that can raise RTS or DTR - each switches both off before anything is sent - and every command still passes the one write gate of 5.7. When the cable is pulled, nothing more is written to the departed device.
So on a phone the programs choose the path by platform: WebUSB to a supported chip on Android, Web Serial everywhere else, with a link on Android to use a Bluetooth serial port through Web Serial instead. iOS has neither API, so a phone there gets audio only.
5.10 On Linux, the port belongs to the dialout group
A Debian 13 laptop with current Chrome and Firefox could not open the K2's port from either program, although minicom on the same laptop reached the radio and ran commands. Both pages said the port was "already in use". Nothing else held it. The cause was permission:
- The device files belong to a group. On Linux the serial ports
(
/dev/ttyS*for a built-in port,/dev/ttyUSB*for a USB adapter) are owned byrootand thedialoutgroup. A browser opens the port as the logged-in user, and that user was not indialout. minicom most likely worked because it was run as root. - The fix.
sudo usermod -aG dialout $USER, then reboot. The new group applies only to a fresh login, and on a desktop session logging out is not always enough. Until thenidstill shows the old groups;getent group dialoutshows at once that the change was saved. After a reboot both programs connected, in Chrome and in Firefox 153.4. - Why a Pi never showed it. Raspberry Pi OS puts its default user in
dialout; a fresh Debian install does not. - The lesson for the program. Chrome reports this permission fault with the
same "Failed to open serial port" it uses when another program holds the port. My programs
translated that into plain words as "already in use" - right on Windows, and on Linux a message
that sends the operator hunting for a program that is not there. Do not map a generic open failure
to "in use" alone: on Linux, name the
dialoutgroup as the other likely cause. Both programs now do (DigiMode v1.12.0 and the K2 CAT Terminal v1.0.17): on Linux the message names the group and the command, then the "already in use" explanation; elsewhere it is as before.
5.11 A right message nobody sees
Building the dialout message of 5.10 turned up an older fault.
When a connect failed, DigiMode put the correct explanation on the screen - and then its tidy-up
ran, closed the port that had never opened, and at once replaced the explanation with "Port closed
and released". The operator never saw the reason. The fault had been there since at least version
1.4.0.
- How it hid. The test suite checked that the failure text was present in the program's source. It was. Nothing checked that the text was still on the screen once the failure path had finished.
- The fix. A failure path now tells the tidy-up to keep the message it found. One test fails a connect and then reads the message panel the operator would see; another makes sure an ordinary Disconnect still reports the port closed.
- The lesson. Clean-up after a failure must not overwrite the reason for the failure, and a test of an error message should check what the operator ends up looking at, not only that the words exist somewhere in the code.
5.12 Hardware flow control can key the rig
flrig, the source of DigiMode's rig definitions, sets RTS/CTS hardware flow control for the Kenwoods DigiMode now supports. With hardware flow control the operating system drives RTS itself - and on the Digirig and many other interfaces RTS is the PTT line, so asking for flow control would hand the transmitter's key to the serial driver. DigiMode therefore opens every rig with flow control off and holds RTS and DTR off, whatever the rig's definition says. The cost is that a Kenwood whose COM port expects RTS/CTS may need its own flow control turned off before it answers. That has not yet been tried on a real Kenwood; a tester's report would settle it.
5.13 The line is the key - and the unkey
DigiMode's transmitter keys the rig by the serial port's RTS or DTR line, or by VOX, never by a CAT command. Before any of it was built, a small bench page probed the lines at the K2, from a Raspberry Pi and from Windows:
- Opening a port raises RTS until the page forces it off, on both systems. The rig may click into transmit and out again as the port opens, so leave it in receive when connecting, and put an amplifier in standby.
- Closing the port, a crashed tab and a killed browser all drop RTS; the K2 was back in receive within two or three seconds at most. A page that dies cannot leave the rig keyed by the line.
- A CAT receive command does not unkey a rig whose RTS is held. The K2 ignored
RX;while RTS was up. So the line is the unkey: DigiMode drops the line first, then sendsRX;as a second word. - The rig talks back while transmitting. The K2 answered DigiMode's 15-second
display read with
?;during a transmission, so the heartbeat - or a rig's polling - is now held until the transmission ends.
The guards that end a transmission - a limit on its length and a check that the operator is still there - run on the transmit audio clock, so a hidden or minimised tab keeps them.
6. Adapting This to Other Rigs and Interfaces
6.1 Common USB-serial chips
| Chip family | USB vendor ID | Seen in |
|---|---|---|
| Silicon Labs CP210x | 0x10C4 | Digirig Mobile; built-in USB on many current transceivers |
| FTDI FT232 and relatives | 0x0403 | Better-quality USB-serial and CAT cables |
| WCH CH340 / CH341 | 0x1A86 | Low-cost cables and microcontroller boards |
| Prolific PL2303 | 0x067B | Older USB-serial cables |
If you are unsure which chip your cable uses, call requestPort() with no filter, pick
the port, and read port.getInfo(), which returns the vendor and product IDs. Then add
the filter if you still want one.
On Android none of these chips appears in Web Serial (lesson 5.9); my programs carry WebUSB drivers for the CP210x, the FTDI FT232R and the MCT U232 (Belkin F5U109/F5U409). CH340, PL2303 and the CP2105 dual UART are not supported on a phone yet.
6.2 Protocol families
- Kenwood-style text CAT (Kenwood, Elecraft, and many others in compatibility
mode): ASCII commands ending in a semicolon, such as
FA;to read VFO A. The skeleton above fits this family directly. - Icom CI-V: binary frames beginning
FE FEand endingFD, with a radio address byte. The read loop is the same, but frames are split on the 0xFD byte and parsed as bytes rather than text. Lesson 5.2 matters even more here. - Yaesu: newer rigs use a Kenwood-like semicolon text format; older rigs use fixed-length binary blocks. Check the CAT manual for your model.
- PTT only: a page that just needs to key a transmitter can open the port and
drive RTS or DTR with
setSignals(), sending no data at all. Treat that line with the same care as a transmit command. DigiMode does this with its No rig control (PTT only) entry - for a keying-only port such as microHAM Router's PTT port.
6.3 Practical cautions
- Match baud rate, data bits, parity and stop bits to the rig's menu exactly; a mismatch usually shows as silence or garbage, not an error.
- A loopback plug (TX tied to RX) echoes your own commands back. Real rigs mostly do not echo, so the parser should ignore bare queries it receives.
- Ground loops and RF on the USB cable can lock up or confuse both the interface and the rig. Ferrites, short cables and audio isolation are worth having before blaming the code.
- Build or check the cable to the rig maker's drawing. Elecraft warns against any pre-assembled cable between the KIO2 and a computer; the kit's own cable joins pins 7 and 8 (an RTS/CTS loop-back) at the computer end only, because at the K2 end those pins are RF Detect and the DC supply. A cable that looks right can still put a line where it does not belong.
- Test transmit-capable code into a dummy load first, and never let a page key the rig without a deliberate operator action.
7. References
- W3C Web Platform Incubator Community Group, Web Serial API draft specification.
- MDN Web Docs, Web Serial API.
- Chrome for Developers, Read from and write to a serial port.
- Mozilla Hacks, Announcing Web Serial Support in Firefox (May 2026).
- Chromium blink-dev, Intent to Ship: Web Serial API on Android (Chrome 148, March 2026).
- Can I use, Web Serial API support tables.
- MDN browser-compat-data, issue 23802 - Web Serial on Android lists CDC-ACM and Bluetooth RFCOMM ports only.
- Silicon Labs, AN571: CP210x Virtual COM Interface Specification - the vendor requests used to drive the CP210x over WebUSB.
- The Linux kernel USB-serial drivers
ftdi_sio(Greg Kroah-Hartman, Bill Ryder, Kuba Ober, Johan Hovold and others) andmct_u232(Wolfgang Grandegger) - read as protocol references for the FTDI FT232R and MCT U232 over WebUSB; no code was copied. GPL-2.0-or-later. - flrig 2.0.12, by Dave Freese, W1HKJ, and contributors - the source of DigiMode's rig definitions (read as data; no code copied). GPL-3.0-or-later.
- Elecraft, KIO2 Programmer's Reference, Rev. E (2004) - the K2 command set used in the examples.
- Elecraft, KIO2 Aux I/O Module manual, Rev. C - "K2 to Computer Cable Assembly", pp. 13-14, and Table 2, p. 22 (the K2-end pins).
For the programs themselves, and how a ham and an AI built them together, see The WA5PB Ham Radio AI Project.
73 de WA5PB