26
26
27
27
28
28
def import_od (filename ):
29
+ """Parse an EDS or EPF file.
30
+
31
+ :param str filename:
32
+ Path to object dictionary file.
33
+
34
+ :return:
35
+ A :class:`canopen.ObjectDictionary` object.
36
+ """
29
37
if filename .endswith (".eds" ):
30
38
from . import eds
31
39
return eds .import_eds (filename )
@@ -35,18 +43,19 @@ def import_od(filename):
35
43
36
44
37
45
class ObjectDictionary (collections .Mapping ):
46
+ """Representation of the object dictionary as a Python dictionary."""
38
47
39
48
def __init__ (self ):
40
49
self .indexes = collections .OrderedDict ()
41
50
self .names = collections .OrderedDict ()
51
+ #: Default bitrate if specified by file
42
52
self .bitrate = None
43
53
44
54
def __getitem__ (self , index ):
45
- """Get Object Dictionary index."""
55
+ """Get object from object dictionary by name or index."""
46
56
return self .names .get (index ) or self .indexes [index ]
47
57
48
58
def __iter__ (self ):
49
- """Iterates over all Object Dictionary indexes."""
50
59
return iter (self .names )
51
60
52
61
def __len__ (self ):
@@ -56,14 +65,26 @@ def __contains__(self, index):
56
65
return index in self .names or index in self .indexes
57
66
58
67
def add_object (self , obj ):
68
+ """Add object to the object dictionary.
69
+
70
+ :param obj:
71
+ Should be either one of
72
+ :class:`canopen.objectdictionary.Variable`,
73
+ :class:`canopen.objectdictionary.Record`, or
74
+ :class:`canopen.objectdictionary.Array`.
75
+ """
59
76
obj .parent = self
60
77
self .indexes [obj .index ] = obj
61
78
self .names [obj .name ] = obj
62
79
63
80
64
81
class Record (collections .Mapping ):
82
+ """Groups multiple :class:`canopen.objectdictionary.Variable` objects using
83
+ subindexes.
84
+ """
65
85
66
86
def __init__ (self , name , index ):
87
+ #: The :class:`canopen.ObjectDictionary` owning the record.
67
88
self .parent = None
68
89
self .index = index
69
90
self .name = name
@@ -86,22 +107,31 @@ def __eq__(self, other):
86
107
return self .index == other .index
87
108
88
109
def add_member (self , variable ):
110
+ """Adds a :class:`canopen.objectdictionary.Variable` to the record."""
89
111
variable .parent = self
90
112
self .subindexes [variable .subindex ] = variable
91
113
self .names [variable .name ] = variable
92
114
93
115
94
116
class Array (collections .Sequence ):
117
+ """An array of :class:`canopen.objectdictionary.Variable` objects using
118
+ subindexes.
119
+
120
+ Actual length of array must be read from the node using SDO.
121
+ """
95
122
96
123
def __init__ (self , name , index ):
124
+ #: The :class:`canopen.ObjectDictionary` owning the array.
97
125
self .parent = None
98
126
self .index = index
99
127
self .name = name
100
128
self .length = 255
129
+ #: Variable to read to get length of array
101
130
self .last_subindex = Variable (
102
131
"Number of entries" , index , 0 )
103
132
self .last_subindex .data_type = UNSIGNED8
104
133
self .last_subindex .parent = self
134
+ #: Each variable will be based on this with unique subindexes
105
135
self .template = None
106
136
107
137
def __getitem__ (self , subindex ):
@@ -122,7 +152,7 @@ def __len__(self):
122
152
123
153
124
154
class Variable (object ):
125
- """Object Dictionary VAR ."""
155
+ """Simple variable ."""
126
156
127
157
STRUCT_TYPES = {
128
158
BOOLEAN : struct .Struct ("?" ),
@@ -139,16 +169,29 @@ class Variable(object):
139
169
}
140
170
141
171
def __init__ (self , name , index , subindex = 0 ):
172
+ #: The :class:`canopen.ObjectDictionary`,
173
+ #: :class:`canopen.objectdictionary.Record` or
174
+ #: :class:`canopen.objectdictionary.Array` owning the variable
142
175
self .parent = None
176
+ #: 16-bit address of the object in the dictionary
143
177
self .index = index
178
+ #: 8-bit sub-index of the object in the dictionary
144
179
self .subindex = subindex
180
+ #: String representation of the variable
145
181
self .name = name
182
+ #: Data type according to the standard as an :class:`int`
146
183
self .data_type = UNSIGNED32
184
+ #: Access type, should be "rw", "ro", "wo", or "const"
147
185
self .access_type = "rw"
186
+ #: Physical unit
148
187
self .unit = ""
188
+ #: Factor between physical unit and integer value
149
189
self .factor = 1
190
+ #: Minimum allowed value
150
191
self .min = None
192
+ #: Maximum allowed value
151
193
self .max = None
194
+ #: Dictionary of value descriptions
152
195
self .value_descriptions = {}
153
196
self .bit_definitions = {}
154
197
0 commit comments