Chapter Contents

Previous

Next
cfsetospeed

cfsetospeed



Set Output Baud Rate

Portability: POSIX.1 conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
PORTABILITY
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <termios.h>

int cfsetospeed(struct termios *terminal, speed_t speed);


DESCRIPTION

cfsetospeed is used to set a new output baud rate in the termios structure. ( terminal points to a copy of this structure.) This structure is defined in <termios.h> and contains terminal attribute information.

The tcgetattr function must be used to make a copy of the termios structure before you can use the cfsetospeed function to set the output baud rate. The cfsetospeed function changes the baud rate in this copy and the tcsetattr functions can then be used to update the termios control structure.

The defined type, speed_t , specifies the baud rate. 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


RETURN VALUE

If successful, cfsetospeed returns 0 . A -1 is returned if unsuccessful.


PORTABILITY

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


EXAMPLE

The following example illustrates the use of cfsetospeed to set a new output baud rate:

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

main()
{
   struct termios termAttr;
   speed_t baudRate;

      /* Obtain a copy of the termios structure for stdout. */
   tcgetattr(STDOUT_FILENO, &termAttr);
      /* Get the output speed.                              */
   baudRate = cfgetospeed(&termAttr);
      /* Set output speed if not 9600 baud.                 */
   if (baudRate != B9600) {
      cfsetospeed(&termAttr, B9600);
      tcsetattr(STDOUT_FILENO, TCSADRAIN, &termAttr);
   }
}


RELATED FUNCTIONS

cfgetospeed , cfsetispeed , tcsetattr


Chapter Contents

Previous

Next

Top of Page

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