Wednesday, November 22, 2017

Proxy serial over TCP with socat

I recently needed to talk to a serial port from a remote system.  I found a Linux tool called socat - Multipurpose relay (SOcket CAT) that worked perfectly.  The target was a Raspberry Pi with a connected serial device.

To install socat on the Raspberry Pi, and the friend Ubuntu system:

sudo apt-get udpate
sudo apt-get install socat

On the Raspberry Pi I started the socat server with:

# socat tcp-listen:8000,reuseaddr,fork file:/dev/ttyUSB0,nonblock,waitlock=/var/run/tty0.lock,b115200,raw,echo=0

This will connect to the serial port, and stay connected after disconnected clients.

On the Ubuntu friend system I started the socat client with:

socat pty,link=/dev/ttyUSB0,waitslave

After each disconnect the socat client will disconnect as well.  To keep it running, throw it in a loop:

# while true ; do socat pty,link=/dev/ttyUSB0,waitslave ; sleep .001 ; done

I then used tio (or minicom) to talk to the remote serial port:

# tio -b 115200 /dev/ttyUSB0
[tio 16:53:30] tio v1.20
[tio 16:53:30] Press ctrl-t q to quit
[tio 16:53:30] Connected

> I sent something to the serial port

minicom - friendly serial communication program


minicom - is a menu driven communications program. It emulates ANSI and VT102 terminals. It has a dialing directory and auto zmodem download.


# on RedHat based:
yum install minicom

# on Debian based:
sudo apt-get install minicom

Special Keys

# Menu

# To Quit

# To send (via xmodem/ymodem/zmodem)

# To receive (via xmodem/ymodem/zmodem)

# To configure

Command Line

# Bring up minicom configuration
minicom -s

# Connect to ttyUSB0 with 115200 baud rate
minicom -b 115200 -D /dev/ttyUSB0
The default configuration is 115200 8N1 with Hardware Flow Control. I usually disable Hardware Flow Control in my setting and save to the default 'df1'.


Although minicom describes itself as "friendly", it can be painful to setup and use.  As a suggestion, if you don't need send/receive abilities like xmodem, tio is much easier to use.


tio - A simple TTY terminal I/O application

Minicom is painful to use. I found a much easier tool to use called tio - A simple TTY terminal I/O application.


tio /dev/ttyUSB0
tio -b 115200 /dev/ttyUSB0  # 115200 is the default baud rate

Installing Tio

Using the release tar method:
mkdir ~/.src
cd ~/.src
tar -avxf tio-1.20.tar.xz
cd tio-1.20/
make && make install

Using the source source method:
sudo apt-get install autoconf
mkdir ~/.src
cd ~/.src
git clone
cd tio
make && make install

Example Usage

# tio -b 115200 /dev/ttyUSB0
[tio 16:53:30] tio v1.20
[tio 16:53:30] Press ctrl-t q to quit
[tio 16:53:30] Connected

> some serial text


To exit tio:
ctrl-t q

Other references

Thursday, March 30, 2017

Pi is a Palindrome

I know the last few digits of Pi...

Inside a mathematical singularity where infinity ends, where two parallel lines meet in Euclidean space, it turns out Pi is a Palindrome.  :-)

Full Comic

Tuesday, March 14, 2017

Pi Day

Happy Pi Day Everyone!  Today is 3.14, so eat plenty of pies.


Saturday, March 11, 2017

Daylight Saving Time is Upon Us

Daylight Saving Time is upon us tonight - Sunday, March 12th, 2017 at 2am.  Don't forget to turn your "non-smart" clocks forward an hour.

I like to remind myself with, the following which helps me remember which direction to turn the clocks to.

"Spring" forward into action, and "Fall" back to sleep.

Friday, March 10, 2017

Why Fundamental Forces Are Difficult To Explain

Richard Feynman was asked Why Magnets Repel Each Other?  His answer sums up why it is so difficult to explain physics.  It requires accepting other answers as truth, or you rabbit hole down an endless path of why questions.  We take for granted that when your hand pushes against a chair it moves.  But your physical hand never actually touches the chair.  The electrical forces repel the chair at a minuscule level.  The magnetic force is very similar to the electrical forces.  The iron atoms of a magnet are all lined up so the magnetic forces are amplified to where they cross a greater distance.