Serial¶
- class Serial(self: visp._visp.core.Serial, port: str =, baudrate: int, bytesize: visp._visp.core.Serial.bytesize_t, parity: visp._visp.core.Serial.parity_t, stopbits: visp._visp.core.Serial.stopbits_t, flowcontrol: visp._visp.core.Serial.flowcontrol_t)¶
Bases:
pybind11_object
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:
#include <visp3/core/vpSerial.h> int main() { #ifndef WIN32 vpSerial serial("/dev/ttyUSB0"); serial.write("Hello world"); #endif }
Note
This class is not implemented on windows-like OS.
Creates a serial port object that opens the port if the parameter is not empty.
#include <visp3/core/vpSerial.h> int main() { #ifndef WIN32 vpSerial serial("/dev/ttyUSB0"); #endif }
Otherwise the port needs to be opened using open() .
#include <visp3/core/vpSerial.h> int main() { #ifndef WIN32 vpSerial serial; serial.setPort("/dev/ttyUSB0"); serial.open(); #endif }
- Parameters:
- port
Serial port name. A string similar to /dev/ttyUSB0 , /dev/ttySO , /dev/ttyAMA0 …
- baudrate
The baudrate parameter. Common values are 9600, 115200…
- bytesize
Size of each byte in the serial transmission of data. Default is 8 bits.
- parity
Parity parameter. Default is without parity check.
- stopbits
Number of stop bits used. Default is 1 stop bit.
- flowcontrol
Type of flowcontrol used. Default is no flow control.
Methods
Creates a serial port object that opens the port if the parameter is not empty.
Return the number of characters in the buffer.
Closes the serial port.
Return the baud rate; 9600, 115200...
Return the byte size.
Return the flow control type.
Return parity.
Return the serial port name like /dev/ttyUSB0 , /dev/ttySO , /dev/ttyAMA0 ...
Return number of stop bits used.
Open the serial port.
- param eol:
End of line delimiter. A typical example is "n".
Set serial baud rate.
Set the serial port name.
Writes a string to the serial port.
Inherited Methods
Operators
__doc__
Creates a serial port object that opens the port if the parameter is not empty.
__module__
Attributes
__annotations__
eightbits
fivebits
flowcontrol_hardware
flowcontrol_none
flowcontrol_software
parity_even
parity_none
parity_odd
sevenbits
sixbits
stopbits_one
stopbits_two
- class bytesize_t(self, value: int)¶
Bases:
pybind11_object
Defines the possible flowcontrol types for the serial port.
Values:
flowcontrol_none: No flow control.
flowcontrol_software: Software flow control.
flowcontrol_hardware: Hardware flow control.
- class flowcontrol_t(self, value: int)¶
Bases:
pybind11_object
Defines the possible flowcontrol types for the serial port.
Values:
flowcontrol_none: No flow control.
flowcontrol_software: Software flow control.
flowcontrol_hardware: Hardware flow control.
- class parity_t(self, value: int)¶
Bases:
pybind11_object
Defines the possible flowcontrol types for the serial port.
Values:
flowcontrol_none: No flow control.
flowcontrol_software: Software flow control.
flowcontrol_hardware: Hardware flow control.
- class stopbits_t(self, value: int)¶
Bases:
pybind11_object
Defines the possible flowcontrol types for the serial port.
Values:
flowcontrol_none: No flow control.
flowcontrol_software: Software flow control.
flowcontrol_hardware: Hardware flow control.
- __init__(self: visp._visp.core.Serial, port: str =, baudrate: int, bytesize: visp._visp.core.Serial.bytesize_t, parity: visp._visp.core.Serial.parity_t, stopbits: visp._visp.core.Serial.stopbits_t, flowcontrol: visp._visp.core.Serial.flowcontrol_t)¶
Creates a serial port object that opens the port if the parameter is not empty.
#include <visp3/core/vpSerial.h> int main() { #ifndef WIN32 vpSerial serial("/dev/ttyUSB0"); #endif }
Otherwise the port needs to be opened using open() .
#include <visp3/core/vpSerial.h> int main() { #ifndef WIN32 vpSerial serial; serial.setPort("/dev/ttyUSB0"); serial.open(); #endif }
- Parameters:
- port
Serial port name. A string similar to /dev/ttyUSB0 , /dev/ttySO , /dev/ttyAMA0 …
- baudrate
The baudrate parameter. Common values are 9600, 115200…
- bytesize
Size of each byte in the serial transmission of data. Default is 8 bits.
- parity
Parity parameter. Default is without parity check.
- stopbits
Number of stop bits used. Default is 1 stop bit.
- flowcontrol
Type of flowcontrol used. Default is no flow control.
- getBytesize(self) visp._visp.core.Serial.bytesize_t ¶
Return the byte size.
Note
See setBytesize()
- getFlowcontrol(self) visp._visp.core.Serial.flowcontrol_t ¶
Return the flow control type.
Note
See setFlowcontrol()
- getParity(self) visp._visp.core.Serial.parity_t ¶
Return parity.
Note
See setParity()
- getPort(self) str ¶
Return the serial port name like /dev/ttyUSB0 , /dev/ttySO , /dev/ttyAMA0 …
Note
See setPort()
- getStopbits(self) visp._visp.core.Serial.stopbits_t ¶
Return number of stop bits used.
Note
See setStopbits()
- open(self) None ¶
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:
#include <visp3/core/vpSerial.h> int main() { #ifndef WIN32 vpSerial serial; serial.setPort("/dev/ttyUSB0"); serial.setBaudrate(9600); serial.setBytesize(vpSerial::eightbits); serial.setParity(vpSerial::parity_none); serial.setStopbits(vpSerial::stopbits_one); serial.setFlowcontrol(vpSerial::flowcontrol_none); serial.open(); #endif }
- setBaudrate(self, baudrate: int) None ¶
Set serial baud rate. Typical values are 9600, 19200, 38400, 57600, 115200…
Note
See getBaudrate()
- setBytesize(self, bytesize: visp._visp.core.Serial.bytesize_t) None ¶
- setFlowcontrol(self, flowcontrol: visp._visp.core.Serial.flowcontrol_t) None ¶
- setParity(self, parity: visp._visp.core.Serial.parity_t) None ¶
- setPort(self, port: str) None ¶
Set the serial port name. The name is a string similar to /dev/ttyUSB0 , /dev/ttySO , /dev/ttyAMA0 …
#include <visp3/core/vpSerial.h> int main() { #ifndef WIN32 vpSerial serial; serial.setPort("/dev/ttyUSB0"); serial.open(); #endif }
Note
See getPort()
- setStopbits(self, stopbits: visp._visp.core.Serial.stopbits_t) None ¶