def send(self, command): ''' Send a command (report) to the USB device. The method returns True if the command was sent and understood. :param command: A command in the format <key>=<value><newline>, e.g. 'red=on\n'. ''' if self._usb_transfer_type == usb_transfer_types.RAW: if not self._device_is_open(): return False data = command + '\0' * (self._device.get_packet_size() - len(command)) self._logger.debug('Sending data (%u bytes): %s', len(data), binascii.b2a_hex(data)) try: self._device.send(data) data = self._device.receive() self._logger.debug('Received data (%u bytes): %s', len(data), binascii.b2a_hex(data)) return utils.strip(data) == _ACK except IOError: return False elif self._usb_transfer_type == usb_transfer_types.CONTROL: self._device.send(command)
def poll(self): ''' Poll the device. ''' self._device.send(parser.get_challenge_request()) r = self._device.receive() self._logger.debug('\'{0}\''.format(utils.strip(r))) assert(parser.is_challenge_response(r))