Skip to content

Commit fc43ba6

Browse files
committed
Support RPDO / TPDO lookup by communication parameter record index.
This does not work for the generic, joined accessor class PDO yet.
1 parent e9351ec commit fc43ba6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

canopen/pdo/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ def __getitem__(self, key: Union[int, str]):
4646
raise KeyError("PDO index zero requested for 1-based sequence")
4747
if (
4848
0 < key <= 512 # By PDO Index
49-
or 0x1600 <= key <= 0x17FF # By RPDO ID (512)
50-
or 0x1A00 <= key <= 0x1BFF # By TPDO ID (512)
49+
or 0x1600 <= key <= 0x1BFF # By RPDO / TPDO mapping or communication record
5150
):
5251
return self.map[key]
5352
for pdo_map in self.map.values():
@@ -178,6 +177,8 @@ def __getitem__(self, key: int) -> PdoMap:
178177
except KeyError:
179178
with contextlib.suppress(KeyError):
180179
return self.maps[key + 1 - self.map_offset]
180+
with contextlib.suppress(KeyError):
181+
return self.maps[key + 1 - self.com_offset]
181182
raise
182183

183184
def __iter__(self) -> Iterator[int]:

test/test_pdo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def test_pdo_getitem(self):
5454
self.assertIsInstance(by_mapping_record, canopen.pdo.PdoMap)
5555
self.assertEqual(by_mapping_record['INTEGER16 value'].raw, -3)
5656
self.assertIs(node.tpdo[0x1A00], by_mapping_record)
57+
self.assertIs(node.tpdo[0x1800], by_mapping_record)
5758
by_object_name = node.pdo['INTEGER16 value']
5859
self.assertIsInstance(by_object_name, canopen.pdo.PdoVariable)
5960
self.assertIs(by_object_name.od, node.object_dictionary['INTEGER16 value'])

0 commit comments

Comments
 (0)