22import logging
33import re
44
5- from canopen .objectdictionary import datatypes
6-
75try :
86 from configparser import RawConfigParser , NoOptionError , NoSectionError
97except ImportError :
108 from ConfigParser import RawConfigParser , NoOptionError , NoSectionError
9+
1110from canopen import objectdictionary
11+ from canopen .objectdictionary import ObjectDictionary , datatypes
1212from canopen .sdo import SdoClient
1313
1414logger = logging .getLogger (__name__ )
@@ -38,7 +38,7 @@ def import_eds(source, node_id):
3838 if not hasattr (source , "read" ):
3939 fp .close ()
4040
41- od = objectdictionary . ObjectDictionary ()
41+ od = ObjectDictionary ()
4242
4343 if eds .has_section ("FileInfo" ):
4444 od .__edsFileInfo = {
@@ -130,7 +130,7 @@ def import_eds(source, node_id):
130130 arr = objectdictionary .Array (name , index )
131131 last_subindex = objectdictionary .Variable (
132132 "Number of entries" , index , 0 )
133- last_subindex .data_type = objectdictionary .UNSIGNED8
133+ last_subindex .data_type = datatypes .UNSIGNED8
134134 arr .add_member (last_subindex )
135135 arr .add_member (build_variable (eds , section , node_id , index , 1 ))
136136 arr .storage_location = storage_location
@@ -179,7 +179,7 @@ def import_from_node(node_id, network):
179179 :param network: network object
180180 """
181181 # Create temporary SDO client
182- sdo_client = SdoClient (0x600 + node_id , 0x580 + node_id , objectdictionary . ObjectDictionary ())
182+ sdo_client = SdoClient (0x600 + node_id , 0x580 + node_id , ObjectDictionary ())
183183 sdo_client .network = network
184184 # Subscribe to SDO responses
185185 network .subscribe (0x580 + node_id , sdo_client .on_response )
@@ -219,11 +219,11 @@ def _signed_int_from_hex(hex_str, bit_length):
219219
220220
221221def _convert_variable (node_id , var_type , value ):
222- if var_type in (objectdictionary .OCTET_STRING , objectdictionary .DOMAIN ):
222+ if var_type in (datatypes .OCTET_STRING , datatypes .DOMAIN ):
223223 return bytes .fromhex (value )
224- elif var_type in (objectdictionary .VISIBLE_STRING , objectdictionary .UNICODE_STRING ):
224+ elif var_type in (datatypes .VISIBLE_STRING , datatypes .UNICODE_STRING ):
225225 return value
226- elif var_type in objectdictionary .FLOAT_TYPES :
226+ elif var_type in datatypes .FLOAT_TYPES :
227227 return float (value )
228228 else :
229229 # COB-ID can contain '$NODEID+' so replace this with node_id before converting
@@ -237,11 +237,11 @@ def _convert_variable(node_id, var_type, value):
237237def _revert_variable (var_type , value ):
238238 if value is None :
239239 return None
240- if var_type in (objectdictionary .OCTET_STRING , objectdictionary .DOMAIN ):
240+ if var_type in (datatypes .OCTET_STRING , datatypes .DOMAIN ):
241241 return bytes .hex (value )
242- elif var_type in (objectdictionary .VISIBLE_STRING , objectdictionary .UNICODE_STRING ):
242+ elif var_type in (datatypes .VISIBLE_STRING , datatypes .UNICODE_STRING ):
243243 return value
244- elif var_type in objectdictionary .FLOAT_TYPES :
244+ elif var_type in datatypes .FLOAT_TYPES :
245245 return value
246246 else :
247247 return "0x%02X" % value
@@ -273,14 +273,14 @@ def build_variable(eds, section, node_id, index, subindex=0):
273273 except NoSectionError :
274274 logger .warning ("%s has an unknown or unsupported data type (%X)" , name , var .data_type )
275275 # Assume DOMAIN to force application to interpret the byte data
276- var .data_type = objectdictionary .DOMAIN
276+ var .data_type = datatypes .DOMAIN
277277
278278 var .pdo_mappable = bool (int (eds .get (section , "PDOMapping" , fallback = "0" ), 0 ))
279279
280280 if eds .has_option (section , "LowLimit" ):
281281 try :
282282 min_string = eds .get (section , "LowLimit" )
283- if var .data_type in objectdictionary .SIGNED_TYPES :
283+ if var .data_type in datatypes .SIGNED_TYPES :
284284 var .min = _signed_int_from_hex (min_string , _calc_bit_length (var .data_type ))
285285 else :
286286 var .min = int (min_string , 0 )
@@ -289,7 +289,7 @@ def build_variable(eds, section, node_id, index, subindex=0):
289289 if eds .has_option (section , "HighLimit" ):
290290 try :
291291 max_string = eds .get (section , "HighLimit" )
292- if var .data_type in objectdictionary .SIGNED_TYPES :
292+ if var .data_type in datatypes .SIGNED_TYPES :
293293 var .max = _signed_int_from_hex (max_string , _calc_bit_length (var .data_type ))
294294 else :
295295 var .max = int (max_string , 0 )
@@ -341,7 +341,7 @@ def export_common(var, eds, section):
341341 eds .set (section , "StorageLocation" , var .storage_location )
342342
343343 def export_variable (var , eds ):
344- if isinstance (var .parent , objectdictionary . ObjectDictionary ):
344+ if isinstance (var .parent , ObjectDictionary ):
345345 # top level variable
346346 section = "%04X" % var .index
347347 else :
0 commit comments