The pin settings depend on how your circuit is designed. Pulling a UART
line down is uncommon.
If I were you if out this code aside temporarily and write a stupid simple
program that in its loop function reads a byte (blocking) and writes it to
the log. Until you get this working, there's no point in moving on.
On Jun 26, 2014 12:44 PM, "Markus Kaczmarek" <[email protected]>
wrote:

> Hey, I've been reading up on how to recieve UART messages and given it a
> try with no success. The stack trace always returns with a couple of
> "stream has been closed" and I can't seem to figure out what's up.
>
> This is my Uart Thread:
>
> public class MidiIn extends Thread
> {
> private InputStream inputStream;
>
> /**
>  * Channels used for MIDI input
>  */
> private Uart midi_in_;
>
>
> private AACSmain _main;
>
>
> private boolean _running;
>
> private final String DEBUG_TAG = "MIDI_IN: ";
>
> public MidiIn(Uart MIDI, AACSmain m_, DigitalOutput led_) throws
> ConnectionLostException, InterruptedException
> {
>
> Log.i(DEBUG_TAG  ,"Constructor");
>
>
> _main = m_;
>
>
> midi_in_ = MIDI;
>
> led_.write(false);
> Thread.sleep(1);
> led_.write(true);
>
> inputStream = midi_in_.getInputStream();
>
> _running  = true;
>
>
> Log.i(DEBUG_TAG  ,"Constructor finished");
> }
>
>
>
>
> @Override
> public void run()
> {
> while(_running)
> {
> Log.i(DEBUG_TAG  ,"Looping MIDI in");
> try
> {
> Thread.sleep(2);
>
> }
> catch (InterruptedException e)
> {
> e.printStackTrace();
> }
>
> /**
>  * An array of bytes read from the input
>  */
> byte[] recievedData = new byte[3];
>
> try
> {
> Log.i(DEBUG_TAG  ,"Attempting read.. ");
>
> if(inputStream.available() > 0)
>        <====== Always false
> {
> for (int i = 0 ; i < recievedData.length; i++)
> {
> inputStream.read(recievedData, 0,recievedData.length);
>               <==== this always returns stream closed
> Log.i(DEBUG_TAG, String.format("readLine: %02x", recievedData[i]));
> }
> Log.i(DEBUG_TAG  ,"Finished read.. ");
>
> int byteZero = recievedData[0]  & 0xFF;
> int noteNumber = (int) (recievedData[1] & 0xFF); //Sets note number to int
> int byte2 = recievedData[2] & 0xFF;
>
> Log.i(DEBUG_TAG, "Databyte0: " + byteZero + " data1: " +
> recievedData[1] + " data2: " + byte2);
>
> if (recievedData[0] == (ShortMessage.NOTE_ON & 0xFF)) //If it was Note On,
> set color of pad
> _main.setColorOfPad(noteNumber);
> }
>
> }
> catch (IOException e)
> {
> e.printStackTrace();
> }
> }
> }
>
>
>
> Where the uart thread is initialized in main like this:
>
> _uart = ioio_.openUart(new DigitalInput.Spec(MIDI_INPUT_PIN,
> DigitalInput.Spec.Mode.PULL_DOWN),
> new Spec(MIDI_OUTPUT_PIN,Mode.NORMAL),BAUD,Parity.NONE,StopBits.ONE);
>
> _midiIn = new MidiIn(_uart, AACSmain.this, led_); //TODO
>
> _midiIn.start(); //TODO
>
> ( BAUD = 31250, MIDI_OUTPUT_PIN = 7 & MIDI_INPUT_PIN = 6)
>
>
>
> I've tried a few different solutions with a buffered reader and so on, but
> nothing seems to work..
>
>
> Just realized while typing, is it even necessary to specify the input in
> pull down mode? Not sure why I did it this, some parts of the code might be
> written in semi-awake state at 4 in the morning.. ;)
>
> --
> 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/d/optout.
>

-- 
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/d/optout.

Reply via email to