11-11-2013 08:04 PM
Hi guys,
Any advice or help would be much appreciated
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.
Solved! Go to Solution.
11-11-2013 08:22 PM - edited 11-11-2013 08:24 PM
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
11-11-2013 08:25 PM
Hi Lennard,
Unfortunately I cannot change the data input format.
😞
11-11-2013 08:36 PM
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
11-11-2013 08:42 PM
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....
11-11-2013 09:10 PM
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
11-11-2013 09:16 PM
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.
11-11-2013 09:43 PM
Converting to an array of strings and some simple Match Pattern functions seems to do omost of what you want.
Lynn
11-11-2013 10:03 PM - edited 11-11-2013 10:04 PM
Hi pokerprof,
If you are planning to get the data individually, have you tried the following:
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:
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
11-11-2013 11:01 PM
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 ?