Reputation: 1
Hi I am new to programming and need to extract data for my school project. The data is coming in from an Arduino device which sends data that looks like this.
<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>
I need to get rid of the first three lines and then send the remaining code to be graphed. I have tried to Delimit and Split the angle brackets but nothing I know how to do seems to work. Any help would or suggestions of where I can find an answer (I have been looking on here for a day already) would be appreciated thank you.
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
}
I tried editing the question to show what I did.
Upvotes: 0
Views: 152
Reputation: 1
I decided to forgo a delimited and use a Vector with an "indexOf(">") + 1, lastIndexOf("<")" which I know is outdated but it works for my purpose. It holds the data I need and can sent to different graphs which I need. Thank you for your help though I appreciate it.
Upvotes: 0
Reputation: 425073
You need to split before an open bracket, but not when it's followed by a slash. And you need the split to not consume the bracket. All this can be done with a look ahead.
Try this:
scanner.useDelimiter("(?=<[^/])");
Then every time you call scanner.next()
you'll read in an entire tag.
The regex means "the following characters are a <
then a character that is not a slash" and it won't consume any of the input (the match is zero-length, actually between characters)
Upvotes: 1