def _read_usb_block(self, address):
addr1 = (address // 256) & 0xff
addr2 = address & 0xff
self.devh.controlMsg(usb.TYPE_CLASS + usb.RECIP_INTERFACE,
0x0000009,
[0xA1,addr1,addr2,0x20,0xA1,addr1,addr2,0x20],
0x0000200,
0x0000000,
1000)
data = self.devh.interruptRead(self.usb_endpoint,
self.usb_read_size, # bytes to read
int(self.timeout*1000))
return list(data)
def _write_usb(self, address, data):
addr1 = (address // 256) & 0xff
addr2 = address & 0xff
buf = [0xA2,addr1,addr2,0x20,0xA2,data,0,0x20]
result = self.devh.controlMsg(
usb.ENDPOINT_OUT + usb.TYPE_CLASS + usb.RECIP_INTERFACE,
usb.REQ_SET_CONFIGURATION, # 0x09
buf,
value = 0x200,
index = 0,
timeout = int(self.timeout*1000))
if result != len(buf):
return False
buf = self._read_usb_bytes(8)
if buf is None:
return False
for byte in buf:
if byte != 0xA5:
return False
return True