1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| class Looper extends BaseIOIOLooper implements OnClickListener {
@Override
public void setup() throws ConnectionLostException {
uart = ioio_.openUart(7,13,115200,Uart.Parity.NONE,Uart.StopBits.ONE);
in = uart.getInputStream();
out = uart.getOutputStream();
button_.setOnClickListener(this);
}
public void loop() throws ConnectionLostException, InterruptedException {
try {
in.read();
messagein= convertStreamToString(in);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
textin.setText(messagein.toString());
Thread.sleep(10);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==button_){
sending();
}
}
public String convertStreamToString(InputStream is) throws IOException{
byte[] buffer = new byte[1024];
String result;
StringBuffer sb = new StringBuffer();
int readIn=0;
while((readIn = is.read(buffer)) > 0){
String temp = new String(buffer, 0, readIn);
sb.append(temp);
}
result = sb.toString();
return result;
}
} |
Partager