1212 ODVariable ,
1313 ObjectDictionary ,
1414 datatypes ,
15+ objectcodes ,
1516)
1617from canopen .sdo import SdoClient
1718
2122
2223logger = logging .getLogger (__name__ )
2324
24- # Object type. Don't confuse with Data type
25- DOMAIN = 2
26- VAR = 7
27- ARR = 8
28- RECORD = 9
29-
30-
3125def import_eds (source , node_id ):
3226 eds = RawConfigParser (inline_comment_prefixes = (';' ,))
3327 eds .optionxform = str
@@ -128,16 +122,16 @@ def import_eds(source, node_id):
128122 # DS306 4.6.3.2 object description
129123 # If the keyword ObjectType is missing, this is regarded as
130124 # "ObjectType=0x7" (=VAR).
131- object_type = VAR
125+ object_type = objectcodes . VAR
132126 try :
133127 storage_location = eds .get (section , "StorageLocation" )
134128 except NoOptionError :
135129 storage_location = None
136130
137- if object_type in (VAR , DOMAIN ):
131+ if object_type in (objectcodes . VAR , objectcodes . DOMAIN ):
138132 var = build_variable (eds , section , node_id , index )
139133 od .add_object (var )
140- elif object_type == ARR and eds .has_option (section , "CompactSubObj" ):
134+ elif object_type == objectcodes . ARRAY and eds .has_option (section , "CompactSubObj" ):
141135 arr = ODArray (name , index )
142136 last_subindex = ODVariable (
143137 "Number of entries" , index , 0 )
@@ -146,11 +140,11 @@ def import_eds(source, node_id):
146140 arr .add_member (build_variable (eds , section , node_id , index , 1 ))
147141 arr .storage_location = storage_location
148142 od .add_object (arr )
149- elif object_type == ARR :
143+ elif object_type == objectcodes . ARRAY :
150144 arr = ODArray (name , index )
151145 arr .storage_location = storage_location
152146 od .add_object (arr )
153- elif object_type == RECORD :
147+ elif object_type == objectcodes . RECORD :
154148 record = ODRecord (name , index )
155149 record .storage_location = storage_location
156150 od .add_object (record )
@@ -376,7 +370,7 @@ def export_variable(var, eds):
376370 section = f"{ var .index :04X} sub{ var .subindex :X} "
377371
378372 export_common (var , eds , section )
379- eds .set (section , "ObjectType" , f"0x{ VAR :X} " )
373+ eds .set (section , "ObjectType" , f"0x{ objectcodes . VAR :X} " )
380374 if var .data_type :
381375 eds .set (section , "DataType" , f"0x{ var .data_type :04X} " )
382376 if var .access_type :
@@ -414,7 +408,7 @@ def export_record(var, eds):
414408 section = f"{ var .index :04X} "
415409 export_common (var , eds , section )
416410 eds .set (section , "SubNumber" , f"0x{ len (var .subindices ):X} " )
417- ot = RECORD if isinstance (var , ODRecord ) else ARR
411+ ot = objectcodes . RECORD if isinstance (var , ODRecord ) else objectcodes . ARRAY
418412 eds .set (section , "ObjectType" , f"0x{ ot :X} " )
419413 for i in var :
420414 export_variable (var [i ], eds )
0 commit comments