Binterm
Binterm - An Ultra-Simple Terminal Program
I work on a wide variety of microcontroller-based systems. My preferred development platforms for cross-compiling are Linux and Mac OS X. Frequently, I need interact with the serial port on the microcontroller system for development and testing purposes. Both Linux and Mac OS support the ‘screen’ command natively. You can use the screen command to connect serial devices like this:
screen /dev/serial.device 9600 (or whatever baud rate is necessary)
That works just fine, as long as you dont need to dump the output from your microcontroller (uC) system in hex, log it to a file, or any number of other functions. There are a number of gui-based serial console programs, but most of them have long been abandoned, and usually require a list of libraries as long as your arm to compile. I needed something simpler, something portable, something that would let me interact with a system easily, dump to hex, log, and shell out to other arbitrary programs (e.g. avrdude). Something that would easily run on other quasi-embedded systems themselves, like the Raspberry Pi. And better yet, something that works inside of the terminal window in Emacs or VSCodium. And so, ‘binterm’ was born. Binterm is about as simple a serial terminal as you can get. There is no GUI. Source is a single C file which compiles easily and cleanly on Linux and MacOS systems. It’s trivial to modify. If you make useful modifications, I would love to hear from you so I can include them for others to enjoy.
Source and Binaries
The source code and Makefile in both tar files is identical; the only difference is the ‘.binterm’ sample file (see below) that is included.
Configuration
Binterm uses both a dot file, ‘.binterm’, and accepts a small set of command line arguments. The dot file must be located in the current working directory, or in the users $HOME directory. The dot file is read first, then the command line paramaters are parsed. Therefore, it’s is easy to over-ride the setup from the command line as needed.
.binterm
The dot file is a simple text file. Blanks lines, and lines prefixed with the ‘#’ are ignored as comments. The remainder of the file consists of parameter/value pairs expressed in the following format:
paramter=value or string
The supported parameters are:
baudrate - sets the default baudrate device - sets the default serial device 1-9 - sets the macro definitions (see Use below)
Command Line Parameters
Usage: ./binterm -c device [options] -b baudrate [9600 default] -d 5,6,7 or 8 data bits [8 default] -p N,E or O parity [N default] -s 1 or 2 stop bits [1 default] -c device (defines the serial device to use) -l N(ewline), R(eturn), or C(RLF) line ending [N default] -h enable HW flow control
Use
Binterm is trivial to start (see command line parameters above). Once started you will be greeted with a message like this:
Terminal open. Press CTL-Q for command mode.
Any characters typed on the console, are sent unchanged to the serial device. Data received on the serial device is displayed on the console. Pressing CTL-Q gives you the command mode prompt:
Cmd:
The available single-key commands are as follows:
- CTL-Q - Exit command mode
- Q - Exit terminal
- H - Toggle hex mode
- R - Raw send hex values
- L - Toggle logging
- D - Display Macros
- 1-9 - Execute macro
Toggling hex mode enables a hex dump-style output mode that shows you the hexidecimal values of the data sent from the target. Logging records all of the data sent and received during the session to a local file. Raw send (R) allows you to key in a series of hex values that will be sent to the target (handy for hand testing with values that can’t easily be entered via key combinations). Hitting digits 1-9 execute the macros defined in the .binterm file. Note: macros currently just execute other programs on the host. Simple parameter substitution for the current serial device ($$D) and baud rate ($$B) are available. Binterm closes the serial device when the it executes a macro. It immediately re-opens the serial device when the external program completes.