def cp2130_libusb_readRTR(handle): buf = c_ubyte * 8 read_command_buf = buf(0x00, 0x00, 0x04, 0x00, datalen, 0x00, 0x00, 0x00) bytesWritten = c_int() buf = c_ubyte * datalen read_input_buf = buf() bytesRead = c_int() usbTimeout = 500 error_code = libusb1.libusb_bulk_transfer(handle, 0x02, read_command_buf, sizeof(read_command_buf), byref(bytesWritten), usbTimeout) if error_code: print('Error in bulk transfer (read command). Error # {}'.format( error_code)) return False if bytesWritten.value != sizeof(read_command_buf): print('Error in bulk transfer write size') print(bytesWritten.value) return False error_code = libusb1.libusb_bulk_transfer(handle, 0x81, read_input_buf, sizeof(read_input_buf), byref(bytesRead), usbTimeout) if error_code: print('Error in bulk transfer (read buffer). Error # {}'.format( error_code)) return False return read_input_buf
def cp2130_libusb_read(handle): buf = c_ubyte * 8 read_command_buf = buf(0x00, 0x00, 0x00, 0x00, 200, 0x00, 0x00, 0x00) bytesWritten = c_int() buf = c_ubyte * 200 read_input_buf = buf() bytesRead = c_int() usbTimeout = 500 # print('Begin Read') error_code = libusb1.libusb_bulk_transfer(handle, 0x02, read_command_buf, sizeof(read_command_buf), byref(bytesWritten), usbTimeout) if error_code: print('Error in bulk transfer command= {}'.format(error_code)) return False if bytesWritten.value != sizeof(read_command_buf): print('Error in bulk transfer write size') print(bytesWritten.value) return False error_code = libusb1.libusb_bulk_transfer(handle, 0x81, read_input_buf, sizeof(read_input_buf), byref(bytesRead), usbTimeout) if error_code: print(bytesRead.value) print('Error in bulk transfer read = {}'.format(error_code)) return False return read_input_buf
def _bulkTransfer(self, endpoint, data, length, timeout): transferred = c_int() result = libusb1.libusb_bulk_transfer(self.__handle, endpoint, data, length, byref(transferred), timeout) if result: raise libusb1.USBError(result) return transferred.value
def cp2130_libusb_flush_radio_fifo(handle): buf = c_ubyte * 13 write_command_buf = buf(0x00, 0x00, 0x01, 0x00, 0x05, 0x00, 0x00, 0x00, 0xAA, 0x00, 0x00, 0x00, 0x00) bytesWritten = c_int() usbTimeout = 500 if libusb1.libusb_bulk_transfer(handle, 0x02, write_command_buf, sizeof(write_command_buf), byref(bytesWritten), usbTimeout): print('Error in bulk transfer!') return False return True
def cp2130_libusb_read(handle): buf = c_ubyte * 8 read_command_buf = buf(0x00, 0x00, 0x00, 0x00, datalen, 0x00, 0x00, 0x00) bytesWritten = c_int() buf = c_ubyte * datalen read_input_buf = buf() bytesRead = c_int() usbTimeout = 500 error_code = libusb1.libusb_bulk_transfer(handle, 0x02, read_command_buf, sizeof(read_command_buf), byref(bytesWritten), usbTimeout) if error_code: print('Error in bulk transfer (read command). Error # {}'.format( error_code)) return False if bytesWritten.value != sizeof(read_command_buf): print('Error in bulk transfer write size') print(bytesWritten.value) return False # time.sleep(0.05) # while(1): # pass error_code = libusb1.libusb_bulk_transfer(handle, 0x81, read_input_buf, sizeof(read_input_buf), byref(bytesRead), usbTimeout) if error_code: print('Error in bulk transfer (read buffer). Error # {}'.format( error_code)) return False if bytesRead.value != sizeof(read_input_buf): print('Error in bulk transfer - returned {} out of {} bytes'.format( bytesRead.value, sizeof(read_input_buf))) return False # for i in read_input_buf: # print('{} '.format(i), end="") return read_input_buf
def cp2130_libusb_write(handle, value): buf = c_ubyte * 13 write_command_buf = buf(0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00) # populate command buffer with value to write write_command_buf[8:13] = value bytesWritten = c_int() usbTimeout = 500 error_code = libusb1.libusb_bulk_transfer(handle, 0x02, write_command_buf, sizeof(write_command_buf), byref(bytesWritten), usbTimeout) if error_code: print('Error in bulk transfer (write command)! Error # {}'.format( error_code)) return False return True