def _request_SPI(self, slot): self._open_connection(slot) self.spi.xfer2([ Command.ENUMERATE.value, ]) time.sleep(0.01) request = self.spi.readbytes(1) if LOOPBACK: return request time.sleep(0.01) response = [] for i in range(0, request[0]): response.append(self.spi.readbytes(1)[0]) print("Hexdump:", response) response = str(bytes(response), 'ascii') try: module = Module.create_from_string(slot, response) except (TypeError, KeyError): print("Error detecting device on slot {}".format(slot)) module = None self._close_connection() return module
def _request_SPI(self, slot): self._open_connection(slot) self.spi.xfer2([ Command.ENUMERATE.value, ]) time.sleep(0.01) request = self.spi.readbytes(1) if LOOPBACK: return request module = None retry = 0 while not module: retry += 1 time.sleep(0.01) response = [] for i in range(0, request[0]): current_byte = self.spi.readbytes(1)[0] if current_byte == b'\0': print("Zero error") current_byte = self.spi.readbytes(1)[0] response.append(current_byte) time.sleep(0.0001) response = str(bytes(response), 'ascii') try: module = Module.create_from_string(slot, response) except (TypeError, KeyError): module = None if retry > 3: print("Error detecting device on slot {}".format(slot)) print("Hexdump:", response) break self._close_connection() return module
def _request_SPI(self,slot): self._open_connection(slot) self.spi.xfer2([Command.ENUMERATE.value,]) time.sleep(0.01) request = self.spi.readbytes(1) if LOOPBACK: return request time.sleep(0.01) response = [] for i in range(0,request[0]): response.append(self.spi.readbytes(1)[0]) print("Hexdump:",response) response = str(bytes(response),'ascii') try: module = Module.create_from_string(slot,response) except (TypeError,KeyError): print("Error detecting device on slot {}".format(slot)) module = None self._close_connection() return module