2014-07-06 92 views
0

我正在用Java編寫串口到MIDI接口,串口數據來自Arduino並通過RXTX庫進行處理。 不幸的是,使用來自Arduino網站link的建議代碼,我無法檢索串行數據。 示例代碼在Arduino端使用Serial.println,在Java端使用BufferedReader.readLine()。在我的代碼中,我沒有通過Serial.println寫一行,而是寫了一條MIDI消息。Java Arduino串行讀取

的Arduino

void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) 
{ 
    status = MESSAGE + midichannel; 
    Serial.write(status); 
    Serial.write(PITCH); 
    Serial.write(VELOCITY); 
} 

我想讀一個字符緩衝區的串行數據:

的Java

char buf[] = new char[3]; 
reader.read(buf); 
int channel = (int)buf[0] ; 
int key = (int)buf[1] ; 
int vel = (int)buf[2] ; 

,但我越來越怪異的數據...

回答

2

解決: 這只是一個錯誤在port.setSerialPortParams,我在波特率115200寫作,但在9600

+0

你可以標記爲已接受這個答案閱讀,因此它不會對懸而未決的問題清單上顯示?謝謝。 – dsolimano

+0

對不起,我忘了。 – ascallonisi

+1

NP,感謝讓堆棧溢出一個更好的地方! – dsolimano