Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions canopen/pdo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ def __init__(self, pdo_node, com_record, map_array):
self._task = None

def __repr__(self) -> str:
return f"<{type(self).__qualname__} {self.name!r} at COB-ID 0x{self.cob_id:X}>"
cob = f"0x{self.cob_id:X}" if self.cob_id is not None else "Unassigned"
return f"<{type(self).__qualname__} {self.name!r} at COB-ID {cob}>"

def __getitem_by_index(self, value):
valid_values = []
Expand Down Expand Up @@ -492,7 +493,7 @@ def subscribe(self) -> None:
associated with read() or save(), if the local PDO setup is
known to match what's stored on the node.
"""
if self.enabled:
if self.enabled and self.cob_id is not None:
logger.info("Subscribing to enabled PDO 0x%X on the network", self.cob_id)
self.pdo_node.network.subscribe(self.cob_id, self.on_message)

Expand Down Expand Up @@ -540,6 +541,8 @@ def add_variable(

def transmit(self) -> None:
"""Transmit the message once."""
if self.cob_id is None:
raise ValueError("A valid COB-ID has not been configured")
self.pdo_node.network.send_message(self.cob_id, self.data)

def start(self, period: Optional[float] = None) -> None:
Expand All @@ -559,6 +562,8 @@ def start(self, period: Optional[float] = None) -> None:

if not self.period:
raise ValueError("A valid transmission period has not been given")
if self.cob_id is None:
raise ValueError("A valid COB-ID has not been configured")
logger.info("Starting %s with a period of %s seconds", self.name, self.period)

self._task = self.pdo_node.network.send_periodic(
Expand All @@ -579,7 +584,7 @@ def remote_request(self) -> None:
"""Send a remote request for the transmit PDO.
Silently ignore if not allowed.
"""
if self.enabled and self.rtr_allowed:
if self.enabled and self.rtr_allowed and self.cob_id is not None:
self.pdo_node.network.send_message(self.cob_id, bytes(), remote=True)

def wait_for_reception(self, timeout: float = 10) -> float:
Expand Down