@@ -103,7 +103,7 @@ def __init__(self):
103
103
104
104
def __getitem__ (
105
105
self , index : Union [int , str ]
106
- ) -> Union ["Array " , "Record " , "Variable " ]:
106
+ ) -> Union ["ODArray " , "ODRecord " , "ODVariable " ]:
107
107
"""Get object from object dictionary by name or index."""
108
108
item = self .names .get (index ) or self .indices .get (index )
109
109
if item is None :
@@ -112,7 +112,7 @@ def __getitem__(
112
112
return item
113
113
114
114
def __setitem__ (
115
- self , index : Union [int , str ], obj : Union ["Array " , "Record " , "Variable " ]
115
+ self , index : Union [int , str ], obj : Union ["ODArray " , "ODRecord " , "ODVariable " ]
116
116
):
117
117
assert index == obj .index or index == obj .name
118
118
self .add_object (obj )
@@ -131,35 +131,35 @@ def __len__(self) -> int:
131
131
def __contains__ (self , index : Union [int , str ]):
132
132
return index in self .names or index in self .indices
133
133
134
- def add_object (self , obj : Union ["Array " , "Record " , "Variable " ]) -> None :
134
+ def add_object (self , obj : Union ["ODArray " , "ODRecord " , "ODVariable " ]) -> None :
135
135
"""Add object to the object dictionary.
136
136
137
137
:param obj:
138
138
Should be either one of
139
- :class:`~canopen.objectdictionary.Variable `,
140
- :class:`~canopen.objectdictionary.Record `, or
141
- :class:`~canopen.objectdictionary.Array `.
139
+ :class:`~canopen.objectdictionary.ODVariable `,
140
+ :class:`~canopen.objectdictionary.ODRecord `, or
141
+ :class:`~canopen.objectdictionary.ODArray `.
142
142
"""
143
143
obj .parent = self
144
144
self .indices [obj .index ] = obj
145
145
self .names [obj .name ] = obj
146
146
147
147
def get_variable (
148
148
self , index : Union [int , str ], subindex : int = 0
149
- ) -> Optional ["Variable " ]:
149
+ ) -> Optional ["ODVariable " ]:
150
150
"""Get the variable object at specified index (and subindex if applicable).
151
151
152
- :return: Variable if found, else `None`
152
+ :return: ODVariable if found, else `None`
153
153
"""
154
154
obj = self .get (index )
155
- if isinstance (obj , Variable ):
155
+ if isinstance (obj , ODVariable ):
156
156
return obj
157
- elif isinstance (obj , (Record , Array )):
157
+ elif isinstance (obj , (ODRecord , ODArray )):
158
158
return obj .get (subindex )
159
159
160
160
161
- class Record (MutableMapping ):
162
- """Groups multiple :class:`~canopen.objectdictionary.Variable ` objects using
161
+ class ODRecord (MutableMapping ):
162
+ """Groups multiple :class:`~canopen.objectdictionary.ODVariable ` objects using
163
163
subindices.
164
164
"""
165
165
@@ -178,13 +178,13 @@ def __init__(self, name: str, index: int):
178
178
self .subindices = {}
179
179
self .names = {}
180
180
181
- def __getitem__ (self , subindex : Union [int , str ]) -> "Variable " :
181
+ def __getitem__ (self , subindex : Union [int , str ]) -> "ODVariable " :
182
182
item = self .names .get (subindex ) or self .subindices .get (subindex )
183
183
if item is None :
184
184
raise KeyError ("Subindex %s was not found" % subindex )
185
185
return item
186
186
187
- def __setitem__ (self , subindex : Union [int , str ], var : "Variable " ):
187
+ def __setitem__ (self , subindex : Union [int , str ], var : "ODVariable " ):
188
188
assert subindex == var .subindex
189
189
self .add_member (var )
190
190
@@ -202,18 +202,18 @@ def __iter__(self) -> Iterable[int]:
202
202
def __contains__ (self , subindex : Union [int , str ]) -> bool :
203
203
return subindex in self .names or subindex in self .subindices
204
204
205
- def __eq__ (self , other : "Record " ) -> bool :
205
+ def __eq__ (self , other : "ODRecord " ) -> bool :
206
206
return self .index == other .index
207
207
208
- def add_member (self , variable : "Variable " ) -> None :
209
- """Adds a :class:`~canopen.objectdictionary.Variable ` to the record."""
208
+ def add_member (self , variable : "ODVariable " ) -> None :
209
+ """Adds a :class:`~canopen.objectdictionary.ODVariable ` to the record."""
210
210
variable .parent = self
211
211
self .subindices [variable .subindex ] = variable
212
212
self .names [variable .name ] = variable
213
213
214
214
215
- class Array (Mapping ):
216
- """An array of :class:`~canopen.objectdictionary.Variable ` objects using
215
+ class ODArray (Mapping ):
216
+ """An array of :class:`~canopen.objectdictionary.ODVariable ` objects using
217
217
subindices.
218
218
219
219
Actual length of array must be read from the node using SDO.
@@ -234,7 +234,7 @@ def __init__(self, name: str, index: int):
234
234
self .subindices = {}
235
235
self .names = {}
236
236
237
- def __getitem__ (self , subindex : Union [int , str ]) -> "Variable " :
237
+ def __getitem__ (self , subindex : Union [int , str ]) -> "ODVariable " :
238
238
var = self .names .get (subindex ) or self .subindices .get (subindex )
239
239
if var is not None :
240
240
# This subindex is defined
@@ -243,7 +243,7 @@ def __getitem__(self, subindex: Union[int, str]) -> "Variable":
243
243
# Create a new variable based on first array item
244
244
template = self .subindices [1 ]
245
245
name = "%s_%x" % (template .name , subindex )
246
- var = Variable (name , self .index , subindex )
246
+ var = ODVariable (name , self .index , subindex )
247
247
var .parent = self
248
248
for attr in ("data_type" , "unit" , "factor" , "min" , "max" , "default" ,
249
249
"access_type" , "description" , "value_descriptions" ,
@@ -260,17 +260,17 @@ def __len__(self) -> int:
260
260
def __iter__ (self ) -> Iterable [int ]:
261
261
return iter (sorted (self .subindices ))
262
262
263
- def __eq__ (self , other : "Array " ) -> bool :
263
+ def __eq__ (self , other : "ODArray " ) -> bool :
264
264
return self .index == other .index
265
265
266
- def add_member (self , variable : "Variable " ) -> None :
267
- """Adds a :class:`~canopen.objectdictionary.Variable ` to the record."""
266
+ def add_member (self , variable : "ODVariable " ) -> None :
267
+ """Adds a :class:`~canopen.objectdictionary.ODVariable ` to the record."""
268
268
variable .parent = self
269
269
self .subindices [variable .subindex ] = variable
270
270
self .names [variable .name ] = variable
271
271
272
272
273
- class Variable :
273
+ class ODVariable :
274
274
"""Simple variable."""
275
275
276
276
STRUCT_TYPES = {
@@ -289,8 +289,8 @@ class Variable:
289
289
290
290
def __init__ (self , name : str , index : int , subindex : int = 0 ):
291
291
#: The :class:`~canopen.ObjectDictionary`,
292
- #: :class:`~canopen.objectdictionary.Record ` or
293
- #: :class:`~canopen.objectdictionary.Array ` owning the variable
292
+ #: :class:`~canopen.objectdictionary.ODRecord ` or
293
+ #: :class:`~canopen.objectdictionary.ODArray ` owning the variable
294
294
self .parent = None
295
295
#: 16-bit address of the object in the dictionary
296
296
self .index = index
@@ -328,7 +328,7 @@ def __init__(self, name: str, index: int, subindex: int = 0):
328
328
self .pdo_mappable = False
329
329
330
330
331
- def __eq__ (self , other : "Variable " ) -> bool :
331
+ def __eq__ (self , other : "ODVariable " ) -> bool :
332
332
return (self .index == other .index and
333
333
self .subindex == other .subindex )
334
334
@@ -486,3 +486,9 @@ def __init__(self):
486
486
487
487
class ObjectDictionaryError (Exception ):
488
488
"""Unsupported operation with the current Object Dictionary."""
489
+
490
+
491
+ # Compatibility for old names
492
+ Record = ODRecord
493
+ Array = ODArray
494
+ Variable = ODVariable
0 commit comments