0

I use python3.7 pyusb1.0.2 and libusb-win32-devel-filter-1.2.6.0 in windows 10.
My FPGA send data to my computer in 10MB/s through USB interface after it received 0x1111. It lasts ten seconds. I found my python program just can receive part of data, about 4MB. Here is the code:

import usb.core
import usb.util

filename = r'E:\FlowFluorescence\1.mywork\experiment\data\201901290000.txt'
file = open(filename,'wb')

dev = usb.core.find(idVendor=0x04b4, idProduct=0x00f1)

if dev is None:
   raise ValueError('Device not found')

dev.set_configuration()

cfg = dev.get_active_configuration()
intf = cfg[(0,0)]

data = b''
dev.write(0x02, b'\x11\x11')

while True:
     try:
        data = data + dev.read(0x86,512,100)
    except usb.core.USBError:
        break

file.write(data)
file.close()

How can I improve the pyusb reading speed? I need 10MB/s at least. Hoping for your answer.

1 Answers1

0

I found this way is faster.

while True:
    try:
        #data = data + dev.read(0x86,512,100)
        data = dev.read(0x86,512,100)
        file.write(data)
    except usb.core.USBError:
        break

In this way, it read 28MB at last.

  • I made more tests. I found while ture costs 0.25us and that writing 512 bytes to a txt costs about 3us. So the reading speed limits must be in the pyusb. This is right? – ui vfxi Jan 30 '19 at 07:12