|
1 | 1 | import binascii
|
2 |
| -from typing import Iterable, Union |
| 2 | +from typing import Iterable, Optional, Union |
3 | 3 | try:
|
4 | 4 | from collections.abc import Mapping
|
5 | 5 | except ImportError:
|
@@ -67,6 +67,19 @@ def __len__(self) -> int:
|
67 | 67 | def __contains__(self, key: Union[int, str]) -> bool:
|
68 | 68 | return key in self.od
|
69 | 69 |
|
| 70 | + def get_variable( |
| 71 | + self, index: Union[int, str], subindex: int = 0 |
| 72 | + ) -> Optional["SdoVariable"]: |
| 73 | + """Get the variable object at specified index (and subindex if applicable). |
| 74 | +
|
| 75 | + :return: SdoVariable if found, else `None` |
| 76 | + """ |
| 77 | + obj = self.get(index) |
| 78 | + if isinstance(obj, SdoVariable): |
| 79 | + return obj |
| 80 | + elif isinstance(obj, (SdoRecord, SdoArray)): |
| 81 | + return obj.get(subindex) |
| 82 | + |
70 | 83 | def upload(self, index: int, subindex: int) -> bytes:
|
71 | 84 | raise NotImplementedError()
|
72 | 85 |
|
@@ -132,6 +145,14 @@ def set_data(self, data: bytes):
|
132 | 145 | force_segment = self.od.data_type == objectdictionary.DOMAIN
|
133 | 146 | self.sdo_node.download(self.od.index, self.od.subindex, data, force_segment)
|
134 | 147 |
|
| 148 | + @property |
| 149 | + def writable(self) -> bool: |
| 150 | + return self.od.writable |
| 151 | + |
| 152 | + @property |
| 153 | + def readable(self) -> bool: |
| 154 | + return self.od.readable |
| 155 | + |
135 | 156 | def open(self, mode="rb", encoding="ascii", buffering=1024, size=None,
|
136 | 157 | block_transfer=False, request_crc_support=True):
|
137 | 158 | """Open the data stream as a file like object.
|
|
0 commit comments