|
|
| 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.
|
|
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.
|
|
void | setBaudRate (unsigned rate) |
| | Sets the baud rate.
|
|
unsigned | baudRate () const |
| | Gets the baud rate.
|
|
void | setCharSize (int size) |
| | Sets the char size.
|
|
int | charSize () const |
| | Gets the current char size.
|
|
void | setStopBits (StopBits bits) |
| | Sets the number of stop bits.
|
|
StopBits | stopBits () const |
| | Gets the current number of stop bits.
|
|
void | setParity (Parity parity) |
| | Sets the parity.
|
|
Parity | parity () const |
| | Gets the current parity.
|
|
void | setFlowControl (FlowControl flowControl) |
| | Sets the flow control kind.
|
|
FlowControl | flowControl () const |
| | Gets the current flow control kind.
|
|
void | setRts (bool on) |
| | Sets the RTS control line.
|
|
void | setDtr (bool on) |
| | Sets the DTR control line.
|
|
void | setBreak (bool on) |
| | Sets or clears a break condition.
|
|
void | sendBreak (int duration=0) |
| | Sends a break condition.
|
|
bool | isCts () const |
| | Returns true if CTS is asserted.
|
|
bool | isDsr () const |
| | Returns true if DSR is asserted.
|
|
void | clear () |
| | Clears pending error flags.
|
|
void | close () |
| | Closes the device.
|
|
void | setTimeout (std::size_t timeout) |
| | Sets the timeout for blocking I/O in milliseconds.
|
|
void | beginRead (char *buffer, std::size_t n) |
| | Begins to read data.
|
|
std::size_t | endRead () |
| | Ends reading data.
|
| std::size_t | read (char *buffer, std::size_t n) |
| | Read data from I/O device.
|
|
void | beginWrite (const char *buffer, std::size_t n) |
| | Begins to write data.
|
|
std::size_t | endWrite () |
| | Ends writing data.
|
| std::size_t | write (const char *buffer, std::size_t n) |
| | Write data to I/O device.
|
|
bool | seekable () const |
| | Returns true if device is seekable.
|
| pos_type | seek (off_type offset, seekdir sd) |
| | Moves the read position to the given offset.
|
| std::size_t | peek (char *buffer, std::size_t n) |
| | Peek data from I/O device without consuming them.
|
| void | sync () |
| | Synchronize device.
|
| pos_type | position () |
| | Returns the current I/O position.
|
|
bool | isEof () const |
| | Returns if the device has reached EOF.
|
| Signal< IODevice & > & | inputReady () |
| | Notifies about available data.
|
| Signal< IODevice & > & | outputReady () |
| | Notifies when data can be written.
|
|
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 | setActive (EventLoop &parent) |
| | Sets the parent loop, so that operations can be run.
|
|
void | detach () |
| | Remove from event loop and cancels outstanding operations.
|
|
void | cancel () |
| | Cancels all operations.
|
|
bool | run () |
| | Run operation if it is ready.
|
|
EventLoop * | parent () const |
| | Returns the used event loop.
|
SerialDevice opens a serial port as an IODevice. The path is system-dependent, for example "COM1" on Windows or "/dev/ttyS0" on POSIX. Open the port, then set baud rate, character size, stop bits, parity, and flow control before read or write.
The device supports the blocking and asynchronous transfers of IODevice. Control lines are available as setRts(), setDtr(), isCts(), and isDsr(). setBreak() and sendBreak() generate a break condition.
device.setBaudRate(Pt::System::SerialDevice::BaudRate9600);
device.setCharSize(8);
device.setStopBits(Pt::System::SerialDevice::OneStopBit);
device.setParity(Pt::System::SerialDevice::ParityNone);
device.setFlowControl(Pt::System::SerialDevice::FlowControlNone);
char buffer[64];
std::size_t n = device.read(buffer, sizeof(buffer));
Serial port as an IODevice.
Definition SerialDevice.h:69