I refresh the chart in Timer. When the function refresh chart only everything is OK, but when I add code to the USB communication the graph is updated (once) only when the function is complete.
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();
You need to move all of your network operations out of the main UI thread. I would recommend using
AsyncTaskorThreadto do this. Your network commands are blocking everything else from running which is why it only updates at the end.