title: RS232 serial signal input via 3.5mm audio port of android smartphone (android developing)
body: <p>Hi and first thank you for reading my question!</p>
  
  <p>I have a device, which gives me an output of essentially just a RS232 serial signal (1200 baud, 8 databits, no parity bits, one stop bit). This output comes in to my android phone via the 3.5mm audio jack.</p>
  
  <p>I want to store every data bit into a variable, display or calculate something and when the next bits come in, it should override the variable.</p>
  
  <p>I know exactly what to do with it after I thave the databits in variables but I have no idea on how to do the basic input / stream / read from audio jack thing...</p>
  
  <p>I found this but it dosn't help me very much: <a href="https://stackoverflow.com/questions/8425617/android-serial-port-via-audio-jack">Android serial port via audio jack</a>
  Maybe something like this: <a href="https://stackoverflow.com/questions/6959930/android-need-to-record-mic-input">Android: Need to record mic input</a></p>
  
  <p>Please help me, thank you!</p>
  
  <p>Edit: More informations about my signal
  The payload is transmitted in 9 byte packets:</p>
  
  <pre><code>1: command byte as ASCII character ('I','A','S','L','R','C' or ' ')
  2-6: time in ASCII chars (2:34:56)
  7: checksum (64 + sum of time digits)
  8: CR (carriage return, ASCII code 0x0D)
  9: LF (line feed, ASCII code 0x0A)
  </code></pre>
  
  <p>Edit2: I also think I have to store the input into a buffer and then read the signals from the buffer... But how do I write serial input from audio jack into a buffer?</p>
  
  <p>Edit3: Maybe something like this will work:</p>
  
  <pre><code>try
          {
              int N = AudioRecord.getMinBufferSize(8000,AudioFormat.CHANNEL_IN_MONO,AudioFormat.ENCODING_PCM_16BIT);
              recorder = new AudioRecord(AudioSource.MIC, 1200, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, N*10);
              track = new AudioTrack(AudioManager.STREAM_MUSIC, 1200, 
                      AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, N*10, AudioTrack.MODE_STREAM);
              recorder.startRecording();
              track.play();
              /*
               * Loops until something outside of this thread stops it.
               * Reads the data from the recorder and writes it to the audio track for playback.
               */
              while(!stopped)
              { 
                  Log.i("Map", "Writing new data to buffer");
                  short[] buffer = buffers[ix++ % buffers.length];
                  N = recorder.read(buffer,0,buffer.length);
                  track.write(buffer, 0, buffer.length);
              }
          }
          catch(Throwable x)
          { 
              Log.w("Audio", "Error reading voice audio", x);
          }
          /*
           * Frees the thread's resources after the loop completes so that it can be run again
           */
          finally
          { 
              recorder.stop();
              recorder.release();
              track.stop();
              track.release();
          }
      }
  </code></pre>