WA5PB

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

Checked October 1, 2026; the Chrome on Android row, and my own test notes in the Chrome and Firefox rows, updated October 8 - 12, 2026 from my own testing. The other rows were not rechecked. Browser support changes; see Can I use (References) for the current picture.
BrowserStatusNotes
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

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.

LayerResponsibility
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

  1. Check for the API. If navigator.serial is missing, say so plainly (wrong browser, or not HTTPS) rather than failing later.
  2. Request the port from a button click. A vendor-ID filter is optional, and has a cost (see 2.2).
  3. 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.
  4. 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).
  5. 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.
  6. Ask the rig what state it is in before changing anything: identity, frequency and mode, and any reporting mode.
  7. 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.

JavaScript - minimal Web Serial CAT skeleton
// 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:

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:

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.

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:

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 familyUSB vendor IDSeen in
Silicon Labs CP210x0x10C4Digirig Mobile; built-in USB on many current transceivers
FTDI FT232 and relatives0x0403Better-quality USB-serial and CAT cables
WCH CH340 / CH3410x1A86Low-cost cables and microcontroller boards
Prolific PL23030x067BOlder 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

6.3 Practical cautions

7. References

For the programs themselves, and how a ham and an AI built them together, see The WA5PB Ham Radio AI Project.

73 de WA5PB