InputStream.read() which you are calling reads a single byte from the input. This is probably not what you want. I do not know the format of your stream, but in case it is text, take a look at http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html, which provides an easy way to parse numbers from a textual representation. I also recommend you to get rid of the "if (available)" pattern. Just let it block.
On Fri, Feb 14, 2014 at 7:35 AM, Marius Vosylius <[email protected]>wrote: > Im struggling with peace of code. Can someone tell me what Im doing wrong > and give me same explanation please. > > > > class Looper extends BaseIOIOLooper { > > Uart uart; > > InputStream in; > > double latitude, longitude; > > > > public void setup() throws ConnectionLostException { > > > > uart = ioio_.openUart(12, 11, 9600, Uart.Parity.NONE, > Uart.StopBits.ONE); > > in = uart.getInputStream(); > > } > > > public void loop() throws ConnectionLostException { > > try { > > if (in.available() != 0){ > > latitude = in.read(); > > longitude = in.read(); > > // append to terminal > > String s1 = "" + (char)latitude; > > appendText(s1); > > } > > } catch (IOException e) { > > // TODO Auto-generated catch block > > e.printStackTrace(); > > } > > } > > > private void appendText(final String s1) { > > // TODO Auto-generated method stub > > runOnUiThread(new Runnable() { > > @Override > > public void run() { > > txtLatitude.setText(String.format("%.6f", latitude)); > > txtLongitude.setText(String.format("%.6f", longitude)); > > } > > }); > > } > > } > > -- > You received this message because you are subscribed to the Google Groups > "ioio-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/ioio-users. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "ioio-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/ioio-users. For more options, visit https://groups.google.com/groups/opt_out.
