처음에는 프로그래밍에 익숙치 않아 정보 부족으로 실례합니다. 아래는 내 안드로이드 장치를 직렬 통신을 통해 Arduino에 연결하기 위해 Physicaloid를 여는 코드입니다. 지금 당장 arduino에서 나오는 아날로그 신호를 받고 "buf"라는 배열의 tVread에 나타납니다. 그러나 나는 실패하고 안드로이드 플롯을 사용하여 배열 "buf"를 그려 내려고 노력했습니다. 제발 친절하게 조언. 고맙습니다!안드로이드에서 바이트 배열을 그래프로 그리기
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();
}
}
코드를 실행하려고하면 어떤 예외/오류 메시지 또는 예기치 않은 결과가 나타 납니까? – Nick
위의 코드를 실행하면 그래프가 채워지지 않습니다. 오류 메시지가 없습니다. –