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

__init__

Creates a serial port object that opens the port if the parameter is not empty.

available

Return the number of characters in the buffer.

close

Closes the serial port.

getBaudrate

Return the baud rate; 9600, 115200...

getBytesize

Return the byte size.

getFlowcontrol

Return the flow control type.

getParity

Return parity.

getPort

Return the serial port name like /dev/ttyUSB0 , /dev/ttySO , /dev/ttyAMA0 ...

getStopbits

Return number of stop bits used.

open

Open the serial port.

readline

param eol:

End of line delimiter. A typical example is "n".

setBaudrate

Set serial baud rate.

setBytesize

setFlowcontrol

setParity

setPort

Set the serial port name.

setStopbits

write

Writes a string to the serial port.

Inherited Methods

Operators

__doc__

__init__

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.

__and__(self, other: object) object
__eq__(self, other: object) bool
__ge__(self, other: object) bool
__getstate__(self) int
__gt__(self, other: object) bool
__hash__(self) int
__index__(self) int
__init__(self, value: int)
__int__(self) int
__invert__(self) object
__le__(self, other: object) bool
__lt__(self, other: object) bool
__ne__(self, other: object) bool
__or__(self, other: object) object
__rand__(self, other: object) object
__ror__(self, other: object) object
__rxor__(self, other: object) object
__setstate__(self, state: int) None
__xor__(self, other: object) object
property name : str
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.

__and__(self, other: object) object
__eq__(self, other: object) bool
__ge__(self, other: object) bool
__getstate__(self) int
__gt__(self, other: object) bool
__hash__(self) int
__index__(self) int
__init__(self, value: int)
__int__(self) int
__invert__(self) object
__le__(self, other: object) bool
__lt__(self, other: object) bool
__ne__(self, other: object) bool
__or__(self, other: object) object
__rand__(self, other: object) object
__ror__(self, other: object) object
__rxor__(self, other: object) object
__setstate__(self, state: int) None
__xor__(self, other: object) object
property name : str
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.

__and__(self, other: object) object
__eq__(self, other: object) bool
__ge__(self, other: object) bool
__getstate__(self) int
__gt__(self, other: object) bool
__hash__(self) int
__index__(self) int
__init__(self, value: int)
__int__(self) int
__invert__(self) object
__le__(self, other: object) bool
__lt__(self, other: object) bool
__ne__(self, other: object) bool
__or__(self, other: object) object
__rand__(self, other: object) object
__ror__(self, other: object) object
__rxor__(self, other: object) object
__setstate__(self, state: int) None
__xor__(self, other: object) object
property name : str
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.

__and__(self, other: object) object
__eq__(self, other: object) bool
__ge__(self, other: object) bool
__getstate__(self) int
__gt__(self, other: object) bool
__hash__(self) int
__index__(self) int
__init__(self, value: int)
__int__(self) int
__invert__(self) object
__le__(self, other: object) bool
__lt__(self, other: object) bool
__ne__(self, other: object) bool
__or__(self, other: object) object
__rand__(self, other: object) object
__ror__(self, other: object) object
__rxor__(self, other: object) object
__setstate__(self, state: int) None
__xor__(self, other: object) object
property name : str
__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.

available(self) int

Return the number of characters in the buffer.

close(self) None

Closes the serial port.

Note

See open()

getBaudrate(self) int

Return the baud rate; 9600, 115200…

Note

See setBaudrate()

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
}
readline(self, eol: str) str
Parameters:
eol: str

End of line delimiter. A typical example is “n”.

Returns:

A string containing the data that has been read.

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
write(self, s: str) None

Writes a string to the serial port.

Parameters:
s: str

The data to write.