basic_robotics.interfaces.serial_bridge module

Handle Serial Communication as a CommsObject.

class basic_robotics.interfaces.serial_bridge.SerialObject(name: str, port: str = 'COM1', baud: int = 9600)[source]

Bases: CommsObject

Create a new CommsObject that handles Serial Communication.

__init__(name: str, port: str = 'COM1', baud: int = 9600) → SerialObject[source]

Initialize a new Serial CommsObject.

Parameters:
  • name (str) – name of the object

  • port (str, optional) – port to select. Defaults to “COM1”.

  • baud (int, optional) – Baud rate. Defaults to 9600.

Returns:

SerialObject – New Serial CommsObject

openCom() → bool[source]

Open a Communications Channel.

Returns:

bool – Success of Opening the Channel

sendData(message: str) → int[source]

Send a message.

Parameters:

message – message to be sent

Returns:

int – bytes written. 0 is failure.

getData(sleeptime: float = 0.2)[source]

Receive a Message.

Parameters:

sleeptime (float, optional) – amount of time to sleep before checking for message

Returns:

Any – Message Data bool: Message Receive Success

setPort(port: str) → None[source]

Set the serial port.

Parameters:

port (str) – port to be set

setBaud(baud: int) → None[source]

Set the baud rate.

Parameters:

baud (int) – baud rate to be set

getPort() → str[source]

Return the set port.

Returns:

str – port

getBaud() → int[source]

Return the baud rate.

Returns:

int – baud