简体   繁体   English

使用USB4Java轮询USB以获取数据

[英]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. 我正在使用USB4Java轮询线程中的某个USB设备,并在可用时立即读取数据。 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). 我面临的问题是,没有像流一样的available()方法,该方法检查端口上可供读取的字节数(串行端口为la NRSerial)。 Is there an equivalent way of doing this for USB? USB是否有等效的方法? If not, could I simply just call the read function and wait for timeout? 如果没有,我可以简单地调用read函数并等待超时吗? The latter seems too brute force to me. 后者对我来说似乎太残酷了。

There is simply no other choice than polling (at least in USB 2.0). 除了轮询以外,别无选择(至少在USB 2.0中)。 This is how reading in USB works: The host asks the device for data. 这就是读取USB的工作方式:主机要求设备提供数据。 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). 只有USB 3才使设备有可能在缓冲区中有新数据时通知主机(从技术上讲,这也是主机轮询标志的重量,该标志比启动读取传输的重量更重)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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