2626
2727
2828def 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+ """
2937 if filename .endswith (".eds" ):
3038 from . import eds
3139 return eds .import_eds (filename )
@@ -35,18 +43,19 @@ def import_od(filename):
3543
3644
3745class ObjectDictionary (collections .Mapping ):
46+ """Representation of the object dictionary as a Python dictionary."""
3847
3948 def __init__ (self ):
4049 self .indexes = collections .OrderedDict ()
4150 self .names = collections .OrderedDict ()
51+ #: Default bitrate if specified by file
4252 self .bitrate = None
4353
4454 def __getitem__ (self , index ):
45- """Get Object Dictionary index."""
55+ """Get object from object dictionary by name or index."""
4656 return self .names .get (index ) or self .indexes [index ]
4757
4858 def __iter__ (self ):
49- """Iterates over all Object Dictionary indexes."""
5059 return iter (self .names )
5160
5261 def __len__ (self ):
@@ -56,14 +65,26 @@ def __contains__(self, index):
5665 return index in self .names or index in self .indexes
5766
5867 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+ """
5976 obj .parent = self
6077 self .indexes [obj .index ] = obj
6178 self .names [obj .name ] = obj
6279
6380
6481class Record (collections .Mapping ):
82+ """Groups multiple :class:`canopen.objectdictionary.Variable` objects using
83+ subindexes.
84+ """
6585
6686 def __init__ (self , name , index ):
87+ #: The :class:`canopen.ObjectDictionary` owning the record.
6788 self .parent = None
6889 self .index = index
6990 self .name = name
@@ -86,22 +107,31 @@ def __eq__(self, other):
86107 return self .index == other .index
87108
88109 def add_member (self , variable ):
110+ """Adds a :class:`canopen.objectdictionary.Variable` to the record."""
89111 variable .parent = self
90112 self .subindexes [variable .subindex ] = variable
91113 self .names [variable .name ] = variable
92114
93115
94116class 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+ """
95122
96123 def __init__ (self , name , index ):
124+ #: The :class:`canopen.ObjectDictionary` owning the array.
97125 self .parent = None
98126 self .index = index
99127 self .name = name
100128 self .length = 255
129+ #: Variable to read to get length of array
101130 self .last_subindex = Variable (
102131 "Number of entries" , index , 0 )
103132 self .last_subindex .data_type = UNSIGNED8
104133 self .last_subindex .parent = self
134+ #: Each variable will be based on this with unique subindexes
105135 self .template = None
106136
107137 def __getitem__ (self , subindex ):
@@ -122,7 +152,7 @@ def __len__(self):
122152
123153
124154class Variable (object ):
125- """Object Dictionary VAR ."""
155+ """Simple variable ."""
126156
127157 STRUCT_TYPES = {
128158 BOOLEAN : struct .Struct ("?" ),
@@ -139,16 +169,29 @@ class Variable(object):
139169 }
140170
141171 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
142175 self .parent = None
176+ #: 16-bit address of the object in the dictionary
143177 self .index = index
178+ #: 8-bit sub-index of the object in the dictionary
144179 self .subindex = subindex
180+ #: String representation of the variable
145181 self .name = name
182+ #: Data type according to the standard as an :class:`int`
146183 self .data_type = UNSIGNED32
184+ #: Access type, should be "rw", "ro", "wo", or "const"
147185 self .access_type = "rw"
186+ #: Physical unit
148187 self .unit = ""
188+ #: Factor between physical unit and integer value
149189 self .factor = 1
190+ #: Minimum allowed value
150191 self .min = None
192+ #: Maximum allowed value
151193 self .max = None
194+ #: Dictionary of value descriptions
152195 self .value_descriptions = {}
153196 self .bit_definitions = {}
154197
0 commit comments