Command line

The spu command line

One console program for SSH sessions, scripts, CI and services: a terminal, a TCP server for the port, a sharing agent or an MCP server.

On this page

The spu command line

The direct-download and Microsoft Store builds ship a small console program, spu, next to the application (the Mac App Store build does not include it). It needs no desktop session, so it is the tool for a lab PC over SSH, a Raspberry Pi beside the bench, a CI job or a systemd service. One spu opens one port and is one of these:

  • a terminal: your keyboard to the port, the port to your screen, or a pipe in and out for scripts;
  • a TCP server for the port (--listen), the way ser2net does it;
  • a Live Relay or Live Share agent (--share, --invite), see Live Relay and Live Share;
  • an MCP server (spu mcp) that lets an AI coding assistant open ports, send commands and read the answers.
spu -l                                         # list local serial ports
spu -D /dev/ttyUSB0 -b 115200                  # terminal
spu -D COM3 -b 9600 --parity even --data-bits 7
spu -D rfc2217://192.168.1.20:2217 -b 57600    # a remote serial port
spu -D /dev/ttyUSB0 --listen 4000              # serve it on TCP port 4000
spu mcp -D /dev/ttyUSB0                        # for Claude Code, Cursor, ...

spu --help lists every option.

The terminal

spu -D <port> -b <baud> connects the keyboard to the port. The terminal is raw: Ctrl+C, Ctrl+Z, Ctrl+S and Ctrl+Q go to the device like any other key, which is what a shell or a bootloader on the other end expects. Enter sends CR; --enter lf or --enter crlf changes that.

spu's own commands come after Ctrl+]:

Keys Does
Ctrl+] then q quit
Ctrl+] then b send a 250 ms Break
Ctrl+] then d toggle DTR
Ctrl+] then r toggle RTS
Ctrl+] then ? show these, with the current DTR and RTS levels
Ctrl+] twice send Ctrl+] itself

--escape ^A (or any Ctrl+letter) picks another key, and --escape none turns the commands off; then spu stops only on a signal, a timeout or when the port goes away.

The line settings are the ones the application offers: --data-bits 5|6|7|8, --parity none|even|odd|mark|space, --stop-bits 1|1.5|2, --flow none|rtscts|xonxoff, and --dtr on|off, --rts on|off for the levels after opening (both on by default; many boards reset when DTR changes). Every option is checked before the port opens, so a typo never toggles a line on somebody's board.

How the output looks:

  • -x / --hex prints what the device sends as hex, one line per read;
  • -t / --timestamp starts every line with the local date and time, to the millisecond;
  • --log FILE appends the same output to a file as well.
spu -D /dev/ttyUSB0 -b 115200 -t --log boot.log

Scripts and pipes

With standard input redirected, spu sends what it reads and exits 0 once all of it has left the port. It does not wait for an answer, unless you give a timeout:

  • --idle-timeout 300ms ends the run once nothing has moved either way for that long, counted after all the input was sent;
  • --timeout 10s ends it after that long.

With either one, the end of input no longer ends the run, so the device's answer is printed:

printf 'AT\r' | spu -D /dev/ttyUSB0 --idle-timeout 300ms
printf '01 03 00 00 00 01 84 0A' | spu -D /dev/ttyUSB0 -b 9600 --hex-in -x --idle-timeout 200ms

--hex-in reads standard input as hex text: 01 03, 0x01,0x03 and 0103 all work, every token must be whole bytes, and # starts a comment, so a file of requests can explain itself. --no-input reads nothing and only receives -- for capturing to a file until --timeout, or for good under systemd:

spu -D /dev/ttyUSB0 -t --log /var/log/sensor.log --no-input --reconnect

Durations take ms, s, m or h; a bare number is seconds.

Network targets

-D also takes a network address:

Target What it is
tcp://host:port a raw TCP connection, e.g. a device server in TCP mode
udp://host:port datagrams to and from one peer
rfc2217://host:port a remote serial port over RFC 2217: the baud rate, framing, flow control and DTR/RTS travel to the far port

An IPv6 address goes in brackets: tcp://[fe80::1]:23. Line settings only make sense for rfc2217://; with tcp:// and udp:// they are refused. An RFC 2217 server that turns out not to support the option is still used, and spu says how (plain Telnet or raw TCP). See RFC 2217 client for what RFC 2217 is.

Serve a port on TCP (--listen)

--listen puts the serial port on a TCP port instead of the terminal, with no desktop session -- the job ser2net does:

spu -D /dev/ttyUSB0 -b 115200 --listen 4000                        # this machine only
spu -D /dev/ttyUSB0 --listen '*:4000' --allow 192.168.1.0/24       # the LAN, one subnet
spu -D /dev/ttyUSB0 --listen 2217 --listen-protocol rfc2217        # an RFC 2217 server
spu -D /dev/ttyUSB0 -b 9600 --listen '*:502' --listen-protocol modbus
  • A bare port number listens on 127.0.0.1 only. Give an address, or * for every address, to let other machines in; without --allow, spu warns that anyone who can reach that address can use the port.
  • --listen-protocol raw (the default) passes bytes unchanged. rfc2217 lets the client set the baud rate, framing and control lines over the same connection. modbus is a Modbus TCP to RTU gateway: TCP masters on one side, the RTU bus on the serial port.
  • One client at a time; a second one is refused while the first is connected.
  • --allow (repeatable) takes an address or a subnet such as 10.0.0.0/8.
  • --log FILE writes a capture of both directions in hex.

It is the same implementation as the application's RFC 2217 server, including its back pressure and its handling of RFC 2217 commands.

When the port goes away

If the device is unplugged or the network peer hangs up, spu closes the port and exits with code 7, in every mode, sharing included -- so a service manager can restart it rather than leave a process holding a port that no longer exists.

--reconnect makes it wait instead: a serial port is retried every second, a network peer every two seconds, and spu carries on when it is back. It also waits when the port is not there yet at start-up. Typed keys are dropped while it waits; piped input waits too.

For AI assistants (spu mcp)

spu mcp is a Model Context Protocol server on standard input and output. Register it with your assistant and it can list ports, open one, send a command and read the reply, drive DTR, RTS and Break, and change the line settings. For Claude Code:

claude mcp add spu -- spu mcp -D /dev/ttyUSB0

Other assistants take the same command line in their MCP settings ("command": "spu", "args": ["mcp", "-D", "COM3"]).

The tools are list_ports, open_port, close_port, write, read, exchange, set_control_lines, configure_port and port_status. The one an assistant uses most is exchange: it drops whatever was received earlier, sends the command and waits for the end of the reply -- until gives the text the reply ends with, such as OK\r\n or a shell prompt; without it the reply ends when the line has been quiet for 200 ms. What the device sends between two calls is kept per port (up to 1 MiB) until a read takes it. Bytes that are not printable text come back as \xNN, or ask for hex.

What it may open. With no -D, the assistant may open any local serial port. With one or more -D, only those -- name the port your board is on and the assistant cannot wander onto the one that drives something else. Network targets can only be allowed this way: spu mcp -D rfc2217://10.0.0.5:2217. Options such as -b 9600 or --parity even become the defaults for the ports it opens.

spu mcp is a process of its own: it does not see the ports the application has open, and a port open in the application cannot be opened by it at the same time.

Exit codes

Code Meaning
0 done: end of input, a timeout, or Ctrl+] q
1 a wrong option or value
2 the port cannot be opened, or --listen cannot bind
3 not signed in, or the sign-in could not be renewed (--share, --invite)
4 the invite could not be created
5 online features are not allowed yet (--accept-privacy)
6 not all of standard input could be sent
7 the port went away
128 + N stopped by signal N (130 for SIGINT, 143 for SIGTERM)

SIGINT, SIGTERM and SIGHUP from outside always put the terminal back, close the port and revoke an invite before spu exits.

Was this document helpful?