Serial Port Programming – Reading/Writing Status of Control Lines: DTR/RTS/CTS/DSR

tiocmget and tiocmset

In the 2.4 and older kernels, there used to be a number of tty ioctl calls to get and set the different control line settings. These were denoted by the constants TIOCMGET, TIOCMBIS, TIOCMBIC, and TIOCMSET. TIOCMGET was used to get the line setting values of the kernel, and as of the 2.6 kernel, this ioctl call has been turned into a tty driver callback function called tiocmget. The other three ioctls have been simplified and are now represented with a single tty driver callback function called tiocmset.

If the user is interested in finding out the status of Control Lines:DTR/DSR/RTS/CTS, he can use ‘TIOCMGET’ control code in the ioctl call. ‘TIOCMSET’ control code in ioctl allows you to set/clear DTR and RTS lines as they are output.

Example Code

Consider the example shown below:

#include <stdio.h>
#include <sys/types.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define SERIAL_DEVICE "/dev/ttyUSB0"
int set_DTR(int fd, unsigned short level)
{
 int status;

 if (fd 

Output:

Related Post