.TH "SerialPort" 3 "Mon Sep 14 2015" "Version 0.6.0rc3" "libserial" \" -*- nroff -*- .ad l .nh .SH NAME SerialPort \- .SH SYNOPSIS .br .PP .PP \fC#include \fP .SS "Classes" .in +1c .ti -1c .RI "class \fBAlreadyOpen\fP" .br .ti -1c .RI "class \fBNotOpen\fP" .br .ti -1c .RI "class \fBOpenFailed\fP" .br .ti -1c .RI "class \fBReadTimeout\fP" .br .ti -1c .RI "class \fBUnsupportedBaudRate\fP" .br .in -1c .SS "Public Types" .in +1c .ti -1c .RI "enum \fBBaudRate\fP { \fBBAUD_50\fP = B50, \fBBAUD_75\fP = B75, \fBBAUD_110\fP = B110, \fBBAUD_134\fP = B134, \fBBAUD_150\fP = B150, \fBBAUD_200\fP = B200, \fBBAUD_300\fP = B300, \fBBAUD_600\fP = B600, \fBBAUD_1200\fP = B1200, \fBBAUD_1800\fP = B1800, \fBBAUD_2400\fP = B2400, \fBBAUD_4800\fP = B4800, \fBBAUD_9600\fP = B9600, \fBBAUD_19200\fP = B19200, \fBBAUD_38400\fP = B38400, \fBBAUD_57600\fP = B57600, \fBBAUD_115200\fP = B115200, \fBBAUD_230400\fP = B230400, \fBBAUD_DEFAULT\fP = BAUD_57600 }" .br .RI "\fIThe allowed set of baud rates\&. \fP" .ti -1c .RI "enum \fBCharacterSize\fP { \fBCHAR_SIZE_5\fP = CS5, \fBCHAR_SIZE_6\fP = CS6, \fBCHAR_SIZE_7\fP = CS7, \fBCHAR_SIZE_8\fP = CS8, \fBCHAR_SIZE_DEFAULT\fP = CHAR_SIZE_8 }" .br .ti -1c .RI "enum \fBStopBits\fP { \fBSTOP_BITS_1\fP, \fBSTOP_BITS_2\fP, \fBSTOP_BITS_DEFAULT\fP = STOP_BITS_1 }" .br .ti -1c .RI "enum \fBParity\fP { \fBPARITY_EVEN\fP, \fBPARITY_ODD\fP, \fBPARITY_NONE\fP, \fBPARITY_DEFAULT\fP = PARITY_NONE }" .br .ti -1c .RI "enum \fBFlowControl\fP { \fBFLOW_CONTROL_HARD\fP, \fBFLOW_CONTROL_SOFT\fP, \fBFLOW_CONTROL_NONE\fP, \fBFLOW_CONTROL_DEFAULT\fP = FLOW_CONTROL_NONE }" .br .ti -1c .RI "typedef std::vector< unsigned char > \fBDataBuffer\fP" .br .RI "\fIRead the specified number of bytes from the serial port\&. \fP" .in -1c .SS "Public Member Functions" .in +1c .ti -1c .RI "\fBSerialPort\fP (const std::string &serialPortName)" .br .RI "\fIConstructor for a serial port\&. \fP" .ti -1c .RI "virtual \fB~SerialPort\fP () throw ()" .br .RI "\fIDestructor\&. \fP" .ti -1c .RI "void \fBOpen\fP (const \fBBaudRate\fP baudRate=\fBBAUD_DEFAULT\fP, const \fBCharacterSize\fP charSize=\fBCHAR_SIZE_DEFAULT\fP, const \fBParity\fP parityType=\fBPARITY_DEFAULT\fP, const \fBStopBits\fP stopBits=\fBSTOP_BITS_DEFAULT\fP, const \fBFlowControl\fP flowControl=\fBFLOW_CONTROL_DEFAULT\fP) throw ( AlreadyOpen, OpenFailed, UnsupportedBaudRate, std::invalid_argument )" .br .RI "\fIOpen the serial port with the specified settings\&. \fP" .ti -1c .RI "bool \fBIsOpen\fP () const " .br .RI "\fICheck if the serial port is open for I/O\&. \fP" .ti -1c .RI "void \fBClose\fP () throw (NotOpen)" .br .RI "\fIClose the serial port\&. \fP" .ti -1c .RI "void \fBSetBaudRate\fP (const \fBBaudRate\fP baudRate) throw ( UnsupportedBaudRate, NotOpen, std::invalid_argument )" .br .RI "\fISet the baud rate for the serial port to the specified value (baudRate)\&. \fP" .ti -1c .RI "\fBBaudRate\fP \fBGetBaudRate\fP () const throw ( NotOpen, std::runtime_error )" .br .RI "\fIGet the current baud rate for the serial port\&. \fP" .ti -1c .RI "void \fBSetCharSize\fP (const \fBCharacterSize\fP charSize) throw ( NotOpen, std::invalid_argument )" .br .RI "\fISet the character size for the serial port\&. \fP" .ti -1c .RI "\fBCharacterSize\fP \fBGetCharSize\fP () const throw (NotOpen)" .br .RI "\fIGet the current character size for the serial port\&. \fP" .ti -1c .RI "void \fBSetParity\fP (const \fBParity\fP parityType) throw ( NotOpen, std::invalid_argument )" .br .RI "\fISet the parity type for the serial port\&. \fP" .ti -1c .RI "\fBParity\fP \fBGetParity\fP () const throw (NotOpen)" .br .RI "\fIGet the parity type for the serial port\&. \fP" .ti -1c .RI "void \fBSetNumOfStopBits\fP (const \fBStopBits\fP numOfStopBits) throw ( NotOpen, std::invalid_argument )" .br .RI "\fISet the number of stop bits to be used with the serial port\&. \fP" .ti -1c .RI "\fBStopBits\fP \fBGetNumOfStopBits\fP () const throw (NotOpen)" .br .RI "\fIGet the number of stop bits currently being used by the serial port\&. \fP" .ti -1c .RI "void \fBSetFlowControl\fP (const \fBFlowControl\fP flowControl) throw ( NotOpen, std::invalid_argument )" .br .RI "\fISet flow control\&. \fP" .ti -1c .RI "\fBFlowControl\fP \fBGetFlowControl\fP () const throw ( NotOpen )" .br .RI "\fIGet the current flow control setting\&. \fP" .ti -1c .RI "bool \fBIsDataAvailable\fP () const throw (NotOpen)" .br .RI "\fICheck if data is available at the input of the serial port\&. \fP" .ti -1c .RI "unsigned char \fBReadByte\fP (const unsigned int msTimeout=0) throw ( NotOpen, ReadTimeout, std::runtime_error )" .br .RI "\fIRead a single byte from the serial port\&. \fP" .ti -1c .RI "void \fBRead\fP (\fBDataBuffer\fP &dataBuffer, const unsigned int numOfBytes=0, const unsigned int msTimeout=0) throw ( NotOpen, ReadTimeout, std::runtime_error )" .br .ti -1c .RI "const std::string \fBReadLine\fP (const unsigned int msTimeout=0, const char lineTerminator= '\\n') throw ( NotOpen, ReadTimeout, std::runtime_error )" .br .RI "\fIRead a line of characters from the serial port\&. \fP" .ti -1c .RI "void \fBWriteByte\fP (const unsigned char dataByte) throw ( NotOpen, std::runtime_error )" .br .RI "\fISend a single byte to the serial port\&. \fP" .ti -1c .RI "void \fBWrite\fP (const \fBDataBuffer\fP &dataBuffer) throw ( NotOpen, std::runtime_error )" .br .RI "\fIWrite the data from the specified vector to the serial port\&. \fP" .ti -1c .RI "void \fBWrite\fP (const std::string &dataString) throw ( NotOpen, std::runtime_error )" .br .RI "\fIWrite a string to the serial port\&. \fP" .ti -1c .RI "void \fBSetDtr\fP (const bool dtrState=true) throw ( NotOpen, std::runtime_error )" .br .RI "\fISet the DTR line to the specified value\&. \fP" .ti -1c .RI "bool \fBGetDtr\fP () const throw ( NotOpen, std::runtime_error )" .br .RI "\fIGet the status of the DTR line\&. \fP" .ti -1c .RI "void \fBSetRts\fP (const bool rtsState=true) throw ( NotOpen, std::runtime_error )" .br .RI "\fISet the RTS line to the specified value\&. \fP" .ti -1c .RI "bool \fBGetRts\fP () const throw ( NotOpen, std::runtime_error )" .br .RI "\fIGet the status of the RTS line\&. \fP" .ti -1c .RI "bool \fBGetCts\fP () const throw ( NotOpen, std::runtime_error )" .br .ti -1c .RI "bool \fBGetDsr\fP () const throw ( NotOpen, std::runtime_error )" .br .ti -1c .RI "int \fBGetFileDescriptor\fP () const " .br .RI "\fIGet the low-level file descriptor associated with the serial port\&. \fP" .in -1c .SS "Private Member Functions" .in +1c .ti -1c .RI "\fBSerialPort\fP (const \fBSerialPort\fP &otherSerialPort)" .br .RI "\fIPrevent copying of objects of this class by declaring the copy constructor private\&. \fP" .ti -1c .RI "\fBSerialPort\fP & \fBoperator=\fP (const \fBSerialPort\fP &otherSerialPort)" .br .RI "\fIPrevent copying of objects of this class by declaring the assignment operator private\&. \fP" .in -1c .SS "Private Attributes" .in +1c .ti -1c .RI "SerialPortImpl * \fBmSerialPortImpl\fP" .br .RI "\fIPointer to implementation class instance\&. \fP" .in -1c .SH "Detailed Description" .PP .PP \fBNote:\fP .RS 4 This class attaches a handler to the SIGIO signal to detect the data arriving at a serial port\&. However, this signal handler will also call any signal handler that is already attached to this signal\&. However, if other parts of the application attach a signal handler to SIGIO after constructing an instance of SIGIO, they must ensure that they call the existing signal handler\&. Otherwise, it may not be possible to receive any data through the serial port using this class\&. .RE .PP :FIXME: Provide examples of the above potential problem\&. .PP \fBTodo\fP .RS 4 The current implementation does not check if another process has locked the serial port device and does not lock the serial port device after opening it\&. This has been observed to cause problems while using this library while other programs such as minicom are also accessing the same device\&. It will be useful to lock the serial port device when it is being used by this class\&. .RE .PP .PP Definition at line 50 of file SerialPort\&.h\&. .SH "Member Typedef Documentation" .PP .SS "typedef std::vector \fBSerialPort::DataBuffer\fP" .PP Read the specified number of bytes from the serial port\&. The method will timeout if no data is received in the specified number of milliseconds (msTimeout)\&. If msTimeout is 0, then this method will block till all requested bytes are received\&. If numOfBytes is zero, then this method will keep reading data till no more data is available at the serial port\&. In all cases, all read data is available in dataBuffer on return from this method\&. .PP Definition at line 370 of file SerialPort\&.h\&. .SH "Member Enumeration Documentation" .PP .SS "enum \fBSerialPort::BaudRate\fP" .PP The allowed set of baud rates\&. .PP \fBEnumerator\fP .in +1c .TP \fB\fIBAUD_50 \fP\fP .TP \fB\fIBAUD_75 \fP\fP .TP \fB\fIBAUD_110 \fP\fP .TP \fB\fIBAUD_134 \fP\fP .TP \fB\fIBAUD_150 \fP\fP .TP \fB\fIBAUD_200 \fP\fP .TP \fB\fIBAUD_300 \fP\fP .TP \fB\fIBAUD_600 \fP\fP .TP \fB\fIBAUD_1200 \fP\fP .TP \fB\fIBAUD_1800 \fP\fP .TP \fB\fIBAUD_2400 \fP\fP .TP \fB\fIBAUD_4800 \fP\fP .TP \fB\fIBAUD_9600 \fP\fP .TP \fB\fIBAUD_19200 \fP\fP .TP \fB\fIBAUD_38400 \fP\fP .TP \fB\fIBAUD_57600 \fP\fP .TP \fB\fIBAUD_115200 \fP\fP .TP \fB\fIBAUD_230400 \fP\fP .TP \fB\fIBAUD_DEFAULT \fP\fP .PP Definition at line 56 of file SerialPort\&.h\&. .SS "enum \fBSerialPort::CharacterSize\fP" .PP \fBEnumerator\fP .in +1c .TP \fB\fICHAR_SIZE_5 \fP\fP 5 bit characters\&. .TP \fB\fICHAR_SIZE_6 \fP\fP 6 bit characters\&. .TP \fB\fICHAR_SIZE_7 \fP\fP 7 bit characters\&. .TP \fB\fICHAR_SIZE_8 \fP\fP 8 bit characters\&. .TP \fB\fICHAR_SIZE_DEFAULT \fP\fP .PP Definition at line 96 of file SerialPort\&.h\&. .SS "enum \fBSerialPort::FlowControl\fP" .PP \fBEnumerator\fP .in +1c .TP \fB\fIFLOW_CONTROL_HARD \fP\fP .TP \fB\fIFLOW_CONTROL_SOFT \fP\fP .TP \fB\fIFLOW_CONTROL_NONE \fP\fP .TP \fB\fIFLOW_CONTROL_DEFAULT \fP\fP .PP Definition at line 117 of file SerialPort\&.h\&. .SS "enum \fBSerialPort::Parity\fP" .PP \fBEnumerator\fP .in +1c .TP \fB\fIPARITY_EVEN \fP\fP Even parity\&. .TP \fB\fIPARITY_ODD \fP\fP Odd parity\&. .TP \fB\fIPARITY_NONE \fP\fP No parity i\&.e\&. parity checking disabled\&. .TP \fB\fIPARITY_DEFAULT \fP\fP .PP Definition at line 110 of file SerialPort\&.h\&. .SS "enum \fBSerialPort::StopBits\fP" .PP \fBEnumerator\fP .in +1c .TP \fB\fISTOP_BITS_1 \fP\fP .TP \fB\fISTOP_BITS_2 \fP\fP 1 stop bit\&. .TP \fB\fISTOP_BITS_DEFAULT \fP\fP 2 stop bits\&. .PP Definition at line 104 of file SerialPort\&.h\&. .SH "Constructor & Destructor Documentation" .PP .SS "SerialPort::SerialPort (const std::string & serialPortName)\fC [explicit]\fP" .PP Constructor for a serial port\&. .SS "virtual SerialPort::~SerialPort ()\fC [virtual]\fP" .PP Destructor\&. .SS "SerialPort::SerialPort (const \fBSerialPort\fP & otherSerialPort)\fC [private]\fP" .PP Prevent copying of objects of this class by declaring the copy constructor private\&. This method is never defined\&. .SH "Member Function Documentation" .PP .SS "void SerialPort::Close ()\fBNotOpen\fP" .PP Close the serial port\&. All settings of the serial port will be lost and no more I/O can be performed on the serial port\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .RE .PP .SS "\fBBaudRate\fP SerialPort::GetBaudRate () const \fBNotOpen\fP,std::runtime_error" .PP Get the current baud rate for the serial port\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .RE .PP .SS "\fBCharacterSize\fP SerialPort::GetCharSize () const\fBNotOpen\fP" .PP Get the current character size for the serial port\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .RE .PP .SS "bool SerialPort::GetCts () const \fBNotOpen\fP,std::runtime_error" .SS "bool SerialPort::GetDsr () const \fBNotOpen\fP,std::runtime_error" .SS "bool SerialPort::GetDtr () const \fBNotOpen\fP,std::runtime_error" .PP Get the status of the DTR line\&. .SS "int SerialPort::GetFileDescriptor () const" .PP Get the low-level file descriptor associated with the serial port\&. .PP \fBWarning:\fP .RS 4 This is for advanced/power users only\&. Messing with this file descriptor (such as closing it) will probably cause problems\&. Be careful when you use it\&. Using this file descriptor after the controlling serial port has been closed or deleted (for example, when it goes out of scope) will result in undefined behavior\&. You have been warned! .RE .PP \fBReturns:\fP .RS 4 The low-level file descriptor corresponding to the serial port\&. .RE .PP \fBExceptions:\fP .RS 4 \fIThis\fP method will throw \fBNotOpen\fP if the serial port is not currently open\&. .RE .PP .SS "\fBFlowControl\fP SerialPort::GetFlowControl () const\fBNotOpen\fP" .PP Get the current flow control setting\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .RE .PP .SS "\fBStopBits\fP SerialPort::GetNumOfStopBits () const\fBNotOpen\fP" .PP Get the number of stop bits currently being used by the serial port\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .RE .PP .SS "\fBParity\fP SerialPort::GetParity () const\fBNotOpen\fP" .PP Get the parity type for the serial port\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .RE .PP .SS "bool SerialPort::GetRts () const \fBNotOpen\fP,std::runtime_error" .PP Get the status of the RTS line\&. .SS "bool SerialPort::IsDataAvailable () const\fBNotOpen\fP" .PP Check if data is available at the input of the serial port\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .RE .PP .SS "bool SerialPort::IsOpen () const" .PP Check if the serial port is open for I/O\&. .SS "void SerialPort::Open (const \fBBaudRate\fP baudRate = \fC\fBBAUD_DEFAULT\fP\fP, const \fBCharacterSize\fP charSize = \fC\fBCHAR_SIZE_DEFAULT\fP\fP, const \fBParity\fP parityType = \fC\fBPARITY_DEFAULT\fP\fP, const \fBStopBits\fP stopBits = \fC\fBSTOP_BITS_DEFAULT\fP\fP, const \fBFlowControl\fP flowControl = \fC\fBFLOW_CONTROL_DEFAULT\fP\fP) \fBAlreadyOpen\fP, \fBOpenFailed\fP, \fBUnsupportedBaudRate\fP,std::invalid_argument" .PP Open the serial port with the specified settings\&. A serial port cannot be used till it is open\&. .PP \fBExceptions:\fP .RS 4 \fI\fBAlreadyOpen\fP\fP This exception is thrown if the serial port is already open\&. .br \fI\fBOpenFailed\fP\fP This exception is thrown if the serial port could not be opened\&. .br \fIstd::invalid_argument\fP This exception is thrown if an invalid parameter value is specified\&. .RE .PP .SS "\fBSerialPort\fP& SerialPort::operator= (const \fBSerialPort\fP & otherSerialPort)\fC [private]\fP" .PP Prevent copying of objects of this class by declaring the assignment operator private\&. This method is never defined\&. .SS "void SerialPort::Read (\fBDataBuffer\fP & dataBuffer, const unsigned int numOfBytes = \fC0\fP, const unsigned int msTimeout = \fC0\fP) \fBNotOpen\fP, \fBReadTimeout\fP,std::runtime_error" .SS "unsigned char SerialPort::ReadByte (const unsigned int msTimeout = \fC0\fP) \fBNotOpen\fP, \fBReadTimeout\fP,std::runtime_error" .PP Read a single byte from the serial port\&. If no data is available in the specified number of milliseconds (msTimeout), then this method will throw \fBReadTimeout\fP exception\&. If msTimeout is 0, then this method will block till data is available\&. .SS "const std::string SerialPort::ReadLine (const unsigned int msTimeout = \fC0\fP, const char lineTerminator = \fC'\\n'\fP) \fBNotOpen\fP, \fBReadTimeout\fP,std::runtime_error" .PP Read a line of characters from the serial port\&. .SS "void SerialPort::SetBaudRate (const \fBBaudRate\fP baudRate) \fBUnsupportedBaudRate\fP, \fBNotOpen\fP,std::invalid_argument" .PP Set the baud rate for the serial port to the specified value (baudRate)\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .br \fIstd::invalid_argument\fP Thrown if an invalid baud rate is specified\&. .RE .PP .SS "void SerialPort::SetCharSize (const \fBCharacterSize\fP charSize) \fBNotOpen\fP,std::invalid_argument" .PP Set the character size for the serial port\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .br \fIstd::invalid_argument\fP Thrown if an invalid character size is specified\&. .RE .PP .SS "void SerialPort::SetDtr (const bool dtrState = \fCtrue\fP) \fBNotOpen\fP,std::runtime_error" .PP Set the DTR line to the specified value\&. .SS "void SerialPort::SetFlowControl (const \fBFlowControl\fP flowControl) \fBNotOpen\fP,std::invalid_argument" .PP Set flow control\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .br \fIstd::invalid_argument\fP Thrown if an invalid flow control is specified\&. .RE .PP .SS "void SerialPort::SetNumOfStopBits (const \fBStopBits\fP numOfStopBits) \fBNotOpen\fP,std::invalid_argument" .PP Set the number of stop bits to be used with the serial port\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .br \fIstd::invalid_argument\fP Thrown if an invalid number of stop bits is specified\&. .RE .PP .SS "void SerialPort::SetParity (const \fBParity\fP parityType) \fBNotOpen\fP,std::invalid_argument" .PP Set the parity type for the serial port\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .br \fIstd::invalid_argument\fP Thrown if an invalid parity is specified\&. .RE .PP .SS "void SerialPort::SetRts (const bool rtsState = \fCtrue\fP) \fBNotOpen\fP,std::runtime_error" .PP Set the RTS line to the specified value\&. .SS "void SerialPort::Write (const \fBDataBuffer\fP & dataBuffer) \fBNotOpen\fP,std::runtime_error" .PP Write the data from the specified vector to the serial port\&. .SS "void SerialPort::Write (const std::string & dataString) \fBNotOpen\fP,std::runtime_error" .PP Write a string to the serial port\&. .SS "void SerialPort::WriteByte (const unsigned char dataByte) \fBNotOpen\fP,std::runtime_error" .PP Send a single byte to the serial port\&. .PP \fBExceptions:\fP .RS 4 \fI\fBNotOpen\fP\fP Thrown if this method is called while the serial port is not open\&. .RE .PP .SH "Member Data Documentation" .PP .SS "SerialPortImpl* SerialPort::mSerialPortImpl\fC [private]\fP" .PP Pointer to implementation class instance\&. .PP Definition at line 504 of file SerialPort\&.h\&. .SH "Author" .PP Generated automatically by Doxygen for libserial from the source code\&.