g...@novadsp.com wrote:
> Once I have opened a device using LibUsbX, is there a
> synchronization handle I can pend on whilst waiting for the
> peripheral device to write back to the host?

The device is not allowed to transmit to the host before your
application requests data.


> // open device etc.
> libusb_open_device_with_vid_pid(NULL,m_args.VID,m_args.PID);
> while (!done)
> {
>    DWORD dw = WaitForMultipleObjects(handles.size(),&handles[0],FALSE,10);
>    // data waiting to be read from device
>    if (dw == WAIT_OBJECT_0 + 0)
>    {
>         // do the read ...
>         result = libusb_bulk_transfer(m_pDevice,m_epIn,...);
>    }
>    // ....
> }

No good since there can be no data from device until you initiate a
transfer.

Another point is that the code is absolutely unportable, which kindof
misses one big point of using the portable libusb-1.0 API.

I recommend to create one USB event handling thread (which you may
already have) that calls libusb_handle_events_completed() in a loop,
and then you can choose per transfer if you want to perform a
synchronous transfer like in the call above where
libusb_bulk_transfer() will return when the requested data has been
transfered, or if you want to use the asynchronous API and queue a
transfer for processing an get a callback notification once it is
done, but be able to continue your own processing meanwhile.


//Peter

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to