Jacques Pelletier wrote:
> What I'm trying to do now is to integrate the libusb routines with glib to be
> used in my application. I took the giounix.c source code from glib as a
> In order to do that, I would need a function which report if there are any
> bytes available for reading. Would it be difficult to write?
In the most general case, yes, it is difficult. I haven't commented yet
on the philosophy of what you're trying to do here, but there's a
certain mismatch between your concept and the way USB works.
People who come from an RS232 background have a tendency to think of USB
as a serial port from a better neighborhood, but it's not very much like
a serial port. With a serial port, you read bytes, you write bytes.
That's it. One stream, one protocol. With a USB device, you have
multiple endpoints essentially reading or writing multiple streams of
data, all transmitting at once, each of which can be of a different type
(bulk, isochronous, interrupt, control). Each endpoint has its own
"protocol", often affected by what is going on in the other endpoints.
Further, USB is entirely a host-driven bus. A device cannot initiate a
transmission. It cannot send anything at all unless a host asks it for
data, and a host won't ask for data unless an application has made a
request for that data.
So, when you ask "are there bytes available for reading," there is no
simple answer. You can submit a read request on a particular endpoint
(assuming it is an IN endpoint; remember that endpoints are
unidirectional), and if the device has data ready, it will send it. If
not, it will block until there IS data (for a bulk endpoint). So, your
application could conceivably queue up a read request unilaterally,
buffer up the data, and use that to answer the "are there bytes
available for reading" question, but even then you wouldn't know how
much data was really out there. If a bulk endpoint defines a packet
size of 64 bytes, and you queue up a read request for 64 bytes, it won't
return until there are 64 bytes, even if the device only has 8 bytes
ready. Further, if you submit a read request for 8 bytes, but the
device wants to send 64 bytes, that's an error.
There may be very specific classes of USB device where your
ultra-generic send/receive debug tool is valuable, but in the general
case, I think you are in for a certain amount of frustration.
Tim Roberts, timr@...
Providenza & Boekelheide, Inc.