Re: 4 devices and bulk mode data transfer with all in parallel

Ekkehard <[email protected]>
Newsgroups gmane.comp.lib.libusb.devel.windows
Message-ID <[email protected]>
Hello,
sorry have this read late, but maybe still an issue.
One thread per device is good.
The essential trick is to run the whole thing in an array, so that at least
one usb_submit_async ... usb_reap_async pair is pending.
In your code in the time between usb_reap_async and the next
usb_submit_async call, all data are lost. 
So the code would be something like this
(I am not working with C, so my code below is not syntax checked :-))

#define numctx 16

void readThread()
{

// define an array with numctx contexts
void async_context[numctx];

// init all contexts and start reading all contexes
for (i=0;i<numctx;i++) {
  usb_bulk_setup_async(m_dev, &amp;async_context[i], ucEP);
  usb_submit_async(async_context[i], bytes, size);
}

ndx = 0;
while(!terminated)
{
  // wait for the first reading finished (timed out or having data)
  len = usb_reap_async(async_context[ndx], timeout);
  if (len > 0) { 
  // if not timed out do something with the data, but keep this time short,
eg copy data to a different thread
  }
// I am not 100% sure if the context can be reused, but it looks like
// so just re-arm the thing
  usb_submit_async(async_context[ndx], bytes, size);
// increment the index and wait for the the buffer
  ndx++;
  if (ndx >= numctx) 
    ndx = 0; 
}
// clean up
for (i=0;i<numctx;i++) {
  // evtually cancel actual running readings...
  usb_free_async(&amp;async_context[i]);
}
}

Hope that will help you. I was able to read big data rates fromseveral
devices with this approach
Greetings Ekkehard



&lt;quote author=&quot;rSrinivas&quot;>
Hi,

I have to get our windows application working with USB data read from MAX 4
devices of same VID+PID ( different serial nos ).  

As per my setup, either one device can be connected to USB or all 4 devices.

Each device gets 512 bytes in one milli second and I need to read data all
connected devices WITHOUT DATA LOSS. 

With 4 devices connected, I am not able to read data fast enough and
performance drops. Thats my issue.

Device has an internal buffer of 6000 bytes to store this data. So it is
sufficient to poll each device even after 10 milli sec; but I am trying to
poll for each 6 milliseconds.

I am using bulk mode async data transfers to read/write the BULK endpoints
of the device.

When device was configured in CDC mode, I see every short data frames ( even
3 bytes ) in USBlyzer tool. But when the device is configured as Generic
bulk mode device
, I observe 4096 bytes transferred in USBlyzer for each 6 milliseconds.

I am not able to get this point? Which mode gives better performance? I am
using TI USB library.


Moreover, I have a read thread , per device one thread, and it is something
similar,


void readThread()
{

while(1)
{
......
usb_bulk_setup_async(m_dev, &async_context, ucEP);
usb_submit_async(async_context, bytes, size);
usb_reap_async(async_context, timeout);
usb_free_async(&async_context);
//Sleep(6);
...
}

}

With one device connected , I am able to read all the DATA and it works fine
for me. But when more devices are connected, it is taking more time to poll
each device and so performance is failing.


I AM SURE READING, data of 2560  * 4 bytes from 4 devices is not issue. But
why not getting the required throughtput is an issue for me?


ANy hints, pls help.


srinivas





--
View this message in context: http://libusb.6.n5.nabble.com/4-devices-and-bulk-mode-data-transfer-with-all-in-parallel-tp5712875p5713092.html
Sent from the LibUSB Dev - Win32 mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.