I am trying to receive serial data from Arduino and i want to store the value in a variable how can i do it ? I tried the code below but it is not storing the value of string in the array element t[0]
or is there a way to store reading from input stream ?
final String[] t = new String[1];
t[0]="0";
final Handler handler = new Handler();
stopThread = false;
buffer = new byte[1024];
Thread thread = new Thread(new Runnable()
{
public void run()
{
while(!Thread.currentThread().isInterrupted() && !stopThread)
{
try
{
int byteCount = inputStream.available();
if(byteCount > 0)
{
byte[] rawBytes = new byte[byteCount];
inputStream.read(rawBytes);
final String string=new String(rawBytes,"UTF-8");
handler.post(new Runnable() {
public void run()
{
textView.append(string);
t[0]=string;
}
});
}
}
catch (IOException ex)
{
stopThread = true;
}
}
}
});
thread.start();
return t[0];