嗨,首先感謝您閱讀我的問題!通過android智能手機的3.5mm音頻端口輸入RS232串行信號(android開發)
我有一個設備,它給我一個本質上只是一個RS232串行信號(1200波特,8個數據位,無奇偶校驗位,一個停止位)的輸出。這個輸出通過3.5mm音頻插孔進入我的android手機。
我想存儲每個數據位到一個變量,顯示或計算的東西,當下一個位進來時,它應該覆蓋變量。
我知道到底該怎麼用它做後我thave變量的數據位,但我對如何做基本輸入/流/從音頻插孔的事情讀不知道......
我發現這一點,但它不會很幫我:Android serial port via audio jack 也許是這樣的:Android: Need to record mic input
請幫助我,謝謝!
編輯:
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)
EDIT2:我的信號 的有效載荷在9個字節的數據包傳送的更詳細的信息我也認爲我必須將輸入存儲到緩衝器,然後從緩衝器讀出的信號...但是,我怎樣從音頻插孔將串行輸入寫入緩衝區?
EDIT3:也許這樣的事情會工作:
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();
}
}