Visual Servoing Platform
version 3.6.1 under development (2024-11-14)
|
#include <visp3/core/vpSerial.h>
Public Types | |
enum | bytesize_t { fivebits = 5 , sixbits = 6 , sevenbits = 7 , eightbits = 8 } |
enum | parity_t { parity_none = 0 , parity_odd = 1 , parity_even = 2 } |
enum | stopbits_t { stopbits_one = 1 , stopbits_two = 2 } |
enum | flowcontrol_t { flowcontrol_none = 0 , flowcontrol_software , flowcontrol_hardware } |
Public Member Functions | |
vpSerial (const std::string &port="", unsigned long baudrate=9600, bytesize_t bytesize=eightbits, parity_t parity=parity_none, stopbits_t stopbits=stopbits_one, flowcontrol_t flowcontrol=flowcontrol_none) | |
virtual | ~vpSerial () |
int | available () |
void | close () |
unsigned long | getBaudrate () |
bytesize_t | getBytesize () |
flowcontrol_t | getFlowcontrol () |
parity_t | getParity () |
std::string | getPort () |
stopbits_t | getStopbits () |
void | open () |
bool | read (char *c, long timeout_s) |
std::string | readline (const std::string &eol) |
void | setBaudrate (const unsigned long baudrate) |
void | setBytesize (const bytesize_t &bytesize) |
void | setFlowcontrol (const flowcontrol_t &flowcontrol) |
void | setParity (const parity_t &parity) |
void | setPort (const std::string &port) |
void | setStopbits (const stopbits_t &stopbits) |
void | write (const std::string &s) |
This class allows a serial port communication between 2 devices.
The following example shows how to write a string on port /dev/ttyUSB0
using the default constructor:
Definition at line 70 of file vpSerial.h.
enum vpSerial::bytesize_t |
Defines the possible byte sizes for the serial port.
Enumerator | |
---|---|
fivebits | Data is encoded with 5 bits. |
sixbits | Data is encoded with 6 bits. |
sevenbits | Data is encoded with 7 bits. |
eightbits | Data is encoded with 8 bits. |
Definition at line 76 of file vpSerial.h.
Defines the possible flowcontrol types for the serial port.
Enumerator | |
---|---|
flowcontrol_none | No flow control. |
flowcontrol_software | Software flow control. |
flowcontrol_hardware | Hardware flow control. |
Definition at line 106 of file vpSerial.h.
enum vpSerial::parity_t |
Defines the possible parity types for the serial port.
Enumerator | |
---|---|
parity_none | No parity check. |
parity_odd | Check for odd parity. |
parity_even | Check for even parity. |
Definition at line 87 of file vpSerial.h.
enum vpSerial::stopbits_t |
Defines the possible stopbit types for the serial port.
Enumerator | |
---|---|
stopbits_one | 1 stop bit is used |
stopbits_two | 2 stop bits are used |
Definition at line 97 of file vpSerial.h.
BEGIN_VISP_NAMESPACE vpSerial::vpSerial | ( | const std::string & | port = "" , |
unsigned long | baudrate = 9600 , |
||
bytesize_t | bytesize = eightbits , |
||
parity_t | parity = parity_none , |
||
stopbits_t | stopbits = stopbits_one , |
||
flowcontrol_t | flowcontrol = flowcontrol_none |
||
) |
Creates a serial port object that opens the port if the parameter is not empty.
Otherwise the port needs to be opened using open().
[in] | port | : Serial port name. A string similar to /dev/ttyUSB0 , /dev/ttySO , /dev/ttyAMA0 ... |
[in] | baudrate | : The baudrate parameter. Common values are 9600, 115200... |
[in] | bytesize | : Size of each byte in the serial transmission of data. Default is 8 bits. |
[in] | parity | : Parity parameter. Default is without parity check. |
[in] | stopbits | : Number of stop bits used. Default is 1 stop bit. |
[in] | flowcontrol | : Type of flow control used. Default is no flow control. |
Definition at line 104 of file vpSerial.cpp.
References open().
|
virtual |
Destructor that closes the serial port.
Definition at line 116 of file vpSerial.cpp.
References close().
int vpSerial::available | ( | ) |
Return the number of characters in the buffer.
Definition at line 174 of file vpSerial.cpp.
References vpException::fatalError.
void vpSerial::close | ( | ) |
Closes the serial port.
Definition at line 192 of file vpSerial.cpp.
References vpException::fatalError.
Referenced by ~vpSerial().
|
inline |
Return the baud rate; 9600, 115200...
Definition at line 125 of file vpSerial.h.
|
inline |
|
inline |
|
inline |
|
inline |
Return the serial port name like /dev/ttyUSB0
, /dev/ttySO
, /dev/ttyAMA0
...
Definition at line 149 of file vpSerial.h.
|
inline |
void vpSerial::open | ( | ) |
Open the serial port. If the serial port name is empty, or if the serial port is already opened an exception vpException::fatalError is thrown.
The following example shows how to open the serial port /dev/ttyUSB0
without using the constructor:
Definition at line 240 of file vpSerial.cpp.
References vpException::fatalError.
Referenced by vpSerial().
bool vpSerial::read | ( | char * | c, |
long | timeout_s | ||
) |
Read one character at a time.
[out] | c | : Character that is read. |
[in] | timeout_s | : Timeout in seconds. |
Definition at line 275 of file vpSerial.cpp.
References vpException::fatalError.
Referenced by readline().
std::string vpSerial::readline | ( | const std::string & | eol | ) |
Reads a set of characters until a given delimiter has been received.
[in] | eol | : End of line delimiter. A typical example is "\n". |
Definition at line 309 of file vpSerial.cpp.
References read().
void vpSerial::setBaudrate | ( | const unsigned long | baudrate | ) |
Set serial baud rate. Typical values are 9600, 19200, 38400, 57600, 115200...
Definition at line 122 of file vpSerial.cpp.
void vpSerial::setBytesize | ( | const bytesize_t & | bytesize | ) |
void vpSerial::setFlowcontrol | ( | const flowcontrol_t & | flowcontrol | ) |
void vpSerial::setParity | ( | const parity_t & | parity | ) |
void vpSerial::setPort | ( | const std::string & | port | ) |
Set the serial port name. The name is a string similar to /dev/ttyUSB0
, /dev/ttySO
, /dev/ttyAMA0
...
Definition at line 169 of file vpSerial.cpp.
void vpSerial::setStopbits | ( | const stopbits_t & | stopbits | ) |
void vpSerial::write | ( | const std::string & | s | ) |
Writes a string to the serial port.
[in] | s | : The data to write. |
Definition at line 332 of file vpSerial.cpp.
References vpException::fatalError.