basic_robotics.interfaces.comms_core module

Implement communications from Basic-Robotics to UDP, TCP, and Serial connections.

This is a basic implementation of these communications systems, and byte packing and more advanced features are not included. Also not included are any sort of multithreaded capabilities. Users who desire to use such capabilities would be best off performing their own implementations or extending these classes.

class basic_robotics.interfaces.comms_core.Comms[source]

Bases: object

Communications wrapper class for multiple communications objects.

__init__() → Comms[source]

Create an empty communications object.

Returns:

Communications – new communications object

newComPort(name: str, type: str, *args, **kwargs) → None[source]

Create a new named comm port and adds it to the register.

Parameters:
  • name – String - name to identify new port

  • type – String - type of port “UDP” or “Serial”

  • args – Optional - List of arguments specific to comm port

getCom(name: str) → CommsObject[source]

Return a reference to a specified CommsObject.

Parameters:

name (str) – Desired Comms Object

Returns:

CommsObject – Desired Comms Object

openAll() → None[source]

Open All Com Ports.

closeAll() → None[source]

Close ALl Com Ports.

openCom(name: str) → None[source]

Open a specified Communications line.

Parameters:

name (str) – CommsObject name

Returns:

bool – Success of Opening the Channel

closeCom(name: str) → bool[source]

Close a specified Communications line.

Parameters:

name (str) – CommsObject name.

Returns:

bool – Success of Closing the Channel

setDataSource(output_name: str, input_handle) → bool[source]

Set a function that produces a compatible data output as an automatic message source.

Do not bind a function to both a data input and a data output. :param output_name: data sender to use. :type output_name: str :param input_handle: input handle to use. Must produce one output. :type input_handle: Any

Returns:

bool – Success on binding function.

setDataSink(input_name: str, output_handle) → bool[source]

Set an output function for received data to automatically populate.

Do not bind a function to both a data input and a data output. :param input_name: Name of input data handle. :type input_name: str :param output_handle: function to be called. Must take only one argument. :type output_handle: Any

Returns:

bool – Success with binding data output

deleteForwardingRule(input_name: str, output_name: str) → bool[source]

Delete a previously established forwarding rule.

Parameters:
  • input_name (str) – receiving com object

  • output_name (str) – destination com object

Returns:

bool – success in removing a forwarding rule.

setForwardData(input_name: str, output_name: str) → bool[source]

Set a forwarding rule, from one com object to another.

If data is pulled from one com_port that is linked to another, then the data will be automatically sent to the next com port.

Parameters:
  • input_name (str) – receiving com object

  • output_name (str) – destination com object

Returns:

bool – Success in establishing forwarding rule.

spin(spin_iterations=-1)[source]

Spin the communications instance, executing all forwarding rules, input and output functions.

if spin_iterations < 0, will spin infinitely. :param spin_iterations: spin iterations. Defaults to -1. :type spin_iterations: int, optional

sendData(name, data)[source]

Send data from a comm port with a specific name.

Parameters:
  • name – String - unique name of comm port

  • message – Data to send

getData(name)[source]

Receives data from a comm port with a specific name.

Parameters:

name – String - unique name of comm port

Returns:

data – Retrieved data success: Whether it was able to retrieve anything at all