DUNE: Uniform Navigational Environment  2019.02.1
DUNE::Hardware::SerialPort Class Reference

Detailed Description

The SerialPort class encapsulates serial port access.

Classes

class  Error
 

Public Types

Public Member Functions

 SerialPort (const std::string &device, int baudrate=38400, Parity parity=SP_PARITY_NONE, StopBits stopbits=SP_STOPBITS_1, DataBits databits=SP_DATABITS_8, bool block=false)
 
 ~SerialPort (void)
 
void setMinimumRead (int value)
 
void setBaudRate (int baudrate)
 
void setParity (Parity parity)
 
void setDataBits (DataBits databits)
 
void setStopBits (StopBits sbits)
 
void setCanonicalInput (bool enable)
 
void setCanonicalInputTerminator (char terminator)
 
void setNonBlocking (void)
 
void sendBreak (int duration)
 
void setXONXOFF (bool enabled)
 
void setCTSRTS (bool enabled)
 
- Public Member Functions inherited from DUNE::IO::Handle
virtual ~Handle (void)
 
size_t write (const uint8_t *data, size_t length)
 
size_t write (const char *data, size_t length)
 
size_t writeString (const char *cstr)
 
size_t read (uint8_t *data, size_t length)
 
size_t read (char *data, size_t length)
 
size_t readString (char *bfr, size_t length)
 
void flush (void)
 
void flushInput (void)
 
void flushOutput (void)
 
NativeHandle getNative (void) const
 

Static Public Member Functions

static std::vector< std::string > enumerate (void)
 

Additional Inherited Members

Member Enumeration Documentation

Data bits.

Enumerator
SP_DATABITS_5 

Five data bits.

SP_DATABITS_6 

Six data bits.

SP_DATABITS_7 

Seven data bits.

SP_DATABITS_8 

Eight data bits.

The optional parity bit is a simple sum of the data bits indicating whether or not the data contains an even or odd number of 1 bits.

With even parity, the parity bit is 0 if there is an even number of 1's in the character. With odd parity, the parity bit is 0 if there is an odd number of 1's in the data. No parity means that no parity bit is present or transmitted.

Enumerator
SP_PARITY_NONE 

No parity.

SP_PARITY_EVEN 

Even parity.

SP_PARITY_ODD 

Odd parity.

There can be 1, 1.5, or 2 stop bits between characters and they always have a value of 1.

Stop bits traditionally were used to give the computer time to process the previous character, but now only serve to synchronize the receiving computer to the incoming characters.

Enumerator
SP_STOPBITS_1 

One stop bit.

SP_STOPBITS_1_5 

One and half stop bits.

SP_STOPBITS_2 

Two stop bits.

Constructor & Destructor Documentation

DUNE::Hardware::SerialPort::SerialPort ( const std::string &  device,
int  baudrate = 38400,
Parity  parity = SP_PARITY_NONE,
StopBits  stopbits = SP_STOPBITS_1,
DataBits  databits = SP_DATABITS_8,
bool  block = false 
)

Serial port constructor.

Parameters
deviceserial port device.
baudrateI/O baud rate.
parityparity checking type.
stopbitsnumber of stop bits.
databitsnumber of data bits.
blockfalse enable non-blocking I/O.
Exceptions
SerialPortError.

References DUNE::System::Error::getLastMessage(), setBaudRate(), setCanonicalInput(), setCTSRTS(), setDataBits(), setMinimumRead(), setNonBlocking(), setParity(), setStopBits(), and setXONXOFF().

DUNE::Hardware::SerialPort::~SerialPort ( void  )

Serial port destructor.

References DUNE::IO::Handle::flush().

Member Function Documentation

std::vector< std::string > DUNE::Hardware::SerialPort::enumerate ( void  )
static

Enumerate available serial ports.

The names returned are dependent on the operating system.

Returns
vector of serial port names (devices).

References DUNE::Utils::String::format(), and DUNE::FileSystem::Path.

void DUNE::Hardware::SerialPort::sendBreak ( int  duration)
void DUNE::Hardware::SerialPort::setBaudRate ( int  baudrate)

Set the baud rate of the serial port.

Parameters
baudratebaud rate value.

References DUNE::System::Error::getLastMessage().

Referenced by SerialPort().

void DUNE::Hardware::SerialPort::setCanonicalInput ( bool  enable)

Enable canonical input.

Canonical input is line-oriented. Input characters are put into a buffer which can be edited interactively by the user until a CR (carriage return) or LF (line feed) character is received.

Parameters
enableenable / disable canonical input.

References DUNE::System::Error::getLastMessage().

Referenced by SerialPort().

void DUNE::Hardware::SerialPort::setCanonicalInputTerminator ( char  terminator)
void DUNE::Hardware::SerialPort::setCTSRTS ( bool  enabled)

Enable hardware flow control (CTSRTS).

Parameters
enabledenable / disable hardware flow control

References DUNE::System::Error::getLastMessage().

Referenced by SerialPort().

void DUNE::Hardware::SerialPort::setDataBits ( DataBits  databits)

Set the number of data bits of the serial port.

Parameters
databitsnumber of data bits.

References DUNE::System::Error::getLastMessage(), SP_DATABITS_5, SP_DATABITS_6, SP_DATABITS_7, and SP_DATABITS_8.

Referenced by SerialPort().

void DUNE::Hardware::SerialPort::setMinimumRead ( int  value)
void DUNE::Hardware::SerialPort::setNonBlocking ( void  )
void DUNE::Hardware::SerialPort::setParity ( Parity  parity)

Set the parity of the serial port.

Parameters
parityparity value.

References DUNE::System::Error::getLastMessage(), SP_PARITY_EVEN, SP_PARITY_NONE, and SP_PARITY_ODD.

Referenced by SerialPort().

void DUNE::Hardware::SerialPort::setStopBits ( StopBits  sbits)

Set the number of stop bits of the serial port.

Parameters
sbitsnumber of stop bits.

References DUNE::System::Error::getLastMessage(), SP_STOPBITS_1, SP_STOPBITS_1_5, and SP_STOPBITS_2.

Referenced by SerialPort().

void DUNE::Hardware::SerialPort::setXONXOFF ( bool  enabled)

Enable software flow control (XON/XOFF/XANY).

Parameters
enabledenable / disable software flow control

References DUNE::System::Error::getLastMessage().

Referenced by SerialPort().

Collaboration diagram for DUNE::Hardware::SerialPort:
Collaboration graph