Sending Serial data over TCP/IP in command line

I’ve wracked my brain over this and been through several dozen help files and tutorials, and just cannot figure how to properly do this in Linux.

The situation is that I need to send serial text to a LAN modem. (Baud=9600, Data: 8-bits, Parity: none, Stop; 1bit, Flow Control: none)
The lan modem waiting for serial data on TCP/IP port 10001.
Let’s say that for this situation the ip is
I need to send this data using a command line in ubuntu 20.04
In the serial data are also carriage return "n" and the ctrl+z command.
The TCP connection MUST close after the information is sent.

I’ve tried opening the connection with socat, but I can’t figure out how to pipe the information into the PTY.

Asked By: DesignerJT


You can use socat to establish a TCP connection to the LAN modem on port 10001 and send serial data to it from the command line in Ubuntu 20.04. To send the data with carriage return ("n") and the Ctrl+Z command, you can use the echo command and then pipe the output to socat.

Use the following command to establish a TCP connection to the LAN modem and send your serial data:

echo -e "YourSerialDataHerenx1A" | socat - TCP4:

Replace "YourSerialDataHere" with the actual serial data you want to send.

echo -e: This option is used to enable interpretation of escape sequences like "n".
"n": This adds a carriage return to the serial data.
"x1A": This is the Ctrl+Z character.

After running the command, socat will establish a TCP connection to the LAN modem at IP address on port 10001 and send your serial data.
The connection will automatically close once the data is sent.

Make sure to replace "YourSerialDataHere" with your actual serial data.
This command sends the data as you specified with the desired baud rate, data bits, parity, stop bits, and flow control.

Answered By: kyodake
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.