class Enumerator(_Value): def __init__(self): _Value.__init__(self) self.__node_id__ = '120065' def configure(self, dict): _Value.configure(self, dict) set_attribute(self, 'scale_or_enum', REQUIRED, dict) if type(self.scale_or_enum) == str: #eonvert to list of words if self.scale_or_enum[0] == '[': #self discovered self.scale_or_enum = eval(self.scale_or_enum) else: #static self.scale_or_enum = string.split(self.scale_or_enum, ';') def configuration(self): config = _Value.configuration(self) get_attribute(self, 'scale_or_enum', config, str) get_attribute(self, '__node_id__', config, str) return config def start(self): i = 0 enumeration = {} for word in self.scale_or_enum: enumeration[i] = word i += 1 self.enumeration = EnumeratedDictionary(enumeration) _Value.start(self) self.point = value.TCSValue(self.line_handler, self.parameter, self.position, self.unit_number) def get(self, skipCache=0): answer = _Value.get(self, skipCache) if self.enumeration.has_key(answer): return self.enumeration[answer] return answer def _set(self, value): if self.enumeration.has_key(value): _Value._set(self, int(self.enumeration[value])) return raise EInvalidValue(str(self.enumeration), str(value), 'not found in enumeration list')
# No exception, so we must have gotten a response, check it out. if not res: # Did not get a matching response. msglog.log('USAP', WARN, "Object:get() - Did not receive a matching response.") else: # Check to see if we got a matching and successful response. resp_startCode_value = self.resp_startCode_obj.getValue() resp_vData_value = self.resp_vData_obj.getValue() resp_crc_value = self.resp_crc_obj.getValue() # if resp_startCode_value != 0xEE or resp_crc_value != 0x0000: msglog.log('USAP', WARN, "Object:get() - Received invalid response frame with startCode = %02X and CRC = %04X." % ( resp_startCode_value, resp_crc_value )) else: # Get the USAP command resp_code_value = resp_vData_value[3:] error = resp_code_value.count('?') if error == 0: value = resp_code_value.rsplit('=', 1)[1] if command.has_key(int(value)): self.value = command[int(value)] msglog.log('USAP', INFO, "Object:get() - Got response: %s, self.value = %s" % (str(resp_code_value), str(self.value))) else: msglog.log('USAP', INFO, "Object:get() - Got invalid value as: %s" % str(value)) raise EInvalidValue('Got invalid value as: %s' % str(value)) else: msglog.log('USAP', WARN, "Object:get() - Got ERROR response code: %s" % str(resp_code_value)) raise EInvalidValue('Got ERROR response code: %s' % str(resp_code_value)) # return self.value
resp_startCode_value = self.resp_startCode_obj.getValue() resp_vData_value = self.resp_vData_obj.getValue() resp_crc_value = self.resp_crc_obj.getValue() # if resp_startCode_value != 0xEE or resp_crc_value != 0x0000: msglog.log( 'USAP', WARN, "Object:get() - Received invalid response frame with startCode = %02X and CRC = %04X." % (resp_startCode_value, resp_crc_value)) else: # Get the USAP command resp_code_value = resp_vData_value[3:] error = resp_code_value.count('?') if error == 0: value = resp_code_value.rsplit('=', 1)[1] if command.has_key(int(value)): self.value = command[int(value)] msglog.log( 'USAP', INFO, "Object:get() - Got response: %s, self.value = %s" % (str(resp_code_value), str(self.value))) else: msglog.log( 'USAP', INFO, "Object:get() - Got invalid value as: %s" % str(value)) raise EInvalidValue('Got invalid value as: %s' % str(value)) else: msglog.log( 'USAP', WARN,