I’m presently developing a USB device (microcontroller based data logger) and would like to collect data from the device to a host computer for visualization. Libusbjava is used for USB data transfer. Presently, I’m able to connect to the device and send/receive data.
My problem is when I try to continuously receive data (5.12Mb/s) from the device in a continuous fashion. Here is what happens:
· If I try to continuously collect data in a while loop, desired USB throughput is achieved, but the graphing thread no longer works · If I try collecting data every 1ms using a timer thread (640bytes every 1ms), throughput is significantly affected but the graphing thread is functional
What would be the optimal way to structure my java code to allow for desired throughput and graphing?
Handle the USB communication in the background using
SwingWorker
. Trying to update the GUI every millisecond is unrealistic. Instead,publish()
updates in batches andprocess()
them on the event dispatch thread.