LinuxCommandLibrary

microcom

Communicate with serial ports

TLDR

Open a serial port using the specified baud rate

$ microcom [[-p|--port]] [/dev/ttyXYZ] [[-s|--speed]] [baud_rate]
copy

Establish a telnet connection to the specified host
$ microcom [[-t|--telnet]] [hostname]:[port]
copy

SYNOPSIS

microcom [options] device

Example: microcom -p /dev/ttyUSB0 -s 115200
Example: echo "ATZ" | microcom -p /dev/ttyS0 -s 9600

PARAMETERS

-p, --port device
    Specifies the serial port device to use, e.g., /dev/ttyS0 or /dev/ttyUSB0.

-s, --speed baudrate
    Sets the communication speed in bits per second (baud rate), e.g., 9600, 115200.

-d, --databits bits
    Configures the number of data bits per character (5, 6, 7, or 8). Default is 8.

-b, --stopbits bits
    Sets the number of stop bits (1 or 2). Default is 1.

-P, --parity type
    Defines the parity check: n (none), o (odd), or e (even). Default is none.

-H, --hangup
    Performs a DTR hangup on exit, often used to reset modems.

-X, --flow-control type
    Sets flow control: n (none), h (hardware RTS/CTS), or s (software XON/XOFF).

-N, --nocr
    Prevents sending a carriage return (CR) character when Enter is pressed.

-e, --escape char
    Sets the escape character. Default is Ctrl-A. Followed by 'X' to exit.

-o, --logfile file
    Logs all incoming and outgoing data to the specified file.

-c, --capture-file file
    Captures only incoming data to the specified file.

-q, --quiet
    Suppresses most informational messages during operation.

-v, --version
    Displays the microcom version information and exits.

-h, --help
    Shows a help message summarizing command usage and options.

DESCRIPTION

microcom is a lightweight, non-interactive serial port communication utility, typically distributed as part of the minicom package. While minicom provides a full-featured, menu-driven terminal emulator, microcom focuses on simplicity and command-line operability, making it ideal for scripting and automated tasks involving serial devices.

It allows users to send and receive data over a specified serial port (e.g., RS-232, USB-to-serial adapters), configuring parameters like baud rate, data bits, stop bits, and parity. This makes it invaluable for interacting with embedded systems, network equipment (like routers or switches with console ports), modems, or other hardware that communicates via a serial interface.

Unlike more complex terminal programs, microcom doesn't offer advanced features like file transfer protocols (ZModem, XModem) or extensive terminal emulation. Its strength lies in its ability to quickly establish a serial connection from the command line, pipe data into it, and capture output, facilitating debugging, configuration, and data logging in automated environments. It provides a straightforward way to bridge a shell script with a serial device.

CAVEATS

microcom is intentionally minimal. It lacks advanced features found in minicom, such as file transfer protocols (ZModem, XModem) and extensive terminal emulation capabilities.

Users must have appropriate permissions (e.g., be part of the dialout or uucp group) to access serial port devices.

The default exit sequence is Ctrl-A followed by X, which might be unexpected for new users. This can be changed with the -e option.

EXITING MICROCOM

By default, microcom exits when you press Ctrl-A followed by X. The escape character can be changed using the -e option.

SCRIPTING USAGE

microcom is particularly useful for scripting. You can send commands to a serial device by piping input to microcom and capture output by redirecting its standard output.
Example: echo "status" | microcom -p /dev/ttyS0 -s 9600 -o output.log

PERMISSIONS

Ensure the user running microcom has read/write access to the serial device file (e.g., /dev/ttyUSB0). This usually means being a member of the dialout or uucp group. You can add a user to the dialout group with:
sudo usermod -a -G dialout your_username (requires re-login).

HISTORY

microcom is a component of the minicom package, a popular terminal emulator for Unix-like systems. minicom itself originated in the early 1990s as a powerful alternative to DOS-based terminal programs like Procomm Plus.

While minicom evolved into a full-featured, menu-driven interactive tool, microcom was developed specifically to address the need for a non-interactive, command-line utility. Its design prioritizes ease of integration into shell scripts and automated workflows, offering direct serial port control without the overhead of a graphical or interactive interface. This divergence allowed users to leverage the core serial communication capabilities of minicom in headless or programmatic environments.

SEE ALSO

minicom(1), screen(1), cu(1), stty(1)

Copied to clipboard