Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 17 additions & 7 deletions canopen/pdo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@


class PDO(PdoBase):
"""PDO Class for backwards compatibility
"""PDO Class for backwards compatibility.

:param rpdo: RPDO object holding the Receive PDO mappings
:param tpdo: TPDO object holding the Transmit PDO mappings
"""
Expand All @@ -27,9 +28,11 @@ def __init__(self, node, rpdo, tpdo):


class RPDO(PdoBase):
"""PDO specialization for the Receive PDO enabling the transfer of data from the master to the node.
"""Receive PDO to transfer data from somewhere to the represented node.

Properties 0x1400 to 0x1403 | Mapping 0x1600 to 0x1603.
:param object node: Parent node for this object."""
:param object node: Parent node for this object.
"""

def __init__(self, node):
super(RPDO, self).__init__(node)
Expand All @@ -38,8 +41,10 @@ def __init__(self, node):

def stop(self):
"""Stop transmission of all RPDOs.

:raise TypeError: Exception is thrown if the node associated with the PDO does not
support this function"""
support this function.
"""
if isinstance(self.node, canopen.RemoteNode):
for pdo in self.map.values():
pdo.stop()
Expand All @@ -48,8 +53,11 @@ def stop(self):


class TPDO(PdoBase):
"""PDO specialization for the Transmit PDO enabling the transfer of data from the node to the master.
Properties 0x1800 to 0x1803 | Mapping 0x1A00 to 0x1A03."""
"""Transmit PDO to broadcast data from the represented node to the network.

Properties 0x1800 to 0x1803 | Mapping 0x1A00 to 0x1A03.
:param object node: Parent node for this object.
"""

def __init__(self, node):
super(TPDO, self).__init__(node)
Expand All @@ -58,8 +66,10 @@ def __init__(self, node):

def stop(self):
"""Stop transmission of all TPDOs.

:raise TypeError: Exception is thrown if the node associated with the PDO does not
support this function"""
support this function.
"""
if isinstance(canopen.LocalNode, self.node):
for pdo in self.map.values():
pdo.stop()
Expand Down
26 changes: 23 additions & 3 deletions canopen/pdo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ def save(self):
for pdo_map in self.map.values():
pdo_map.save()

def subscribe(self):
"""Register the node's PDOs for reception on the network.

This normally happens when the PDO configuration is read from
or saved to the node. Use this method to avoid the SDO flood
associated with read() or save(), if the local PDO setup is
known to match what's stored on the node.
"""
for pdo_map in self.map.values():
pdo_map.subscribe()

def export(self, filename):
"""Export current configuration to a database file.

Expand Down Expand Up @@ -331,8 +342,7 @@ def read(self):
if index and size:
self.add_variable(index, subindex, size)

if self.enabled:
self.pdo_node.network.subscribe(self.cob_id, self.on_message)
self.subscribe()

def save(self):
"""Save PDO configuration for this map using SDO."""
Expand Down Expand Up @@ -387,9 +397,19 @@ def save(self):
self._update_data_size()

if self.enabled:
logger.info("Enabling PDO")
self.com_record[1].raw = self.cob_id | (RTR_NOT_ALLOWED if not self.rtr_allowed else 0x0)
self.subscribe()

def subscribe(self):
"""Register the PDO for reception on the network.

This normally happens when the PDO configuration is read from
or saved to the node. Use this method to avoid the SDO flood
associated with read() or save(), if the local PDO setup is
known to match what's stored on the node.
"""
if self.enabled:
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)

def clear(self):
Expand Down