Skip to main content

Acessing Serial Interface

The different serial interfaces are abstracted as device files. These files are in the /dev directory. The files for the serial interfaces are named like ttyx or ttySx or ttyUx. The x is a running number.

Reading and Writing

The files in the /dev directory can be accessed like normal text files. That means you can read data with a normal program like cat. The following is an example for reading data from the serial interface ttyS0:

$ cat /dev/ttyS0

Then you see the data which will be received on the first serial interface.

If you want to send some data over the serial interface you can also use standard programs from the Linux OS. In the following listing you see an example for sending a string over ttyS0:

$ echo "Hello World" > /dev/ttyS0

Configure Parameters

For the configuration of the interface-specific parameters you can use the program stty.

With the following line you can see the settings of the special interface:

stty -F /dev/ttyS0

Then you can change the parameters of the interface. With the following command you can set a new baud rate for the interface:

stty -F /dev/ttyS0 9600