conexus logo

Conexus::TTY Class Reference
[Conexus I/O Endpoints]

This class extends Serial to include operations upon TTY (TeleTYpe) serial communications. More...

#include <tty.h>

Inheritance diagram for Conexus::TTY:

Inheritance graph
[legend]

List of all members.

Public Types

typedef ConexusPointer< TTYpointer

Public Member Functions

 CONEXUS_ENDPOINT_GENERIC_CREATE ()
virtual ~TTY ()
virtual void drain ()
 waits until all output written to the object has been transmitted.
virtual void flush_input ()
 discards data received but not read
virtual void flush_output ()
 discards data written to the object but not transmitted
virtual void flush ()
 discards both data written to the object but not transmitted and data received but not read
virtual void suspend_output ()
 Suspends transmission of data by the object.
virtual void restart_output ()
 Resumes transmission of data by the object.
virtual void suspend_input ()
 Suspends reception of data by the object.
virtual void restart_input ()
 Resumes reception of data by the object.
void set_input_speed (unsigned speed, SetOption option=SET_NOW)
 Sets the input line speed.
void set_output_speed (unsigned speed, SetOption option=SET_NOW)
 Sets the output line speed.
void set_speed (unsigned speed, SetOption option=SET_NOW)
 Sets both the input and output line speeds.
unsigned input_speed ()
 Returns the current input line speed.
unsigned output_speed ()
 Returns the current output line speed.
void set_parity (Parity parity, ParityError error=PARITY_ERROR_IGNORE, SetOption option=SET_NOW)
 Sets parity mode.
Parity parity ()
 Returns the current parity mode.
ParityError parity_error ()
 Returns the current parity error mode.
unsigned byte_size ()
 Get the current byte size in bits.
void set_byte_size (unsigned size, SetOption option=SET_NOW)
 Sets the communication byte size Valid values are:
  • 5 bits-per-byte
  • 6 bits-per-byte
  • 7 bits-per-byte
  • 8 bits-per-byte (default) All other values are ignored.

unsigned stop_bits ()
 Get the number of stop bits (1 or 2).
void set_stop_bits (unsigned size, SetOption option=SET_NOW)
 Sets the stop bits; only values of 1 or 2 will be processed, all others will be ignored.
FlowControl flow_control ()
 Returns the flow control method.
void set_flow_control (FlowControl flowcontrol, SetOption option=SET_NOW)
 Sets the flow control flags according to the flow control method specified.
bool is_carrier_detect_enabled ()
 True if the hardware carrier detect (DCD) is enabled, false otherwise.
void enable_carrier_detect (bool enable=true, SetOption option=SET_NOW)
 Enables or disables a hardware carrier detect.
bool is_receiver_enabled ()
 True if the receive side is enabled, false otherwise.
void enable_receiver (bool enable=true, SetOption option=SET_NOW)
 If true the receiver will be enabled, and if false it will be disabled and no characters can be received.
virtual void open () throw ( open_exception )
virtual void open (const std::string &name, ReadWrite mode=READ_WRITE_UNCHANGED) throw ( open_exception )
 Opens the TTY in the specified mode, storing the original terminal mode, to be restored on close.
virtual void close (bool force=false) throw ( close_exception )
 Restores the original terminal modes on the tty.
void set_input_modes (tcflag_t iflag, SetOption option=SET_NOW)
 Sets TTY modes [ see termios(3) ].
void set_output_modes (tcflag_t oflag, SetOption option=SET_NOW)
 Sets TTY modes [ see termios(3) ].
void set_control_modes (tcflag_t cflag, SetOption option=SET_NOW)
 Sets TTY modes [ see termios(3) ].
void set_local_modes (tcflag_t lflag, SetOption option=SET_NOW)
 Sets TTY modes [ see termios(3) ].
void set_control_characters (int index, cc_t value, SetOption option=SET_NOW)
 Sets TTY modes [ see termios(3) ].
struct termios attributes ()
 Gets TTY attributes [ see termios(3) ].
void inject (char data)
 Injects the character into the input queue.
void inject (const char *buffer, size_t bufsize)
 Injects the input buffer into the input queue.
void inject (const std::string &buffer)
 Injects the input buffer into the input queue.
bool is_reset_on_close_enabled ()
 True if the terminal will be reset to original characteristics on close.
void enable_reset_on_close (bool reset=true)
 Set to true if the terminal should reset to original characteristics on close.
sigc::signal< void > & signal_input_speed_changed ()
sigc::signal< void > & signal_output_speed_changed ()
sigc::signal< void > & signal_parity_changed ()
sigc::signal< void > & signal_byte_size_changed ()
sigc::signal< void > & signal_stop_bits_changed ()
sigc::signal< void > & signal_flow_control_changed ()
sigc::signal< void > & signal_carrier_detect_changed ()
sigc::signal< void > & signal_receiver_changed ()
virtual size_t input_available () throw ()

Static Public Member Functions

static TTY::pointer create (const std::string &device=std::string(), ReadWrite rwmode=READ_WRITE)

Protected Member Functions

 TTY (const std::string &device=std::string(), ReadWrite rwmode=READ_WRITE)
 Default constructor The following default characteristics are set:
  • Byte size: 8 bits
  • Receiver: Enabled
  • Hardware Flow Control: Enabled
  • Hardware Carrier Detect: Disabled (modem status lines ignored)
  • Parity: None
  • Breaks: Ignored
  • Delays set to 0: newline, carriage return, horizontal tab, backspace, vertical tab, form feed.

void tcsetattr (SetOption option)
speed_t unsigned2speed (unsigned speed)
unsigned speed2unsigned (speed_t speed)

Protected Attributes

struct termios m_termios m_origtermios
bool m_reset_on_close
sigc::signal< void > m_signal_input_speed_changed
sigc::signal< void > m_signal_output_speed_changed
sigc::signal< void > m_signal_parity_changed
sigc::signal< void > m_signal_byte_size_changed
sigc::signal< void > m_signal_stop_bits_changed
sigc::signal< void > m_signal_flow_control_changed
sigc::signal< void > m_signal_carrier_detect_changed
sigc::signal< void > m_signal_receiver_changed

Related Functions

(Note that these are not member functions.)

enum  TOS { TOS_LOWDELAY = IPTOS_LOWDELAY, TOS_THROUGHPUT = IPTOS_THROUGHPUT, TOS_RELIABILITY = IPTOS_RELIABILITY, TOS_LOWCOST = IPTOS_LOWCOST }
enum  SetOption { SET_NOW = TCSANOW, SET_FLUSH = TCSAFLUSH, SET_DRAIN = TCSADRAIN }
enum  Parity { PARITY_NONE, PARITY_ODD, PARITY_EVEN }
enum  ParityError { PARITY_ERROR_DISCARD, PARITY_ERROR_MARK, PARITY_ERROR_ZERO, PARITY_ERROR_IGNORE }
enum  FlowControl { FLOW_NONE, FLOW_HARDWARE, FLOW_SOFTWARE, FLOW_CUSTOM }


Detailed Description

This class extends Serial to include operations upon TTY (TeleTYpe) serial communications.

This class should be used to control serial port baud rates and other aspects of serial communications.

Author:
Rick L Vinyard Jr

Member Typedef Documentation

typedef ConexusPointer<TTY> Conexus::TTY::pointer

Reimplemented from Conexus::Serial.

Examples:
miniterm.cpp, and serial_send.cpp.


Constructor & Destructor Documentation

Conexus::TTY::TTY ( const std::string &  device = std::string(),
ReadWrite  rwmode = READ_WRITE 
) [protected]

Default constructor The following default characteristics are set:

  • Byte size: 8 bits
  • Receiver: Enabled
  • Hardware Flow Control: Enabled
  • Hardware Carrier Detect: Disabled (modem status lines ignored)
  • Parity: None
  • Breaks: Ignored
  • Delays set to 0: newline, carriage return, horizontal tab, backspace, vertical tab, form feed.

Referenced by create().

Conexus::TTY::~TTY (  )  [virtual]


Member Function Documentation

struct termios Conexus::TTY::attributes (  )  [read]

Gets TTY attributes [ see termios(3) ].

unsigned Conexus::TTY::byte_size (  )  [virtual]

Get the current byte size in bits.

Implements Conexus::TTYInterface.

void Conexus::TTY::close ( bool  force = false  )  throw ( close_exception ) [virtual]

Restores the original terminal modes on the tty.

Implements Conexus::TTYInterface.

References Conexus::FileDescriptor::close().

Conexus::TTY::CONEXUS_ENDPOINT_GENERIC_CREATE (  ) 

Reimplemented from Conexus::Serial.

TTY::pointer Conexus::TTY::create ( const std::string &  device = std::string(),
ReadWrite  rwmode = READ_WRITE 
) [static]

Reimplemented from Conexus::Serial.

Examples:
miniterm.cpp, and serial_send.cpp.

References TTY().

void Conexus::TTY::drain (  )  [virtual]

waits until all output written to the object has been transmitted.

Implements Conexus::TTYInterface.

References Conexus::FileDescriptor::m_fd.

void Conexus::TTY::enable_carrier_detect ( bool  enable = true,
SetOption  option = SET_NOW 
) [virtual]

Enables or disables a hardware carrier detect.

If hardware carrier detect is enabled and this is a blocking TTY, an open will block until a DCD signal is received from the hardware (useful for modems). If this is not enabled, the TTY will behave as if the DCD is always asserted. The hardware carrier flag should usually be turned on for modems and off for local devices.

Implements Conexus::TTYInterface.

References m_signal_carrier_detect_changed, and tcsetattr().

void Conexus::TTY::enable_receiver ( bool  enable = true,
SetOption  option = SET_NOW 
) [virtual]

If true the receiver will be enabled, and if false it will be disabled and no characters can be received.

Implements Conexus::TTYInterface.

References m_signal_receiver_changed, and tcsetattr().

void Conexus::TTY::enable_reset_on_close ( bool  reset = true  )  [virtual]

Set to true if the terminal should reset to original characteristics on close.

Implements Conexus::TTYInterface.

References m_reset_on_close.

FlowControl Conexus::TTY::flow_control (  )  [virtual]

Returns the flow control method.

Implements Conexus::TTYInterface.

References Conexus::FLOW_CUSTOM, Conexus::FLOW_HARDWARE, Conexus::FLOW_NONE, and Conexus::FLOW_SOFTWARE.

void Conexus::TTY::flush (  )  [virtual]

discards both data written to the object but not transmitted and data received but not read

Implements Conexus::TTYInterface.

References Conexus::FileDescriptor::m_fd.

void Conexus::TTY::flush_input (  )  [virtual]

discards data received but not read

Implements Conexus::TTYInterface.

References Conexus::FileDescriptor::m_fd.

void Conexus::TTY::flush_output (  )  [virtual]

discards data written to the object but not transmitted

Implements Conexus::TTYInterface.

References Conexus::FileDescriptor::m_fd.

void Conexus::TTY::inject ( const std::string &  buffer  )  [virtual]

Injects the input buffer into the input queue.

Implements Conexus::TTYInterface.

References inject().

void Conexus::TTY::inject ( const char *  buffer,
size_t  bufsize 
)

Injects the input buffer into the input queue.

References inject().

void Conexus::TTY::inject ( char  data  ) 

Injects the character into the input queue.

References Conexus::FileDescriptor::m_fd.

Referenced by inject().

size_t Conexus::TTY::input_available (  )  throw () [virtual]

Reimplemented from Conexus::Endpoint.

References Conexus::FileDescriptor::m_fd.

unsigned Conexus::TTY::input_speed (  )  [virtual]

Returns the current input line speed.

Implements Conexus::TTYInterface.

References speed2unsigned().

bool Conexus::TTY::is_carrier_detect_enabled (  )  [virtual]

True if the hardware carrier detect (DCD) is enabled, false otherwise.

Implements Conexus::TTYInterface.

bool Conexus::TTY::is_receiver_enabled (  )  [virtual]

True if the receive side is enabled, false otherwise.

If false, this TTY cannot receive characters.

Implements Conexus::TTYInterface.

bool Conexus::TTY::is_reset_on_close_enabled (  )  [virtual]

True if the terminal will be reset to original characteristics on close.

Implements Conexus::TTYInterface.

References m_reset_on_close.

void Conexus::TTY::open ( const std::string &  name,
ReadWrite  mode = READ_WRITE_UNCHANGED 
) throw ( open_exception ) [virtual]

Opens the TTY in the specified mode, storing the original terminal mode, to be restored on close.

Reimplemented from Conexus::Serial.

References Conexus::Serial::open(), and Conexus::SET_NOW.

void Conexus::TTY::open (  )  throw ( open_exception ) [virtual]

Reimplemented from Conexus::Serial.

unsigned Conexus::TTY::output_speed (  )  [virtual]

Returns the current output line speed.

Implements Conexus::TTYInterface.

References speed2unsigned().

Parity Conexus::TTY::parity (  )  [virtual]

Returns the current parity mode.

Implements Conexus::TTYInterface.

References Conexus::PARITY_EVEN, Conexus::PARITY_NONE, and Conexus::PARITY_ODD.

ParityError Conexus::TTY::parity_error (  )  [virtual]

void Conexus::TTY::restart_input (  )  [virtual]

Resumes reception of data by the object.

Implements Conexus::TTYInterface.

References Conexus::FileDescriptor::m_fd.

void Conexus::TTY::restart_output (  )  [virtual]

Resumes transmission of data by the object.

Implements Conexus::TTYInterface.

References Conexus::FileDescriptor::m_fd.

void Conexus::TTY::set_byte_size ( unsigned  size,
SetOption  option = SET_NOW 
) [virtual]

Sets the communication byte size Valid values are:

  • 5 bits-per-byte
  • 6 bits-per-byte
  • 7 bits-per-byte
  • 8 bits-per-byte (default) All other values are ignored.

Implements Conexus::TTYInterface.

References m_signal_byte_size_changed, and tcsetattr().

void Conexus::TTY::set_control_characters ( int  index,
cc_t  value,
SetOption  option = SET_NOW 
)

Sets TTY modes [ see termios(3) ].

References tcsetattr().

void Conexus::TTY::set_control_modes ( tcflag_t  cflag,
SetOption  option = SET_NOW 
)

void Conexus::TTY::set_flow_control ( FlowControl  flowcontrol,
SetOption  option = SET_NOW 
) [virtual]

Sets the flow control flags according to the flow control method specified.

If FLOW_CUSTOM is specified, no change will occur.

Implements Conexus::TTYInterface.

References Conexus::FLOW_CUSTOM, Conexus::FLOW_HARDWARE, Conexus::FLOW_NONE, Conexus::FLOW_SOFTWARE, m_signal_flow_control_changed, and tcsetattr().

void Conexus::TTY::set_input_modes ( tcflag_t  iflag,
SetOption  option = SET_NOW 
)

void Conexus::TTY::set_input_speed ( unsigned  speed,
SetOption  option = SET_NOW 
) [virtual]

Sets the input line speed.

These are generally defined in /usr/include/bits/termios.h The following is the recognized list:

  • 0 (hang up)
  • 50
  • 75
  • 110
  • 134
  • 150
  • 200
  • 300
  • 600
  • 1200
  • 1800
  • 2400
  • 4800
  • 9600
  • 19200
  • 38400
  • 57600
  • 115200
  • 230400
  • 460800
  • 500000
  • 576000
  • 921600
  • 1000000
  • 1152000
  • 1500000
  • 2000000
  • 2500000
  • 3000000
  • 3500000
  • 4000000

Implements Conexus::TTYInterface.

References m_signal_input_speed_changed, tcsetattr(), and unsigned2speed().

void Conexus::TTY::set_local_modes ( tcflag_t  lflag,
SetOption  option = SET_NOW 
)

Sets TTY modes [ see termios(3) ].

References tcsetattr().

void Conexus::TTY::set_output_modes ( tcflag_t  oflag,
SetOption  option = SET_NOW 
)

Sets TTY modes [ see termios(3) ].

References m_signal_output_speed_changed, and tcsetattr().

void Conexus::TTY::set_output_speed ( unsigned  speed,
SetOption  option = SET_NOW 
) [virtual]

Sets the output line speed.

Implements Conexus::TTYInterface.

References m_signal_output_speed_changed, tcsetattr(), and unsigned2speed().

void Conexus::TTY::set_parity ( Parity  parity,
ParityError  error = PARITY_ERROR_IGNORE,
SetOption  option = SET_NOW 
) [virtual]

Sets parity mode.

Discards all parity error bytes

Delivers three bytes (0xFF, 0x00 and c; where c is the error byte

Delivers 0x00 when a parity error is detected

Ignores all parity errors and delivers all data as is

Implements Conexus::TTYInterface.

References m_signal_parity_changed, Conexus::PARITY_ERROR_DISCARD, Conexus::PARITY_ERROR_IGNORE, Conexus::PARITY_ERROR_MARK, Conexus::PARITY_ERROR_ZERO, Conexus::PARITY_NONE, Conexus::PARITY_ODD, and tcsetattr().

void Conexus::TTY::set_speed ( unsigned  speed,
SetOption  option = SET_NOW 
) [virtual]

Sets both the input and output line speeds.

Implements Conexus::TTYInterface.

References m_signal_input_speed_changed, m_signal_output_speed_changed, tcsetattr(), and unsigned2speed().

void Conexus::TTY::set_stop_bits ( unsigned  size,
SetOption  option = SET_NOW 
) [virtual]

Sets the stop bits; only values of 1 or 2 will be processed, all others will be ignored.

Implements Conexus::TTYInterface.

References m_signal_stop_bits_changed, and tcsetattr().

sigc::signal< void > & Conexus::TTY::signal_byte_size_changed (  )  [virtual]

sigc::signal< void > & Conexus::TTY::signal_carrier_detect_changed (  )  [virtual]

sigc::signal< void > & Conexus::TTY::signal_flow_control_changed (  )  [virtual]

sigc::signal< void > & Conexus::TTY::signal_input_speed_changed (  )  [virtual]

sigc::signal< void > & Conexus::TTY::signal_output_speed_changed (  )  [virtual]

sigc::signal< void > & Conexus::TTY::signal_parity_changed (  )  [virtual]

sigc::signal< void > & Conexus::TTY::signal_receiver_changed (  )  [virtual]

sigc::signal< void > & Conexus::TTY::signal_stop_bits_changed (  )  [virtual]

unsigned Conexus::TTY::speed2unsigned ( speed_t  speed  )  [protected]

Referenced by input_speed(), and output_speed().

unsigned Conexus::TTY::stop_bits (  )  [virtual]

Get the number of stop bits (1 or 2).

Implements Conexus::TTYInterface.

void Conexus::TTY::suspend_input (  )  [virtual]

Suspends reception of data by the object.

Implements Conexus::TTYInterface.

References Conexus::FileDescriptor::m_fd.

void Conexus::TTY::suspend_output (  )  [virtual]

Suspends transmission of data by the object.

Implements Conexus::TTYInterface.

References Conexus::FileDescriptor::m_fd.

void Conexus::TTY::tcsetattr ( SetOption  option  )  [protected]

speed_t Conexus::TTY::unsigned2speed ( unsigned  speed  )  [protected]


Friends And Related Function Documentation

enum FlowControl [related]

Enumerator:
FLOW_NONE 
FLOW_HARDWARE  CRTSCTS off, IXON off, IXOFF off.
FLOW_SOFTWARE  CRTSCTS on, IXON off, IXOFF off.
FLOW_CUSTOM  CRTSCTS off, IXON on, IXOFF on.

enum Parity [related]

Enumerator:
PARITY_NONE 
PARITY_ODD  No parity check.
PARITY_EVEN  Odd parity checks.

enum ParityError [related]

Enumerator:
PARITY_ERROR_DISCARD 
PARITY_ERROR_MARK  Discards all parity error bytes.
PARITY_ERROR_ZERO  Delivers three bytes (0xFF, 0x00 and c; where c is the error byte.
PARITY_ERROR_IGNORE  Delivers 0x00 when a parity error is detected.

enum SetOption [related]

Aliases for the tty function options relating to when an option change takes effect.

Enumerator:
SET_NOW  the setting change occurs immediately
SET_FLUSH  the setting change occurs after all output written to the object has been transmitted, and all input that has been received but not read will be discarded before the change is made.
SET_DRAIN  the setting change occurs after all output has been transmitted; This function should be used when changing parameters that affect output.

enum TOS [related]

Enumerator:
TOS_LOWDELAY  minimize delays for interactive traffic
TOS_THROUGHPUT  optimize throughput
TOS_RELIABILITY  optimize for reliability
TOS_LOWCOST  for "filler data" where slow transmission doesn’t matter


Member Data Documentation

struct termios m_termios Conexus::TTY::m_origtermios [read, protected]

Referenced by ~TTY().

sigc::signal<void> Conexus::TTY::m_signal_byte_size_changed [protected]

sigc::signal<void> Conexus::TTY::m_signal_carrier_detect_changed [protected]

sigc::signal<void> Conexus::TTY::m_signal_flow_control_changed [protected]

sigc::signal<void> Conexus::TTY::m_signal_input_speed_changed [protected]

sigc::signal<void> Conexus::TTY::m_signal_output_speed_changed [protected]

sigc::signal<void> Conexus::TTY::m_signal_parity_changed [protected]

sigc::signal<void> Conexus::TTY::m_signal_receiver_changed [protected]

sigc::signal<void> Conexus::TTY::m_signal_stop_bits_changed [protected]


The documentation for this class was generated from the following files:

Generated on Wed Jul 8 15:51:21 2009 for conexus by doxygen 1.5.8