LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extract data after a certain line

Solved!
Go to solution

Hi guys,

 

Any advice or help would be much appreciated Smiley Embarassed

 

Question: How to extract data after a certain line from a comma deliminated strings which are read from a serial port ?

 

More Info: A have a card that is gathering data values and is read into the computer via a serial port. Example string of data acquired as below:

 

;Data = 1 bps Tool = Sensor
;Label, Time, Voltage, Pressure, Temperature, Current
A, 01:33, 5.1, 18.1, 31.2, -, 
B, 01:34, 5.5, 19.2, 30.5, -, 
;Data = 1 bps Tool = Sensor
;Label, Time, Voltage, Pressure, Temperature, Current 
A, 01:35, 5.3, 18.3, 30.1, -, 
B, 01:36, 5.1, 19.0, 30.5, -, 

;Data = 1 bps Tool = Sensor
;Label, Time, Voltage, Pressure, Temperature, Current 
A, 01:37, 5.1, 18.1, 30.8, -, 
B, 01:38, 5.3, 19.2, 30.1, -, 

 

These data value will be kept updating line by line. I would like to start extracting the data only on the 3rd block of incoming data. I would not want the first 2 blocks of incoming data.

 

Further Info: Currently, my idea of doing that is to scan the ";Data" and put it into a counter. If there are 2 ";Data" scan, then from the counter it woud output a True value to a case structure to start extracting the data. Please see my attached photo.

 

However, I am not able to create such a counter using an array as I cannot use a while loop and shift register. Do you have any idea ? Thank you very much.

 

 

0 Kudos
Message 1 of 13
(3,918 Views)

Hi pokerprof,

 

Just to ask, are those data format:

 

;Data = 1 bps Tool = Sensor
;Label, Time, Voltage, Pressure, Temperature, Current
A, 01:33, 5.1, 18.1, 31.2, -, 
B, 01:34, 5.5, 19.2, 30.5, -, 

 

created by you?

 

As a simpler suggestion, can you add another marker in front of ;Data like <index> where index = 0,1... n? That way you can just search after < marker and see if it is equals to 2 to extract the data from the 3rd block?

 

Warmest regards,

Lennard.C

Learning new things everyday...
0 Kudos
Message 2 of 13
(3,910 Views)

Hi Lennard,

 

Unfortunately I cannot change the data input format.

 

😞

0 Kudos
Message 3 of 13
(3,906 Views)

Hi pokerprof,

 

1. Can I ask how do you receive the data? Is it all 3 block coming simultaneously?:

 

First iteration

 

;Data = 1 bps Tool = Sensor
;Label, Time, Voltage, Pressure, Temperature, Current
A, 01:33, 5.1, 18.1, 31.2, -, 
B, 01:34, 5.5, 19.2, 30.5, -, 
;Data = 1 bps Tool = Sensor
;Label, Time, Voltage, Pressure, Temperature, Current 
A, 01:35, 5.3, 18.3, 30.1, -, 
B, 01:36, 5.1, 19.0, 30.5, -, 

;Data = 1 bps Tool = Sensor
;Label, Time, Voltage, Pressure, Temperature, Current 
A, 01:37, 5.1, 18.1, 30.8, -, 
B, 01:38, 5.3, 19.2, 30.1, -, 

 

 

or individually? :

 

First iteration

;Data = 1 bps Tool = Sensor
;Label, Time, Voltage, Pressure, Temperature, Current
A, 01:33, 5.1, 18.1, 31.2, -, 
B, 01:34, 5.5, 19.2, 30.5, -, 

 

Second iteration
;Data = 1 bps Tool = Sensor
;Label, Time, Voltage, Pressure, Temperature, Current 
A, 01:35, 5.3, 18.3, 30.1, -, 
B, 01:36, 5.1, 19.0, 30.5, -,

 

Third iteration 

 

;Data = 1 bps Tool = Sensor
;Label, Time, Voltage, Pressure, Temperature, Current 
A, 01:37, 5.1, 18.1, 30.8, -, 
B, 01:38, 5.3, 19.2, 30.1, -, 

 

2. Are you to store the data in an array or just display it in string? Because if it is stored in an array, you can just need to use index array to obtain that 3rd block.

 

 

Thanks

 

Warmest regards,

Lennard.C

Learning new things everyday...
0 Kudos
Message 4 of 13
(3,895 Views)

Hi Lennard,

 

Yes it is coming in as individual block.

 

Oh! You mean getting all the values and then only use the index array to eliminate the values from the first two blocks ? I guess that would work too ! However, is there any simple way for us to immediately start extracting the data only after the 3rd iteration ? I believe there should be a simple way to do so.... 

0 Kudos
Message 5 of 13
(3,892 Views)

Hi pokerprof,

 

Well, if you are obtaining all the data and store it in an array, knowing which index of the array you want to extract, you can use the index array function.

 

About extracting data only after 3rd iteration, may I see your overall code? Is it within a while loop?

 

Warmest regards,

Lennard,C 

 

 

 

Learning new things everyday...
0 Kudos
Message 6 of 13
(3,867 Views)

Hi Lennard,

 

Yes sir, the entire thing is inside a while loop. Note that somehow I cannot use a while loop and shift register to make a counter. 

 

I have attached the VI for you.

 

 

0 Kudos
Message 7 of 13
(3,864 Views)

Converting to an array of strings and some simple Match Pattern functions seems to do omost of what you want.

 

Lynn

0 Kudos
Message 8 of 13
(3,853 Views)
Solution
Accepted by topic author pokerprof

Hi pokerprof,

 

If you are planning to get the data individually, have you tried the following:

 

Untitled.jpg

Untitled2.jpg

 

Put the output of the select.vi (where it is used as a part of the counter) to a comparison so that when let's say: output counter => 3, start extracting.

 

Else you can use the below:
Capture.JPG

 

How many iterations you are planning to run? My concern would be the integer overflow of the counter (http://en.wikipedia.org/wiki/Integer_overflow).  

 

You can try just like the vi shown by johnsold (if you are getting all the data in a single iteration).

 

Thanks

 

Warmest regards,

Lennard.C

Learning new things everyday...
Download All
Message 9 of 13
(3,842 Views)

Hi Lennard,

 

Your use of Select and the shift register of the outer while loop works like a charm. Simple and effective ! Don't even need to use Array. Kudos.

 

I am going to run it for at least 5 minutes to capture all the data. Will this be a concern ?

0 Kudos
Message 10 of 13
(3,834 Views)