def decode_string(self, string): # look for true/false keywords if str.lower(string).strip() == "true": return True elif str.lower(string).strip() == "false": return False # try to interprete as integer number num_value = parseIntAutoBase(string) if num_value is None: # interpretation failed return None else: return num_value != 0 # c interpretation of bool
def decode_string(self, string): # look for true/false keywords if str.lower(string).strip() == "true": return True elif str.lower(string).strip() == "false": return False # try to interprete as integer number num_value = parseIntAutoBase(string) if num_value is None: # interpretation failed return None else: return num_value != 0 # c interpretation of bool
def __init__(self, config_parser, section): super(EdsObjectList, self).__init__() # get section from eds file dictionary = get_section(config_parser,section) # retrieve number of objects and then read objects self.num_objects = int(dictionary["SupportedObjects"]) self.object_ids = list() self.objects = dict() # read objects for k in range(1,self.num_objects+1): object_id = parseIntAutoBase(dictionary[str(k)]) self.object_ids.append(object_id) self.objects[object_id] = EdsObject(config_parser,object_id)
def __init__(self, config_parser, index, subindex = 0): super(EdsObject, self).__init__() object_id_str = str.upper(hex(index)[2:]) if subindex > 0: object_id_str += "sub" + str.upper(hex(subindex)[2:]) dictionary = get_section(config_parser,object_id_str) self.index = index self.subindex = subindex self.parameter_name = dictionary["ParameterName"] if dictionary["ObjectType"] is None: # Missing ObjectType equals ObjectType VAR. (306_v01030000.pdf pg. 15) self.object_type = CanOpenObjectType.var else: self.object_type = parseIntAutoBase(dictionary["ObjectType"]) self.object_type = CanOpenObjectType(self.object_type) if dictionary["ObjFlags"] is None: self.obj_flags = 0 else: self.obj_flags = dictionary["ObjFlags"] # object types: (301_v04020005_cor3.pdf pg. 89) # 0x00: null - object with no data fields # 0x01: null - object with no data fields if self.object_type == CanOpenObjectType.var: # var type self.datatype = parseIntAutoBase(dictionary["DataType"]) self.access_type = dictionary["AccessType"] # todo map access_type string to CanOpenObjectAttribute # 306_v01030000.pdf pg. 15 # AccessType for this object, represented by the following strings ( „ro“ - read only, „wo“ - # write only, „rw“ - read/write, „rwr“ - read/write on process input, „rww“ - # read/write on process output, „const“ - constant value) if dictionary["DefaultValue"] is None: self.default_value = None elif CanOpenBasicDatatypes(self.datatype) == CanOpenBasicDatatypes.vis_str: self.default_value = dictionary["DefaultValue"] elif CanOpenBasicDatatypes(self.datatype) in [CanOpenBasicDatatypes.boolean, CanOpenBasicDatatypes.int8, CanOpenBasicDatatypes.int16, CanOpenBasicDatatypes.int32, CanOpenBasicDatatypes.uint8, CanOpenBasicDatatypes.uint16, CanOpenBasicDatatypes.uint32]: if "$NODEID" in str.upper(dictionary["DefaultValue"]): self.default_value = dictionary["DefaultValue"] # todo parse this else: self.default_value = parseIntAutoBase(dictionary["DefaultValue"]) elif CanOpenBasicDatatypes(self.datatype) == CanOpenBasicDatatypes.float32: self.default_value = float(dictionary["DefaultValue"]) self.low_limit = parseIntAutoBase(dictionary["LowLimit"]) self.high_limit = parseIntAutoBase(dictionary["HighLimit"]) self.pdo_mapping = dictionary["PDOMapping"] == "1" elif self.object_type in [CanOpenObjectType.array, CanOpenObjectType.record]: # array or record type # determine number of sub objects self.sub_number = int(dictionary["SubNumber"]) self.sub_objects = list() # read sub objects for k in range(1,self.sub_number): self.sub_objects.append(EdsObject(config_parser, self.index, k))
def decode_string(self, string): # default implementation tries to interprete as integer number return parseIntAutoBase(string)
def decode_string(self, string): # default implementation tries to interprete as integer number return parseIntAutoBase(string)