简体   繁体   中英

Polling USB for data using USB4Java

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM