66from configparser import NoOptionError , NoSectionError , RawConfigParser
77from typing import TYPE_CHECKING
88
9- from canopen import objectdictionary
10- from canopen .objectdictionary import ObjectDictionary , datatypes
9+ from canopen .objectdictionary import (
10+ ODArray ,
11+ ODRecord ,
12+ ODVariable ,
13+ ObjectDictionary ,
14+ datatypes ,
15+ )
1116from canopen .sdo import SdoClient
1217
1318if TYPE_CHECKING :
@@ -107,7 +112,7 @@ def import_eds(source, node_id):
107112 for i in range (1 , 8 ):
108113 key = f"Dummy{ i :04d} "
109114 if eds .getint (section , key ) == 1 :
110- var = objectdictionary . ODVariable (key , i , 0 )
115+ var = ODVariable (key , i , 0 )
111116 var .data_type = i
112117 var .access_type = "const"
113118 od .add_object (var )
@@ -133,20 +138,20 @@ def import_eds(source, node_id):
133138 var = build_variable (eds , section , node_id , index )
134139 od .add_object (var )
135140 elif object_type == ARR and eds .has_option (section , "CompactSubObj" ):
136- arr = objectdictionary . ODArray (name , index )
137- last_subindex = objectdictionary . ODVariable (
141+ arr = ODArray (name , index )
142+ last_subindex = ODVariable (
138143 "Number of entries" , index , 0 )
139144 last_subindex .data_type = datatypes .UNSIGNED8
140145 arr .add_member (last_subindex )
141146 arr .add_member (build_variable (eds , section , node_id , index , 1 ))
142147 arr .storage_location = storage_location
143148 od .add_object (arr )
144149 elif object_type == ARR :
145- arr = objectdictionary . ODArray (name , index )
150+ arr = ODArray (name , index )
146151 arr .storage_location = storage_location
147152 od .add_object (arr )
148153 elif object_type == RECORD :
149- record = objectdictionary . ODRecord (name , index )
154+ record = ODRecord (name , index )
150155 record .storage_location = storage_location
151156 od .add_object (record )
152157
@@ -158,8 +163,7 @@ def import_eds(source, node_id):
158163 index = int (match .group (1 ), 16 )
159164 subindex = int (match .group (2 ), 16 )
160165 entry = od [index ]
161- if isinstance (entry , (objectdictionary .ODRecord ,
162- objectdictionary .ODArray )):
166+ if isinstance (entry , (ODRecord , ODArray )):
163167 var = build_variable (eds , section , node_id , index , subindex )
164168 entry .add_member (var )
165169
@@ -263,7 +267,7 @@ def build_variable(eds, section, node_id, index, subindex=0):
263267 :param subindex: Subindex of the CANOpen object (if presente, else 0)
264268 """
265269 name = eds .get (section , "ParameterName" )
266- var = objectdictionary . ODVariable (name , index , subindex )
270+ var = ODVariable (name , index , subindex )
267271 try :
268272 var .storage_location = eds .get (section , "StorageLocation" )
269273 except NoOptionError :
@@ -350,11 +354,11 @@ def export_dcf(od, dest=None, fileInfo={}):
350354
351355def export_eds (od , dest = None , file_info = {}, device_commisioning = False ):
352356 def export_object (obj , eds ):
353- if isinstance (obj , objectdictionary . ODVariable ):
357+ if isinstance (obj , ODVariable ):
354358 return export_variable (obj , eds )
355- if isinstance (obj , objectdictionary . ODRecord ):
359+ if isinstance (obj , ODRecord ):
356360 return export_record (obj , eds )
357- if isinstance (obj , objectdictionary . ODArray ):
361+ if isinstance (obj , ODArray ):
358362 return export_array (obj , eds )
359363
360364 def export_common (var , eds , section ):
@@ -410,7 +414,7 @@ def export_record(var, eds):
410414 section = f"{ var .index :04X} "
411415 export_common (var , eds , section )
412416 eds .set (section , "SubNumber" , f"0x{ len (var .subindices ):X} " )
413- ot = RECORD if isinstance (var , objectdictionary . ODRecord ) else ARR
417+ ot = RECORD if isinstance (var , ODRecord ) else ARR
414418 eds .set (section , "ObjectType" , f"0x{ ot :X} " )
415419 for i in var :
416420 export_variable (var [i ], eds )
0 commit comments