嗨我是新手編程,需要爲我的學校項目提取數據。數據來自Arduino設備,該設備發送的數據看起來像這樣。在netbeans中分割尖括號之間的傳入數據
<call_sign>IVV-HAM</call_sign>
<mission_call>ARP</mission_call>
<absolute_time>13:13:13</absolute_time>
<elapsed_time>43</elapsed_time>
<imu_accel_x>240</imu_accel_x>
<imu_accel_y>196</imu_accel_y>
<imu_accel_z>62</imu_accel_z>
<imu_gyro_x>599</imu_gyro_x>
<imu_gyro_y>1013</imu_gyro_y>
<imu_gyro_z>215</imu_gyro_z>
<imu_mag_x>402</imu_mag_x>
<imu_mag_y>495</imu_mag_y>
<imu_mag_z>447</imu_mag_z>
<imu_temp>453</imu_temp>
我需要擺脫前三行,然後發送剩餘的代碼進行繪圖。我試圖劃分和分割尖括號但我知道怎麼做似乎工作。 任何幫助意見或建議我可以找到答案(我已經在這裏看了一天已經),將不勝感激謝謝。
public void run(){
//create a new Scanner and connect it to the Serial Port
input = new Scanner(connectedPort.getInputStream());
//HERE I tried to use input.useDelimiter("></")
// I also tried to split by creating a string.split but
// it did not work either.
//loop indefinitely until you get data from the Serial Port
while(input.hasNextLine()){
//get line of text from serial port
String line = input.nextLine();
//dump the raw data to the output text area
//taRawOutput.append(Integer.toString(number)+'\n');
textArea_RawData.append(line+"\n");
}//end of loop
//close the scanner object reading from the serial port
input.close();
}//end of methd run()
};//end of inner class definition
//start the thread that was just defined running
thread.start();
}catch(IOException e){
JOptionPane.showMessageDialog(this, e.getMessage());
}//end of catch block
}
我試着編輯問題來顯示我做了什麼。
請告訴我們你試過的東西 –
PS看起來像XML –
「新掃描儀」之後,我嘗試使用「input.useDelimiter(」>「)」但不起作用的分隔符我刪除了代碼。 –