Conexus::TTY Class Reference
[Conexus]

#include <conexus/tty.h>

Inheritance diagram for Conexus::TTY:

Inheritance graph
[legend]
List of all members.

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


Public Types

typedef boost::shared_ptr<
TTY
pointer
typedef enum Conexus::TTY::SetOption SetOption
 Aliases for the tty function options relating to when an option change takes effect.
enum  SetOption { SET_NOW = TCSANOW, SET_FLUSH = TCSAFLUSH, SET_DRAIN = TCSADRAIN }
 Aliases for the tty function options relating to when an option change takes effect. More...
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 }

Public Member Functions

 TTY (const std::string &device=std::string())
 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 drain ()
 waits until all output written to the object has been transmitted.
void flush_input ()
 discards data received but not read
void flush_output ()
 discards data written to the object but not transmitted
void flush ()
 discards both data written to the object but not transmitted and data received but not read
void suspend_output ()
 Suspends transmission of data by the object.
void restart_output ()
 Resumes transmission of data by the object.
void suspend_input ()
 Suspends reception of data by the object.
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 carrier_detect_enabled ()
 True if the hardware carrier detect (DCD) is enabled, false otherwise.
void set_carrier_detect (bool enable=true, SetOption option=SET_NOW)
 Enables or disables a hardware carrier detect.
bool receiver_enabled ()
 True if the receive side is enabled, false otherwise.
void set_receiver_enabled (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 Data read (size_t s=0) throw (read_error)
 Reads up to s bytes from the TTY.
virtual void open () throw (open_error)
virtual void open (const std::string name, int s=READ|WRITE) throw (open_error)
 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_error)
 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) ].
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 reset_on_close ()
 True if the terminal will be reset to original characteristics on close.
void set_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 ()
sigc::signal< void > signal_output_speed ()
sigc::signal< void > signal_parity ()
sigc::signal< void > signal_byte_size ()
sigc::signal< void > signal_stop_bits ()
sigc::signal< void > signal_flow_control ()
sigc::signal< void > signal_carrier_detect ()
sigc::signal< void > signal_receiver ()
virtual const std::string & object_type ()

Static Public Member Functions

static TTY::pointer create (const std::string &device=std::string())

Protected Member Functions

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

Protected Attributes

termios m_termios m_origtermios
bool m_reset_on_close
sigc::signal< void > m_signal_input_speed
sigc::signal< void > m_signal_output_speed
sigc::signal< void > m_signal_parity
sigc::signal< void > m_signal_byte_size
sigc::signal< void > m_signal_stop_bits
sigc::signal< void > m_signal_flow_control
sigc::signal< void > m_signal_carrier_detect
sigc::signal< void > m_signal_receiver


Member Enumeration Documentation

enum Conexus::TTY::FlowControl
 

Enumerator:
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 Conexus::TTY::Parity
 

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

enum Conexus::TTY::ParityError
 

Enumerator:
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 Conexus::TTY::SetOption
 

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.


Member Function Documentation

bool Conexus::TTY::receiver_enabled  ) 
 

True if the receive side is enabled, false otherwise.

If false, this TTY cannot receive characters.

void Conexus::TTY::set_carrier_detect bool  enable = true,
SetOption  option = SET_NOW
 

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.

void Conexus::TTY::set_flow_control FlowControl  flowcontrol,
SetOption  option = SET_NOW
 

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

If FLOW_CUSTOM is specified, no change will occur.

void Conexus::TTY::set_input_speed unsigned  speed,
SetOption  option = SET_NOW
 

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

void Conexus::TTY::set_parity Parity  parity,
ParityError  error = PARITY_ERROR_IGNORE,
SetOption  option = SET_NOW
 

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


The documentation for this class was generated from the following files:
Generated on Sun Aug 6 12:17:04 2006 by  doxygen 1.4.6