|
| SerialDevice () |
| Default constructor.
|
|
| SerialDevice (const std::string &file, std::ios::openmode mode) |
| Constructs a serial device and open the specified device file.
|
|
| SerialDevice (const char *file, std::ios::openmode mode) |
| Constructs a serial device and open the specified device file.
|
|
virtual | ~SerialDevice () |
| Destructor.
|
|
unsigned | baudRate () const |
| Gets the baud rate.
|
|
void | beginRead (char *buffer, std::size_t n) |
| Begins to read data.
|
|
void | beginWrite (const char *buffer, std::size_t n) |
| Begins to write data.
|
|
void | cancel () |
| Cancels all operations.
|
|
int | charSize () const |
| Gets the current char size.
|
|
void | close () |
| Closes the device.
|
|
void | detach () |
| Remove from event loop and cancels outstanding operations.
|
|
std::size_t | endRead () |
| Ends reading data.
|
|
std::size_t | endWrite () |
| Ends writing data.
|
|
FlowControl | flowControl () const |
| Gets the current flow control kind.
|
|
Signal< IODevice & > & | inputReady () |
| Notifies about available data. More...
|
|
bool | isEof () const |
| Returns if the device has reached EOF.
|
|
bool | isReading () const |
| Returns true if the device is reading.
|
|
bool | isWriting () const |
| Returns true if the device is writing.
|
|
EventLoop * | loop () const |
| Returns the used event loop.
|
|
void | open (const std::string &file, std::ios::openmode mode) |
| Open the specified device file.
|
|
void | open (const char *file, std::ios::openmode mode) |
| Open the specified device file.
|
|
Signal< IODevice & > & | outputReady () |
| Notifies when data can be written. More...
|
|
Parity | parity () const |
| Gets the current parity.
|
|
std::size_t | peek (char *buffer, std::size_t n) |
| Peek data from I/O device without consuming them. More...
|
|
pos_type | position () |
| Returns the current I/O position. More...
|
|
std::size_t | read (char *buffer, std::size_t n) |
| Read data from I/O device. More...
|
|
bool | run () |
| Run operation if it is ready.
|
|
pos_type | seek (off_type offset, seekdir sd) |
| Moves the read position to the given offset. More...
|
|
bool | seekable () const |
| Returns true if device is seekable.
|
|
void | setActive (EventLoop &parent) |
| Sets the parent loop, so that operations can be run.
|
|
void | setBaudRate (unsigned rate) |
| Sets the baud rate.
|
|
void | setCharSize (int size) |
| Sets the char size.
|
|
void | setFlowControl (FlowControl flowControl) |
| Sets the flow control kind.
|
|
void | setParity (Parity parity) |
| Sets the parity.
|
|
void | setStopBits (StopBits bits) |
| Sets the number of stop bits.
|
|
void | setTimeout (std::size_t timeout) |
| Sets the timeout for blocking I/O in milliseconds.
|
|
StopBits | stopBits () const |
| Gets the current number of stop bits.
|
|
void | sync () |
| Synchronize device. More...
|
|
std::size_t | write (const char *buffer, std::size_t n) |
| Write data to I/O device. More...
|
|
This class implements access to a serial port as an IODevice. A SerialDevice can be opened by passing a system dependent path and an open mode. Then serial port attributes can be set before read or write operations are performed. The following example opens a COM port on windows, sets serial device attributes for a serial mouse and toggles the flow control to cause the device to send a PNP string which will be read subsequently:
using Pt::System;
serdev.setBaudRate(Pt::System::SerialDevice::BaudRate1200);
serdev.setCharSize(7);
serdev.setStopBits(Pt::System::SerialDevice::OneStopBit);
serdev.setParity(Pt::System::SerialDevice::ParityNone);
serdev.setFlowControl(Pt::System::SerialDevice::FlowControlHard);
serdev.setFlowControl(Pt::System::SerialDevice::FlowControlSoft);
char pnp_id[200];
size_t size = serdev.read( pnp_id, 200);
std::cerr << "Mouse Id: ";
std::cerr.write(pnp_id, size) << std::endl;