Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On Linux, I want to send a command string (i.e. some data) to a serial port (containing control characters), and listen to the response (which also usually might contain control characters).

How can I do this as simplest as possible on Linux? An example is appreciated!

share|improve this question
you should look at this unix.stackexchange.com/a/116705/53092 – Kiwy Feb 26 '14 at 12:28
I don't have interceptty installed. – Alex Feb 26 '14 at 12:32
nominating for re-opening - it's not a duplicate as suggested. – peterph Jul 1 '15 at 7:19
up vote 11 down vote accepted

All devices on Unix are mapped to a device file, the serial ports would be /dev/ttyS0 /dev/ttyS1 ... .

First have a look at the permissions on that file, lets assume you are using /dev/ttyS1.

ls -l /dev/ttyS1

You will want read.write access, if this is a shared system then you should consider the security consequences of opening it up for everyone.

chmod o+rw /dev/ttyS1

A very simple crude method to write to the file, would use the simple echo command.

echo -ne '\033[2J' > /dev/ttyS1

and to read

cat -v < /dev/ttyS1

You can have cat running in one terminal, and echo in a 2nd.

If everything is gibberish, then baud rate, bit settings might need setting before you start sending. stty will do that. !! NOTE stty will use stdin as default file descriptor to affect.

Equivilent commands.

stty -speed 19200 < /dev/ttyS1
stty -speed 19200 -f /dev/ttyS1

This might be enough for you to script something and log ? Not sure what you are trying to achieve.

For a more interactive, remembers your default settings approach would be to use minicom it is just a program which does everything I've mentioned so far. (similar to hyperterminal in Windows, you might be familiar).

An intermediate solution, would use a terminal program like screen which will work on a serial device.

screen /dev/ttyS1

man screen man minicom man stty for more information

share|improve this answer

All you have to do is open two terminals. In the first terminal you cat everything from the device, e.g.

cat /dev/ttyS0

in the other terminal, you can send arbitrary hex characters and text to the terminal e.g. as follows:

echo -e "\x7E\x03\xD0\xAF und normaler Text" > /dev/ttyS0

The echo -e command enables the interpretation of backslash escapes.

One has to make sure of course that (i) the serial settings (speed, word length, flow ctrl, etc) are correct and (ii) the serial device (on the other end) is not blocking.

share|improve this answer
You have answered this 10 mins after I wrote my answer above and you haven't added any further information at all ! – X Tian Feb 26 '14 at 15:24
Oh sorry, I did not read your answer completly. I saw that my answer is included in yours, so I will accept your answer as the correct one, as you described just what I have described. – Alex Feb 26 '14 at 16:06
I don't know much about COM ports. Could you please explain what does "the serial device (on the other end) is not blocking" mean? Some issue with the firewall? – Sopalajo de Arrierez Sep 13 '15 at 15:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.