[英]Java Arduino Serial Read
我正在用Java開發一個Serial to MIDI接口,串行數據來自Arduino,並通過RXTX庫進行處理。 不幸的是,使用來自Arduino網站鏈接的建議代碼,我無法檢索串行數據。 示例代碼在Arduino端使用Serial.println
,在Java端使用BufferedReader.readLine()
。 在我的代碼中,我不是通過Serial.println寫一行,而是一條MIDI消息。
的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);
}
我嘗試讀取char緩沖區上的串行數據:
爪哇
char buf[] = new char[3];
reader.read(buf);
int channel = (int)buf[0] ;
int key = (int)buf[1] ;
int vel = (int)buf[2] ;
但我得到的數據很奇怪...
已解決:這只是port.setSerialPortParams
的錯誤,我的波特率為115200,但讀取值為9600。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.