![]() |
libcyberradio
22.01.24
|
Class that manages communications with a serial port. More...
#include <SerialPort.h>
Public Member Functions | |
| SerialPort (const std::string &device, int baudrate=115200, char parity='N', int databits=8, int stopbits=1, bool xonxoff=false, bool rtscts=false, bool debug=false) | |
| Constructs a SerialPort object. More... | |
| ~SerialPort () | |
| Destroys a SerialPort object. | |
| SerialPort (const SerialPort &other) | |
| Copies a SerialPort object. More... | |
| SerialPort & | operator= (const SerialPort &other) |
| Assignment operator for SerialPort objects. More... | |
| bool | open () |
| Open the serial port. More... | |
| bool | close () |
| Close the serial port. More... | |
| std::string | read () |
| Reads data from the serial port. | |
| bool | write (const std::string &data) |
| Writes data to the serial port. More... | |
| int | getBaudRate () const |
| Gets the current baud rate. More... | |
| bool | setBaudRate (int baudrate) |
| Sets the current baud rate. More... | |
| char | getParity () const |
| Gets the current parity setting. More... | |
| bool | setParity (char parity) |
| Sets the current parity setting. More... | |
| int | getDataBits () const |
| Gets the current number of data bits. More... | |
| bool | setDataBits (int databits) |
| Sets the current number of data bits. More... | |
| int | getStopBits () const |
| Gets the current number of stop bits. More... | |
| bool | setStopBits (int stopbits) |
| Sets the current number of stop bits. More... | |
| bool | usesXonXoffFlowControl () const |
| Gets whether the serial port currently uses XON/XOFF (software) flow control. More... | |
| bool | enableXonXoffFlowControl (bool enabled) |
| Enables XON/XOFF (software) flow control on the serial port. More... | |
| bool | usesRtsCtsFlowControl () const |
| Gets whether the serial port currently uses RTS/CTS (hardware) flow control. More... | |
| bool | enableRtsCtsFlowControl (bool enabled) |
| Enables RTS/CTS (hardware) flow control on the serial port. More... | |
| std::string | getLastError () const |
| Gets the last error message. More... | |
| virtual void | setDebugName (const std::string &debug_name) |
| Sets the debug name for this object. More... | |
| virtual void | setDebugFile (FILE *debug_fp) |
| Sets the debug file pointer for this object. More... | |
| virtual void | setDebugTimeFormat (const std::string &debug_timefmt) |
| Sets the debug time format for this object. More... | |
| virtual int | debug (const char *format,...) |
| Outputs debug information. More... | |
| virtual const char * | debugBool (bool x) |
| Gets a debug output string for a Boolean value. More... | |
| virtual bool | isDebug () const |
| Gets whether this object produces debug output. More... | |
| virtual std::string | getDebugName () const |
| Gets the debug name for this object. More... | |
| virtual std::string | rawString (const std::string &data) |
| Gets a "raw" string representation of a given data string. More... | |
Class that manages communications with a serial port.
Definition at line 28 of file SerialPort.h.
| SerialPort | ( | const std::string & | device, |
| int | baudrate = 115200, |
||
| char | parity = 'N', |
||
| int | databits = 8, |
||
| int | stopbits = 1, |
||
| bool | xonxoff = false, |
||
| bool | rtscts = false, |
||
| bool | debug = false |
||
| ) |
Constructs a SerialPort object.
| device | Serial device name (such as "/dev/ttyS0") |
| baudrate | Baud rate |
| parity | Parity setting. One of 'N' (none), 'E' (even), or 'O' (odd). |
| databits | Number of data bits |
| stopbits | Number of stop bits |
| xonxoff | Whether the serial port uses XON/XOFF (software) flow control |
| rtscts | Whether the serial port uses RTS/CTS (hardware) flow control |
| debug | Whether the transport emits debug output (Boolean). |
Definition at line 25 of file SerialPort.cpp.
| SerialPort | ( | const SerialPort & | other | ) |
Copies a SerialPort object.
| other | The SerialPort object to copy. |
Definition at line 63 of file SerialPort.cpp.
| bool close | ( | ) |
Close the serial port.
Definition at line 212 of file SerialPort.cpp.
|
virtualinherited |
Outputs debug information.
This method follows the same semantics as printf(). Output is preceded by a timestamp and the name of the object, if provided.
| format | The printf()-style format string. |
| ... | Comma-separated list of arguments to print. Note that these need to be arguments that can be supported natively through printf(). |
Definition at line 95 of file Debuggable.cpp.
|
virtualinherited |
Gets a debug output string for a Boolean value.
| x | Boolean value |
Definition at line 126 of file Debuggable.cpp.
| bool enableRtsCtsFlowControl | ( | bool | enabled | ) |
Enables RTS/CTS (hardware) flow control on the serial port.
| enabled | Whether or not flow control should be used. |
Definition at line 625 of file SerialPort.cpp.
| bool enableXonXoffFlowControl | ( | bool | enabled | ) |
Enables XON/XOFF (software) flow control on the serial port.
| enabled | Whether or not flow control should be used. |
Definition at line 586 of file SerialPort.cpp.
| int getBaudRate | ( | ) | const |
Gets the current baud rate.
Definition at line 303 of file SerialPort.cpp.
| int getDataBits | ( | ) | const |
Gets the current number of data bits.
Definition at line 481 of file SerialPort.cpp.
|
virtualinherited |
Gets the debug name for this object.
Definition at line 138 of file Debuggable.cpp.
| std::string getLastError | ( | ) | const |
Gets the last error message.
Definition at line 659 of file SerialPort.cpp.
| char getParity | ( | ) | const |
Gets the current parity setting.
Definition at line 432 of file SerialPort.cpp.
| int getStopBits | ( | ) | const |
Gets the current number of stop bits.
Definition at line 537 of file SerialPort.cpp.
|
virtualinherited |
Gets whether this object produces debug output.
Definition at line 133 of file Debuggable.cpp.
| bool open | ( | ) |
Open the serial port.
Definition at line 104 of file SerialPort.cpp.
| SerialPort & operator= | ( | const SerialPort & | other | ) |
Assignment operator for SerialPort objects.
| other | The RadioTransport object to copy. |
Definition at line 81 of file SerialPort.cpp.
|
virtualinherited |
Gets a "raw" string representation of a given data string.
"Raw" string representations mimic Python string representations. Whitespace characters are denoted by backslash representations ("\\r", "\\n", "\\t", "\\v", "\\f"), while other non-printable characters are represented with hex representation ("\\x00", etc.)
| data | Data string |
Definition at line 143 of file Debuggable.cpp.
| bool setBaudRate | ( | int | baudrate | ) |
Sets the current baud rate.
| baudrate | The baud rate, in bytes per second. |
Definition at line 308 of file SerialPort.cpp.
| bool setDataBits | ( | int | databits | ) |
Sets the current number of data bits.
| databits | The number of data bits (5, 6, 7, or 8). |
Definition at line 486 of file SerialPort.cpp.
|
virtualinherited |
Sets the debug file pointer for this object.
| debug_fp | File to send debug output to. |
Definition at line 81 of file Debuggable.cpp.
|
virtualinherited |
Sets the debug name for this object.
Use this method to set unique debug names for objects of the same class for easy differentiation.
| debug_name | Name for identifying this object in debug output. |
Definition at line 74 of file Debuggable.cpp.
|
virtualinherited |
Sets the debug time format for this object.
| debug_timefmt | Format string for displaying timestamp, as compatible with strftime(). If this is an empty string, don't display a timestamp. |
Definition at line 88 of file Debuggable.cpp.
| bool setParity | ( | char | parity | ) |
Sets the current parity setting.
| parity | The parity setting. One of 'N' (none), 'E' (even), or 'O' (odd). |
Definition at line 437 of file SerialPort.cpp.
| bool setStopBits | ( | int | stopbits | ) |
Sets the current number of stop bits.
| stopbits | The number of data bits (1 or 2). |
Definition at line 542 of file SerialPort.cpp.
| bool usesRtsCtsFlowControl | ( | ) | const |
Gets whether the serial port currently uses RTS/CTS (hardware) flow control.
Definition at line 620 of file SerialPort.cpp.
| bool usesXonXoffFlowControl | ( | ) | const |
Gets whether the serial port currently uses XON/XOFF (software) flow control.
Definition at line 581 of file SerialPort.cpp.
| bool write | ( | const std::string & | data | ) |
Writes data to the serial port.
| data | Data to write. |
Definition at line 271 of file SerialPort.cpp.