我在计时器中刷新图表。当函数刷新图表时,只有一切正常,但是当我将代码添加到 USB 通信时,图表仅在函数完成时更新(一次)。
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
for (int i = 0; i < data[0].length; i++) {
data[0][i] = getRandom(0, 20);
data[1][i] = (i + 1);
}
lineGraph.refreshChart(data[0], data[1]);
if (complete[0]) {
timer.cancel();
timer.purge();
return;
}
}
}, 100, 100);
// without the following two lines works fine
usbPacketTransfer.send();
recivedData = usbPacketTransfer.recive();