def __findMotor(self, start=0, end=10, found=False): ''' Scans to see if a motor is connected and to which address. Writes the same message to different addresses, if it receives a reply it returns True. It also saves the address every time a motor is found in a list and each address can be summoned with a definition found below. ''' BYTESIZE = 19 ADDRESREGISTER = 156 # MOTOR_TYPE=153 # SERIAL_NBR = 154 data = [] self.addr = dict() if self.port.isOpen() == False: self.port.open() try: for j in range(start, end): address = translations.createcommand_read( j, ADDRESREGISTER ) #ADDRESREGISTER)# SERIAL_NBR) #MOTOR_TYPE)#) self.port.write(address.decode('hex')) for k in range(BYTESIZE): byte = self.port.read() data.append(k) data[k] = byte.encode('hex') try: values = [data[9], data[11]] decim = translations.hextodec(values) if decim == 1: found = True if 'motor' in self.addr: self.addr.append(j) else: self.addr['motor'] = j print 'Motor found on address ' + str( j) + ' decim: %s' % decim, ' values: %s' % values except: print 'No motor on address ' + str(j) finally: self.port.close() return found
def read(self, address, parameter): ''' Asks the motor to give information concerning a parameter, if there is a response, the value will be printed otherwise an error will be raised. :param address: The address of the motor, defined in __init__. :param parameter: The parameter which is being read. :raises: Raises if the motor doesn't respond, check the message sent or the connection with the motor. ''' BYTESIZE = 19 message = translations.createcommand_read(address, parameter) values = self.sendmessage(message, BYTESIZE, True) if values == None: raise ValueError('Values is empty, check connection with motor') return values
def __findMotor(self, start =0, end=10, found = False): ''' Scans to see if a motor is connected and to which address. Writes the same message to different addresses, if it receives a reply it returns True. It also saves the address every time a motor is found in a list and each address can be summoned with a definition found below. ''' BYTESIZE = 19 ADDRESREGISTER = 156 # MOTOR_TYPE=153 # SERIAL_NBR = 154 data = [] self.addr = dict() if self.port.isOpen()==False: self.port.open() try: for j in range(start,end): address = translations.createcommand_read(j, ADDRESREGISTER) #ADDRESREGISTER)# SERIAL_NBR) #MOTOR_TYPE)#) self.port.write(address.decode('hex')) for k in range(BYTESIZE): byte = self.port.read() data.append(k) data[k] = byte.encode('hex') try: values = [data[9],data[11]] decim = translations.hextodec(values) if decim == 1: found = True if 'motor' in self.addr: self.addr.append(j) else: self.addr['motor'] = j print 'Motor found on address ' + str(j)+ ' decim: %s'%decim, ' values: %s'%values except: print 'No motor on address ' + str(j) finally: self.port.close() return found