torfbolt / PyDAQFlex

Python implementation of Measurement Computing's DAQFlex command framework
15 stars 14 forks source link

USB Overflow problem for continuous transfer with solution (set packet_size to multiple of 512) #2

Open west-rynes opened 10 years ago

west-rynes commented 10 years ago

David: Thanks again for the great work on this package!

I ran into an issue when trying to stream data from our USB 1608GX device. When calling code to get continuous data I would get a USB Overflow Error (sample code shown below).

dev.start_continuous_transfer(rate_hz, 1000, packet_size=packet_size)  
dev.send_message("AISCAN:START")
while True:
    data = dev.get_new_bulk_data(wait=True)  # ERROR HERE: USBError: [Errno 84] Overflow

The fix for this is that the packet_size needs to be in multiples of 512. If I manually set the packet size to:

  packet_size = X (where X is some integer multiple of 512 that you want)
  dev.start_continuous_transfer(rate_hz, 1000, packet_size=packet_size)  

then it works! In your module code for start_continuous_transfer you appear to be setting the packet size based on multiples of 64.

This reference I found indicated that the packet sizes must be multiples of 512: http://libusb.sourceforge.net/api-1.0/packetoverflow.html

I have also noticed that if I try to stream data at rates beyond 100kHz for our 1608GX it stops after a bit. I've seen this with the .NET library from measurement computing and with your code. The 1608GX is supposed to go up to 500kHz. I think their devices can't stream long term as fast as they claim. I've had to tune the speed down to get it to work in a stable manner.

-Anthony

ohhorob commented 9 years ago

The Message-based Firmware Specification document states for the 1608G Series:

The bulk in and bulk out max packet sizes are 512 bytes when enumerated as a high-speed device and 64 bytes when enumerated as a full-speed device.

http://www.mccdaq.com/pdfs/manuals/Message-based%20Firmware%20Specification.pdf

torfbolt commented 9 years ago

Thanks for your findings. As I currently do not have a device to test on, could you please try if the formula for automatic package size works when converting it to multiples of 512? Or does it have to be exactly 512?