Skip to content

Commit

Permalink
Mirror some OD access API to the SdoBase / SdoVariable classes. (chri…
Browse files Browse the repository at this point in the history
  • Loading branch information
acolomb authored Apr 25, 2024
1 parent a973919 commit dc8a4ca
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion canopen/sdo/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import binascii
from typing import Iterable, Union
from typing import Iterable, Optional, Union
try:
from collections.abc import Mapping
except ImportError:
Expand Down Expand Up @@ -67,6 +67,19 @@ def __len__(self) -> int:
def __contains__(self, key: Union[int, str]) -> bool:
return key in self.od

def get_variable(
self, index: Union[int, str], subindex: int = 0
) -> Optional["SdoVariable"]:
"""Get the variable object at specified index (and subindex if applicable).
:return: SdoVariable if found, else `None`
"""
obj = self.get(index)
if isinstance(obj, SdoVariable):
return obj
elif isinstance(obj, (SdoRecord, SdoArray)):
return obj.get(subindex)

def upload(self, index: int, subindex: int) -> bytes:
raise NotImplementedError()

Expand Down Expand Up @@ -132,6 +145,14 @@ def set_data(self, data: bytes):
force_segment = self.od.data_type == objectdictionary.DOMAIN
self.sdo_node.download(self.od.index, self.od.subindex, data, force_segment)

@property
def writable(self) -> bool:
return self.od.writable

@property
def readable(self) -> bool:
return self.od.readable

def open(self, mode="rb", encoding="ascii", buffering=1024, size=None,
block_transfer=False, request_crc_support=True):
"""Open the data stream as a file like object.
Expand Down

0 comments on commit dc8a4ca

Please sign in to comment.