|
virtual | ~Port () |
|
virtual void | Open ()=0 |
| Open the port. More...
|
|
virtual void | Close ()=0 |
| Close the port. More...
|
|
virtual ssize_t | Read (void *const buffer, size_t count)=0 |
| Read from the port. More...
|
|
virtual ssize_t | ReadFull (void *const buffer, size_t count)=0 |
| Read the requested quantity of data from the port. More...
|
|
virtual ssize_t | ReadString (std::string &buffer) |
| Read a string. More...
|
|
virtual ssize_t | ReadUntil (void *const buffer, size_t count, uint8_t terminator) |
| Read data until a specified termination byte is received. More...
|
|
virtual ssize_t | ReadStringUntil (std::string &buffer, char terminator) |
| Read a string until the specified termination character is received. More...
|
|
virtual ssize_t | ReadLine (char *const buffer, size_t count) |
| Read a new-line terminated string of data. More...
|
|
virtual ssize_t | ReadLine (std::string &buffer) |
| Read a new-line terminated string of data. More...
|
|
virtual ssize_t | Skip (size_t count) |
| Dump data until the specified number of bytes have been read. More...
|
|
virtual ssize_t | SkipUntil (uint8_t terminator, unsigned int count) |
| Read and dump data until the specified termination character has been seen count times. More...
|
|
virtual ssize_t | BytesAvailable ()=0 |
| Get the number of bytes waiting to be read at the port. More...
|
|
virtual ssize_t | BytesAvailableWait ()=0 |
| Get the number of bytes waiting after blocking for the timeout. More...
|
|
virtual ssize_t | Write (const void *const buffer, size_t count)=0 |
| Write data to the port. More...
|
|
virtual ssize_t | WriteFull (const void *const buffer, size_t count) |
| Write all the data to the port. More...
|
|
virtual ssize_t | WriteString (const char *const buffer) |
| Write a string to the port. More...
|
|
virtual ssize_t | WriteString (const std::string &buffer) |
|
virtual void | Flush ()=0 |
| Flush the port's input and output buffers, discarding all data. More...
|
|
virtual void | Drain ()=0 |
| Drain the port's output buffers. More...
|
|
virtual std::string | GetStatus () const |
| Get the status of the port (type, device, etc). More...
|
|
std::string | GetPortType () const |
| Get the port type. More...
|
|
void | SetDebug (int debug) |
| Set the debug level. More...
|
|
int | GetDebug () const |
| Get the debug level. More...
|
|
virtual void | SetTimeout (Timeout timeout)=0 |
| Set the timeout value. More...
|
|
virtual Timeout | GetTimeout () const |
| Get the timeout. More...
|
|
virtual bool | IsBlocking () const |
| Get the blocking property of the port. More...
|
|
virtual void | SetCanRead (bool canRead)=0 |
| Set the read permissions of the port. More...
|
|
virtual bool | CanRead () const |
| Get the read permissions of the port. More...
|
|
virtual void | SetCanWrite (bool canWrite)=0 |
| Set the write permissions of the port. More...
|
|
virtual bool | CanWrite () const |
| Get the write permissions of the port. More...
|
|
virtual bool | IsOpen () const =0 |
| Check if the port is open. More...
|
|
Base Port class.
This provides the base object from which specific port type implementations inherit.
All functions may throw exceptions of type PortException.
- Options
- debug <integer>
- Debug level. Higher numbers give more information.
- Default: 0 (no debug information)
- timeout <float>
- Time out on read/write, in seconds.microseconds.
- A timeout of -1 disables timeouts, creating a port that will block forever.
- Default: -1
- readonly, writeonly, readwrite
- Specify one type of permissions.
- Default: readwrite
- alwaysopen
- The port should be open for as long as the object exists. It will be opened when constructed and if it closes unexpectedly, an attempt will be made to reopen it.
- Default: off
Definition at line 81 of file port.h.
virtual ssize_t flexiport::Port::ReadFull |
( |
void *const |
buffer, |
|
|
size_t |
count |
|
) |
| |
|
pure virtual |
Read the requested quantity of data from the port.
Reads count bytes from the port into buffer. Similar to Read, but with the important difference that, rather than returning as soon as any data is received, it will continue trying to receive data until buffer is full or an error occurs. This function ignores the timeout setting and blocks anyway.
- Returns
- The number of bytes actually read. Timeouts will cause an exception (because they shouldn't happen).
Implemented in flexiport::UDPPort, flexiport::LogReaderPort, flexiport::SerialPort, flexiport::LogWriterPort, and flexiport::TCPPort.
virtual ssize_t flexiport::Port::ReadLine |
( |
char *const |
buffer, |
|
|
size_t |
count |
|
) |
| |
|
virtual |
Read a new-line terminated string of data.
A convenience function that reads until a newline character (\n, 0x0A) is received and stores the received data in a caller-provided buffer, buffer. Good for text-based protocols that use newlines as message terminators. Will not read more than count bytes.
buffer should include space for a NULL byte. count should reflect this. e.g. if you are expecting to receive a string "abcd\n", you should send a buffer that is 6 bytes long and make count = 6. This function will take into account the need for a NULL terminator when it receives data, receiving at most one less than count bytes. This NULL byte will not be included in the length of the received string returned from this function (just like strlen ()).
- Note
- This function makes many calls to Read, each of which has an individual timeout. The maximum length of time this function may take may therefore be longer than one timeout.
-
If the port is set to non-blocking mode (by setting the timeout to zero), this will effectively timeout immediately when there is no data available, returning -1 irrespective of the quantity of data actually received before that point.
- Returns
- The length of the string (including the new line), or -1 if a timeout occured.
virtual ssize_t flexiport::Port::ReadLine |
( |
std::string & |
buffer | ) |
|
|
inlinevirtual |
Read a new-line terminated string of data.
A convenience function that reads until a newline character (\n, 0x0A) is received and stores the received data in a string, buffer. Good for text-based protocols that use newlines as message terminators.
- Note
- This function makes many calls to Read, each of which has an individual timeout. The maximum length of time this function make take may therefore be longer than one timeout.
-
If the port is set to non-blocking mode (by setting the timeout to zero), this will effectively timeout immediatly when there is no data available, returning -1 irrespective of the quantity of data actually received before that point.
- Returns
- The length of the string (including the new line), or -1 if a timeout occured.
Definition at line 217 of file port.h.
virtual ssize_t flexiport::Port::Write |
( |
const void *const |
buffer, |
|
|
size_t |
count |
|
) |
| |
|
pure virtual |
Write data to the port.
Simply writes count bytes of data from buffer to the port. If the port is blocking, this will block until it can write more when the port's output buffer is full, or until a timeout occurs. The buffer may become full during the write, in which case less than count bytes may be written.
- Returns
- The number of bytes actually written. May be 0 if the port's output buffer is already full and a timeout occurs.
Implemented in flexiport::UDPPort, flexiport::LogReaderPort, flexiport::SerialPort, flexiport::LogWriterPort, and flexiport::TCPPort.