Acessing Serial Interface

From InCircuit
Jump to: navigation, search

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 accessed like normal text files. That means you can read data with a normal programm 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 recieved on the first serial interface.

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

 $ echo "Hello World" > /dev/ttyS0

Configure Parameters

For the configuration of the interface-specific parameters you can use the programm 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
Personal tools