Skip to content

PCP_over_USB

PCP (Pulsar Communication Protocol) adapter for USB connections.

This class provides USB serial communication for the PCP protocol, sending messages, receiving incoming messages in a thread for asynchronous communication

Source code in pcp_api/pcp_over_usb.pyi
class PCP_over_USB:
    """
    PCP (Pulsar Communication Protocol) adapter for USB connections.

    This class provides USB serial communication for the PCP protocol, sending messages,
    receiving incoming messages in a thread for asynchronous communication
    """

    def __init__(self, port: Optional[str] = None, connect_on_init: bool = True, logger: Optional[logging.Logger] = None) -> None:
        """
        Initialize PCP over USB communication adapter.

        Args:
            port: Serial port name (e.g., 'COM3', '/dev/ttyACM0'). If None, auto-discovery is attempted.
            connect_on_init: Whether to automatically connect during initialization
            logger: Optional logger for debugging messages
        """
        ...

    def connect(self, port: Optional[str] = None) -> bool:
        """
        Establish a connection to the device.

        Args:
            port (str, optional): Serial port name. If None, uses previously set port or auto-discovery.

        Returns:
            bool: True if connection successful, False otherwise
        """
        ...

    def disconnect(self) -> None:
        """
        Disconnect from the USB serial port and stop background threads.

        Cleanly shuts down the polling thread and closes the serial connection.
        """
        ...

    def close(self) -> None:
        """
        Alias for disconnect() method.

        Provided for compatibility and explicit resource cleanup.
        """
        ...

    def setCallback(self, address: int, callback: Callable[[int, List[int]], None]) -> None:
        """
        Register a callback function for messages from a specific PCP address.

        Args:
            address: PCP address to listen for (1-16382)
            callback: Function to call when messages are received from this address.
                     Callback signature: callback(address: int, data: List[int])
        """
        ...

    def send_PCP(self, address: int, data: List[int]) -> bool:
        """
        Send a PCP message to the specified address.

        Args:
            address: Target PCP address (1-16382)
            data: List of bytes to send as message payload

        Returns:
            True if message was sent successfully, False otherwise
        """
        ...

    @staticmethod
    def get_ports() -> List[str]:
        """
        Get list of available USB serial ports from Pulsar HRI devices.

        Automatically filters serial ports to only include those manufactured
        by Pulsar HRI, which are compatible with PCP over USB.

        Returns:
            List of serial port names/paths (e.g., ['COM3', 'COM5'] on Windows
            or ['/dev/ttyACM0', '/dev/ttyACM1'] on Linux)
        """
        ...

    @staticmethod
    def get_port() -> str:
        """
        Auto-discover a single USB serial port for PCP communication.

        Attempts to automatically find a suitable serial port. If exactly one
        Pulsar HRI port is found, returns it. Otherwise, returns empty string.

        Returns:
            Serial port name if exactly one suitable port is found, empty string otherwise
        """
        ...

    @property
    def is_connected(self) -> bool:
        """
        Check if the USB connection is active.

        Returns:
            True if connected, False otherwise
        """
        ...

is_connected property

Check if the USB connection is active.

Returns:

Type Description
bool

True if connected, False otherwise

__init__(port=None, connect_on_init=True, logger=None)

Initialize PCP over USB communication adapter.

Parameters:

Name Type Description Default
port Optional[str]

Serial port name (e.g., 'COM3', '/dev/ttyACM0'). If None, auto-discovery is attempted.

None
connect_on_init bool

Whether to automatically connect during initialization

True
logger Optional[Logger]

Optional logger for debugging messages

None
Source code in pcp_api/pcp_over_usb.pyi
def __init__(self, port: Optional[str] = None, connect_on_init: bool = True, logger: Optional[logging.Logger] = None) -> None:
    """
    Initialize PCP over USB communication adapter.

    Args:
        port: Serial port name (e.g., 'COM3', '/dev/ttyACM0'). If None, auto-discovery is attempted.
        connect_on_init: Whether to automatically connect during initialization
        logger: Optional logger for debugging messages
    """
    ...

close()

Alias for disconnect() method.

Provided for compatibility and explicit resource cleanup.

Source code in pcp_api/pcp_over_usb.pyi
def close(self) -> None:
    """
    Alias for disconnect() method.

    Provided for compatibility and explicit resource cleanup.
    """
    ...

connect(port=None)

Establish a connection to the device.

Parameters:

Name Type Description Default
port str

Serial port name. If None, uses previously set port or auto-discovery.

None

Returns:

Name Type Description
bool bool

True if connection successful, False otherwise

Source code in pcp_api/pcp_over_usb.pyi
def connect(self, port: Optional[str] = None) -> bool:
    """
    Establish a connection to the device.

    Args:
        port (str, optional): Serial port name. If None, uses previously set port or auto-discovery.

    Returns:
        bool: True if connection successful, False otherwise
    """
    ...

disconnect()

Disconnect from the USB serial port and stop background threads.

Cleanly shuts down the polling thread and closes the serial connection.

Source code in pcp_api/pcp_over_usb.pyi
def disconnect(self) -> None:
    """
    Disconnect from the USB serial port and stop background threads.

    Cleanly shuts down the polling thread and closes the serial connection.
    """
    ...

get_port() staticmethod

Auto-discover a single USB serial port for PCP communication.

Attempts to automatically find a suitable serial port. If exactly one Pulsar HRI port is found, returns it. Otherwise, returns empty string.

Returns:

Type Description
str

Serial port name if exactly one suitable port is found, empty string otherwise

Source code in pcp_api/pcp_over_usb.pyi
@staticmethod
def get_port() -> str:
    """
    Auto-discover a single USB serial port for PCP communication.

    Attempts to automatically find a suitable serial port. If exactly one
    Pulsar HRI port is found, returns it. Otherwise, returns empty string.

    Returns:
        Serial port name if exactly one suitable port is found, empty string otherwise
    """
    ...

get_ports() staticmethod

Get list of available USB serial ports from Pulsar HRI devices.

Automatically filters serial ports to only include those manufactured by Pulsar HRI, which are compatible with PCP over USB.

Returns:

Type Description
List[str]

List of serial port names/paths (e.g., ['COM3', 'COM5'] on Windows

List[str]

or ['/dev/ttyACM0', '/dev/ttyACM1'] on Linux)

Source code in pcp_api/pcp_over_usb.pyi
@staticmethod
def get_ports() -> List[str]:
    """
    Get list of available USB serial ports from Pulsar HRI devices.

    Automatically filters serial ports to only include those manufactured
    by Pulsar HRI, which are compatible with PCP over USB.

    Returns:
        List of serial port names/paths (e.g., ['COM3', 'COM5'] on Windows
        or ['/dev/ttyACM0', '/dev/ttyACM1'] on Linux)
    """
    ...

send_PCP(address, data)

Send a PCP message to the specified address.

Parameters:

Name Type Description Default
address int

Target PCP address (1-16382)

required
data List[int]

List of bytes to send as message payload

required

Returns:

Type Description
bool

True if message was sent successfully, False otherwise

Source code in pcp_api/pcp_over_usb.pyi
def send_PCP(self, address: int, data: List[int]) -> bool:
    """
    Send a PCP message to the specified address.

    Args:
        address: Target PCP address (1-16382)
        data: List of bytes to send as message payload

    Returns:
        True if message was sent successfully, False otherwise
    """
    ...

setCallback(address, callback)

Register a callback function for messages from a specific PCP address.

Parameters:

Name Type Description Default
address int

PCP address to listen for (1-16382)

required
callback Callable[[int, List[int]], None]

Function to call when messages are received from this address. Callback signature: callback(address: int, data: List[int])

required
Source code in pcp_api/pcp_over_usb.pyi
def setCallback(self, address: int, callback: Callable[[int, List[int]], None]) -> None:
    """
    Register a callback function for messages from a specific PCP address.

    Args:
        address: PCP address to listen for (1-16382)
        callback: Function to call when messages are received from this address.
                 Callback signature: callback(address: int, data: List[int])
    """
    ...