I’m posting this mainly because Google didn’t turn up any help when I queried about using the USR-IOT serial port to ethernet converters (also known as terminal servers) with Linux. They make several low-cost devices that are really handy if you need to talk to serial devices that are far from the host computer. In particular, the USR-TCP232-410S single port converter and USR-N540 four port device are quite inexpensive. Their website has nary a mention of Linux compatibility, and I didn’t find any Google hits indicating that they work with anything other than Windows and maybe Mac.
It turns out that they work just fine under Linux, using standard protocols. You can even change speed as if the port were physically connected to the computer. Leaving the server set at its default settings, all you need to do on the Linux end is install the socat “multipurpose relay” tool (it’s available as a package in Debian-based distributions) and write a simple shell script.
Here’s what I’m using:
#!/bin/bash
# open virtual serial port
socat pty,link=$HOME/vmodem0,waitslave tcp:10.73.1.71:23 &
# run the program
./testcomms.py
# kill socat afterwards
killall socat
Customize the socat command line with the name of the port device (here $HOME/vmodem0, but you can name it and place it wherever you want), and the IP address and port of the serial server.
This worked on the first try, suspiciously easily.
It appears that socat destroys the vmodem0 device when the called program finishes running, but does not kill its process. That’s why I stuck the killall command on the last line. There is probably a way to make the device persistent so you would only need to run the socat command once at bootup, but I haven’t dug around for it yet.
3 comments
Hi there
Very interesting reading. I’ve searched for this information for quite some time
How do you configure the USR-TCP232 unit when it comes to TCP/UDP/Servermode etc?
Hi Steen —
I don’t have the system in front of me right now, but I think I was able to use pretty much the default settings on the USR-TCP232.
Nice. Just had disable flow control in the web interface then i could short pins 2 & 3, connect with minicom and it echos back. whatever I type.
in one terminal
socat pty,link=$HOME/vmodem0,waitslave tcp:192.168.1.7:23
in another
minicom -D $HOME/vmodem0
it does seem to drop inactive connections with these settings, have not looked into that yet.
Next is to try get modbus working.