
#include <Devices/Serial.H>
Inheritance diagram for Serial:


The port will be open at start() time; see ModelComponent.H for details. Because typically one may use several serial ports with different configs, this ModelComponent does not export any command-line option (there would be too many otherwise if many ports are used). Typically, thus, the port can be configured either via config files or using the various access functions provided in this class.
Definition at line 86 of file Serial.H.
Public Member Functions | |
| Serial (OptionManager &mgr, const std::string &descrName="Serial Port", const std::string &tagName="SerialPort") | |
| Constructor. | |
| ~Serial (void) | |
| destructor | |
| void | closePort () |
| Close the serial port device file. | |
| void | enablePort (std::string DeviceName) |
| Enable the serial port. | |
| void | configure (const char *dev="", const int speed=9600, const char *format="8N1", const bool flowSoft=false, const bool flowHard=false, const int=0) |
| Configure the port before it is started. | |
| void | configureSearch (const std::string DeviceDescription, const int speed=115200, const std::string SearchPrefix="ttyUSB", const char *format="8N1", const bool flowSoft=false, const bool flowHard=false, const int=0) |
| Configure the serial port to search for a device. | |
| serialError | setSpeed (const int speed) |
| Set serial port speed for both input and output. | |
| serialError | setFlowControl (const bool useHard, const bool useSoft) |
| Set the serial port flow control on Input as well as Ouput. | |
| serialError | setCharBits (const int bits) |
| Set character size. | |
| serialError | setParity (const bool useParity, const bool oddParity) |
| Set parity mode. | |
| serialError | setStopBits (const int bits) |
| Set number of stop bits. | |
| serialError | setBlocking (const bool blocking) |
| Set the access to blocking or not. | |
| void | toggleDTR (const time_t millisec) |
| Set the DTR mode off momentarily. | |
| void | sendBreak (void) |
| transmit continuous stream of zero-valued bits for specific duration. | |
| int | read (void *buffer, const int nbytes) |
| attempt to read up to nbytes from serial port into the buffer | |
| std::vector< unsigned char > | readFrame (const unsigned char frameStart, const unsigned char frameEnd=255, const int frameLength=-1, const double timeout=-1) |
| Attempt to read a serial frame. | |
| char | read (void) |
| attempts to get the next character from the serial port | |
| int | write (const void *buffer, const int nbytes) |
| write bytes to the port | |
| int | write (const unsigned char character) |
| write a single byte to the port - a simple wrapper around write(const void* buffer, const int nbytes) | |
| void | perror (void) |
| print a verbal message indicating the last error. | |
| void | flush (void) |
| std::string | getDeviceDescriptor () |
| std::string | getDevName () |
Protected Member Functions | |
| void | start2 () |
| open the port and get started | |
| void | stop2 () |
| close the port and get stopped | |
Protected Attributes | |
| OModelParam< std::string > | itsCmdDevName |
| device name passed from cmd line | |
| NModelParam< std::string > | itsDeviceDescription |
| device description to seach for | |
| NModelParam< std::string > | itsSearchPrefix |
| device name prefix (e.g. ttyUSB) | |
| NModelParam< int > | itsBaud |
| Baudrate. | |
| NModelParam< int > | itsCharBits |
| number of useful bits per char | |
| NModelParam< int > | itsStopBits |
| number of stop bits | |
| NModelParam< bool > | itsUseParity |
| use parity if true | |
| NModelParam< bool > | itsParityOdd |
| parity is odd if true, otherwise even | |
| NModelParam< bool > | itsFlowHard |
| use hardware flow control if true | |
| NModelParam< bool > | itsFlowSoft |
| use software flow control if true | |
| NModelParam< int > | itsRdTout |
| read timeout in 1/10000s | |
| NModelParam< bool > | itsBlocking |
| use blocking mode | |
|
||||||||||||||||
|
Constructor.
|
|
|
destructor
|
|
|
Close the serial port device file.
Definition at line 177 of file Serial.C. Referenced by enablePort(), and stop2(). |
|
||||||||||||||||||||||||||||
|
Configure the port before it is started. This will update our internal ModelParam values to the specified ones; thus this should be called before start(). In contrast, the setXXX functions below are for reconfiguration at runtime, once the port is already open and running. This function is provided as a shortcut to set a bunch of ModelParam values in one simple call.
Definition at line 197 of file Serial.C. References itsBaud, itsCharBits, itsFlowHard, itsFlowSoft, itsParityOdd, itsRdTout, itsStopBits, itsUseParity, LFATAL, and NModelParam< T >::setVal(). Referenced by configureSearch(). |
|
||||||||||||||||||||||||||||||||
|
Configure the serial port to search for a device.
Definition at line 186 of file Serial.C. References configure(), itsDeviceDescription, itsSearchPrefix, and NModelParam< T >::setVal(). |
|
|
Enable the serial port. enablePort will do all of the work of actually setting the config properties that have been requested, as well as opening the device file, etc... Definition at line 142 of file Serial.C. References closePort(), NModelParam< T >::getVal(), itsBaud, itsBlocking, itsCharBits, itsFlowHard, itsFlowSoft, itsParityOdd, itsUseParity, perror(), setBlocking(), setCharBits(), setFlowControl(), setParity(), and setSpeed(). Referenced by start2(). |
|
|
print a verbal message indicating the last error.
Definition at line 712 of file Serial.C. References LERROR. Referenced by enablePort(). |
|
|
attempts to get the next character from the serial port for comptability with dirk's code Definition at line 571 of file Serial.C. Referenced by read(), and readFrame(). |
|
||||||||||||
|
attempt to read up to nbytes from serial port into the buffer
|
|
||||||||||||||||||||
|
Attempt to read a serial frame. The frame returned by the device should have the following format: [start byte] [optional number of data bytes] [data...] ... [...data] [end byte]
Definition at line 580 of file Serial.C. References data, Timer::getSecs(), read(), Timer::reset(), and timer. Referenced by start2(). |
|
|
transmit continuous stream of zero-valued bits for specific duration.
|
|
|
Set the access to blocking or not. If blocking, a write will block until all data has actually been sent through; otherwise it will return immediately while the data is being transmitted. Definition at line 426 of file Serial.C. References itsBlocking, PLERROR, and NModelParam< T >::setVal(). Referenced by enablePort(). |
|
|
Set character size. This function is to change the char size while already started.
Definition at line 338 of file Serial.C. References itsCharBits, and NModelParam< T >::setVal(). Referenced by enablePort(). |
|
||||||||||||
|
Set the serial port flow control on Input as well as Ouput. This function is to change the flow control while already started.
Definition at line 310 of file Serial.C. References itsFlowHard, itsFlowSoft, and NModelParam< T >::setVal(). Referenced by enablePort(). |
|
||||||||||||
|
Set parity mode. This function is to change the parity while already started.
Definition at line 370 of file Serial.C. References itsParityOdd, itsUseParity, and NModelParam< T >::setVal(). Referenced by enablePort(). |
|
|
Set serial port speed for both input and output. This function is to change the speed while already started.
Definition at line 234 of file Serial.C. References itsBaud, and NModelParam< T >::setVal(). Referenced by enablePort(). |
|
|
Set number of stop bits. This function is to change the stop bits while started.
Definition at line 401 of file Serial.C. References itsStopBits, and NModelParam< T >::setVal(). |
|
|
open the port and get started
Reimplemented from ModelComponent. Definition at line 82 of file Serial.C. References enablePort(), OModelParam< T >::getVal(), NModelParam< T >::getVal(), itsCmdDevName, itsDeviceDescription, itsSearchPrefix, LFATAL, LINFO, readFrame(), OModelParam< T >::setVal(), and write(). |
|
|
close the port and get stopped
Reimplemented from ModelComponent. Definition at line 171 of file Serial.C. References closePort(). |
|
|
Set the DTR mode off momentarily.
|
|
|
write a single byte to the port - a simple wrapper around write(const void* buffer, const int nbytes)
Definition at line 695 of file Serial.C. References write(). |
|
||||||||||||
|
write bytes to the port
Definition at line 670 of file Serial.C. References n. |
|
|
Baudrate.
Definition at line 233 of file Serial.H. Referenced by configure(), enablePort(), and setSpeed(). |
|
|
use blocking mode
Definition at line 241 of file Serial.H. Referenced by enablePort(), and setBlocking(). |
|
|
number of useful bits per char
Definition at line 234 of file Serial.H. Referenced by configure(), enablePort(), and setCharBits(). |
|
|
device name passed from cmd line
Definition at line 226 of file Serial.H. Referenced by start2(). |
|
|
device description to seach for
Definition at line 231 of file Serial.H. Referenced by configureSearch(), getDeviceDescriptor(), and start2(). |
|
|
use hardware flow control if true
Definition at line 238 of file Serial.H. Referenced by configure(), enablePort(), and setFlowControl(). |
|
|
use software flow control if true
Definition at line 239 of file Serial.H. Referenced by configure(), enablePort(), and setFlowControl(). |
|
|
parity is odd if true, otherwise even
Definition at line 237 of file Serial.H. Referenced by configure(), enablePort(), and setParity(). |
|
|
read timeout in 1/10000s
Definition at line 240 of file Serial.H. Referenced by configure(). |
|
|
device name prefix (e.g. ttyUSB)
Definition at line 232 of file Serial.H. Referenced by configureSearch(), and start2(). |
|
|
number of stop bits
Definition at line 235 of file Serial.H. Referenced by configure(), and setStopBits(). |
|
|
use parity if true
Definition at line 236 of file Serial.H. Referenced by configure(), enablePort(), and setParity(). |
1.4.4