SerialPort Class Reference

Encapsulation of a serial port. More...

#include <serialport.h>

Inheritance diagram for SerialPort:

Port List of all members.

Public Types

enum  Error {
  Ok = 0, SyntaxError, PermissionDenied, NoSuchPort,
  ConfigError, OpenError, WriteError, ReadError,
  UnknownBaudRate, UnknownNumberOfBits, UnknownParity, UnknownStopBits,
  NoData, BadFileDescriptor, BadAddress, Interrupted,
  Invalid, IOError, IsDirectory, UnknownError
}

Public Member Functions

 SerialPort ()
virtual ~SerialPort ()
virtual Port::Error open (const std::string &config)
 Open the serial port.
virtual Port::Error close ()
virtual Error writeByte (int byte) const
virtual Error readByte (int *byte) const
virtual Error writeString (const char *string, ssize_t len) const
virtual Error readString (char *string, ssize_t len) const

Static Public Member Functions

static const char * errorString (Error err)

Protected Member Functions

Error errnoValue () const

Protected Attributes

termios m_oldSettings
int m_handle

Detailed Description

Encapsulation of a serial port.

See also:
open for explanation of the implemented capabilities and how to access them.

Definition at line 33 of file serialport.h.


Member Enumeration Documentation

enum Port::Error [inherited]
 

Enumerator:
Ok 
SyntaxError 
PermissionDenied 
NoSuchPort 
ConfigError 
OpenError 
WriteError 
ReadError 
UnknownBaudRate 
UnknownNumberOfBits 
UnknownParity 
UnknownStopBits 
NoData 
BadFileDescriptor 
BadAddress 
Interrupted 
Invalid 
IOError 
IsDirectory 
UnknownError 

Definition at line 37 of file port.h.


Constructor & Destructor Documentation

SerialPort::SerialPort  ) 
 

Definition at line 26 of file serialport.cpp.

SerialPort::~SerialPort  )  [virtual]
 

Definition at line 31 of file serialport.cpp.

References close().


Member Function Documentation

Port::Error SerialPort::close  )  [virtual]
 

close the previously opened port

Implements Port.

Definition at line 236 of file serialport.cpp.

References Port::m_handle, m_oldSettings, and Port::Ok.

Referenced by VC820::close(), PeakTech10Ascii::close(), MetexAscii::close(), M9803R::close(), GDM703::close(), Escort97::close(), GDM703::~GDM703(), M9803R::~M9803R(), Metex14BytesContinuous::~Metex14BytesContinuous(), MetexAscii::~MetexAscii(), PeakTech10Ascii::~PeakTech10Ascii(), ~SerialPort(), and VC820::~VC820().

Port::Error Port::errnoValue  )  const [protected, inherited]
 

Translate errno into internal value

Returns:
Error code corresponding to the current value of errno

Definition at line 122 of file port.cpp.

References Port::BadAddress, Port::BadFileDescriptor, Port::Interrupted, Port::Invalid, Port::IOError, Port::IsDirectory, Port::NoData, and Port::UnknownError.

Referenced by Port::readByte(), Port::readString(), Port::writeByte(), and Port::writeString().

const char * Port::errorString Error  err  )  [static, inherited]
 

Translate Error code into a human readable string.

Parameters:
err Error code (as returned by the read/write/open/close) members of this class
Returns:
Pointer to human readable string

Definition at line 145 of file port.cpp.

References Port::BadAddress, Port::BadFileDescriptor, Port::ConfigError, Port::Interrupted, Port::Invalid, Port::IOError, Port::IsDirectory, Port::NoData, Port::NoSuchPort, Port::Ok, Port::OpenError, Port::PermissionDenied, Port::ReadError, Port::SyntaxError, Port::UnknownBaudRate, Port::UnknownError, Port::UnknownNumberOfBits, Port::UnknownParity, Port::UnknownStopBits, and Port::WriteError.

Port::Error SerialPort::open const std::string &  config  )  [virtual]
 

Open the serial port.

Parameters:
config Port description in the following format: devicename:baudrate:bits:parity:stopbits[:RTS][:DTR][:DSR][:CTS].
baudrate can be 300, 600, 1200, 1800, 2400, 4800, 9600, 19200 or 38400
bits might be 5, 6, 7 or 8
parity might be n (none), e (even) or o (odd)
stopbits might be 1 or 2

The optional RTS, DTR, DSR, CTS parameter can be used to force these signals to be set. This can be usefull for multimeter that use optocouplers. These guys sometimes are powered with one of these signals. For most multimeter a good starting point would be: DTR:DSR:CTS

Example: /dev/ttyS0:600:8:n:1 - /dev/ttyS0 at 600 baud, 8 bits, no parity and one stop bit.
Example: /dev/ttyS0:300:7:e:1 - /dev/ttyS0 at 300 baud, 7 bits, even parity and one stop bit.
Example: /dev/ttyS0:1200:7:o:2:RTS:CTS - /dev/ttyS0 at 1200 baud, 7 bits, odd parity, two stop bits, RTS and CTS set

Implements Port.

Definition at line 36 of file serialport.cpp.

References Util::tokenize().

Referenced by VC820::open_impl(), PeakTech10Ascii::open_impl(), MetexAscii::open_impl(), M9803R::open_impl(), GDM703::open_impl(), and Escort97::open_impl().

Port::Error Port::readByte int *  byte  )  const [virtual, inherited]
 

Read a byte from the port.

Parameters:
byte Value to be read. Is invalid if an error occured.
Returns:
Error code

Definition at line 51 of file port.cpp.

References Port::errnoValue(), Port::m_handle, and Port::Ok.

Referenced by VC820::readData(), PeakTech10Ascii::readData(), and DMMClass::readData().

Port::Error Port::readString char *  string,
ssize_t  len
const [virtual, inherited]
 

Read a string from the port.

Parameters:
string String to be read.
len Number of bytes to be read
Returns:
Error code

Definition at line 97 of file port.cpp.

References Port::errnoValue(), Port::m_handle, and Port::Ok.

Port::Error Port::writeByte int  byte  )  const [virtual, inherited]
 

Write a byte to the port.

Parameters:
byte Value to be written
Returns:
Error code

Definition at line 32 of file port.cpp.

References Port::errnoValue(), Port::m_handle, and Port::Ok.

Port::Error Port::writeString const char *  string,
ssize_t  len
const [virtual, inherited]
 

Write a string to the port.

Parameters:
string String to be written
len Number of bytes to be written
Returns:
Error code

Definition at line 72 of file port.cpp.

References Port::errnoValue(), Port::m_handle, and Port::Ok.

Referenced by MetexAscii::run().


Member Data Documentation

int Port::m_handle [protected, inherited]
 

Definition at line 108 of file port.h.

Referenced by close(), Port::readByte(), Port::readString(), Port::writeByte(), and Port::writeString().

struct termios SerialPort::m_oldSettings [protected]
 

Definition at line 61 of file serialport.h.

Referenced by close().


The documentation for this class was generated from the following files:
Generated on Mon Jan 22 23:24:19 2007 for cdmm by  doxygen 1.4.6