Polling USB for data using USB4Java

446 views Asked by At

I'm using USB4Java to poll a certain USB device on a thread and immediately read in the data when available. The problem I'm facing is that there's no available() method like there is for streams, which checks the available number of bytes on the port for reading (a la NRSerial for serial ports). Is there an equivalent way of doing this for USB? If not, could I simply just call the read function and wait for timeout? The latter seems too brute force to me.

1

There are 1 answers

0
dryman On

There is simply no other choice than polling (at least in USB 2.0). This is how reading in USB works: The host asks the device for data. The device has to save data to send to the host in a buffer and wait for the host to ask for it. Only USB 3 grants the possibility to the device to tell the host when new data is in the buffer (althrough technically this is also the host polling for a flag which is more leightweight than initiating a read transfer).