Firstly, pardon me due to lack of info as I am very new to programming. Below are my codes for opening Physicaloid to connect my android device to Arduino through serial communication. Right now I am receiving analog signals coming from my arduino and appearing on tVread from the array "buf". However I failed and stucked trying to plot it the array "buf" using Android Plot. Please kindly advice. Thank you!
if (mPhysicaloid.open()) {
setEnabledUi(true);
if (cbAutoscroll.isChecked()) {
tvRead.setMovementMethod(new ScrollingMovementMethod());
}
mPhysicaloid.addReadListener(new ReadLisener() {
@Override
public void onRead(int size) {
byte[] buf = new byte[size];
Number[] numarray = new Number[size];
mPhysicaloid.read(buf,size);
//convert buf to int array
for(int i=0;i<size;i++) {
numarray[i]= buf[i];
}
tvAppend(tvRead, Html.fromHtml("<font color=blue>" + new String (buf) + "</font>"));
XYSeries series1 = new SimpleXYSeries(
Arrays.asList(numarray),SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,"Series1");
LineAndPointFormatter series1Format = new LineAndPointFormatter(
Color.rgb(0, 200, 0), // line color
Color.rgb(0, 100, 0), // point color
null, // fill color (none)
new PointLabelFormatter(Color.WHITE));
mySimpleXYPlot.addSeries(series1, series1Format);
}
});
} else {
Toast.makeText(this, "Cannot open", Toast.LENGTH_LONG).show();
}
}