Chapter Contents

Previous

Next
cfgetispeed

cfgetispeed



Determine Input Baud Rate

Portability: POSIX.1 conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
PORTABILITY
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <termios.h>

speed_t cfgetispeed(const struct termios *termptr);


DESCRIPTION

cfgetispeed returns the input baud rate, which is stored in the termios structure pointed to by termptr . This structure is defined in <termios.h> and contains terminal attribute information.

The tcgetattr function must be used to obtain a copy of the termios structure before you can use the cfgetispeed function to extract the input baud rate from the copy of the structure. The cfsetispeed and tcsetattr functions can then be used to change the input baud rate.


RETURN VALUE

The return value is a defined type, speed_t , which is located in <termios.h> . Each value is associated with an asynchronous line speed as follows:

Return Value Baud Rate
B0 hang up
B50 50 baud
B75 75 baud
B110 110 baud
B134 134.5 baud
B150 150 baud
B200 200 baud
B300 300 baud
B600 600 baud
B1200 1200 baud
B1800 1800 baud
B2400 2400 baud
B4800 4800 baud
B9600 9600 baud
B19200 19,200 baud
B38400 38,400 baud


PORTABILITY

The cfgetispeed function is defined by the POSIX.1 standard and provides portability between operating environments. Note that UNIX System Services (USS) only supports pseudoterminals and that baud rate does not affect the operation of a pseudoterminal.


EXAMPLE

The following code fragment illustrates the use of tcgetattr and cfgetospeed to determine the speed of stdin .

#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>

main()
{
   struct termios termAttr;
   speed_t baudRate;
   char *inputSpeed = "unknown";

      /* Obtain a copy of the termios structure for stdin. */
   tcgetattr(STDIN_FILENO, &termAttr);
      /* Get the input speed.                              */
   baudRate = cfgetispeed(&termAttr);
      /* Print input speed.                                */
   switch (baudRate) {
      case B0:      inputSpeed = "none"; break;
      case B50:     inputSpeed = "50 baud"; break;
      case B110:    inputSpeed = "110 baud"; break;
      case B134:    inputSpeed = "134 baud"; break;
      case B150:    inputSpeed = "150 baud"; break;
      case B200:    inputSpeed = "200 baud"; break;
      case B300:    inputSpeed = "300 baud"; break;
      case B600:    inputSpeed = "600 baud"; break;
      case B1200:   inputSpeed = "1200 baud"; break;
      case B1800:   inputSpeed = "1800 baud"; break;
      case B2400:   inputSpeed = "2400 baud"; break;
      case B4800:   inputSpeed = "4800 baud"; break;
      case B9600:   inputSpeed = "9600 baud"; break;
      case B19200:  inputSpeed = "19200 baud"; break;
      case B38400:  inputSpeed = "38400 baud"; break;
   }
   printf("Input speed = %s\n", inputSpeed);
}


RELATED FUNCTIONS

cfgetospeed , cfsetispeed , tcgetattr


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.