08-20-2015 06:42 PM
I am trying to parse this serial data, which is continuously being added to a string. How can I make this into an array that is appended each time through the loop? The data looks like this:
2015/08/20 04:31:39, 0.242, 4.382, 0.219, 22.97, 8.211, 381,
2015/08/20 04:31:43, 0.241, 4.380, 0.220, 22.78, 8.202, 463,
2015/08/20 04:31:48, 0.242, 4.380, 0.219, 23.06, 8.196, 543,
I have been trying to use the 'scan from string function' block with my 'format string' as
%f/%f/%f %f:%f:%f, %f, %f, %f, %f, %f, %f,
Solved! Go to Solution.
08-20-2015 07:08 PM
08-21-2015 01:29 AM - edited 08-21-2015 01:33 AM
I think there are 2 ways
1) (exactly as Mike suggests) Use the "Spreadsheet String To Array" with the format set to "%f" and the delimiter set to a comma. This VI is in the strings pallete 4th row 1st column
OR if you need to do processing/conversion before saving
2) RegEx.
I used one recently to check incoming data for correctness and it worked really well (wanted to make sure only valid characters for hostnames were allowed to be stored in a hostname value).
My regex skills are poor but I found Regular-Expressioin.info helpful
and then to check and make sure the expression was doing what I expected the Regexr site was really good as you can put your own text and expression in and see what matches instantly.
Then all you need to do is use the "Match Pattern" VI from the string pallete (2nd row and 3rd column)
You just use the bits of the output from the VI you want as it splits the string into 3 parts and puts the parts on different wires
You can loop or chain these up as necessary.
1 possible scenario would be to loop for a line of data and put another loop inside that grabs the 7 values based on the ','
08-21-2015 01:52 AM
@mikeporter wrote:
Personally I've never had a lot of luck with long scan strings like that. I think I would split the incoming stream on the date and then turn the remainder of the sample into a 1D array of floats using spreadsheet string to array. You convert the timestamp separately.
If the timestamps are accurate you have 5 sec between samples so you have plenty of time.
Mike...
I like this method a lot. I've even used it to store and retrieve (small) arrays in ini files. Like maybe an array of parameters or something.
08-21-2015 07:52 AM - edited 08-21-2015 07:53 AM
@mikeporter wrote:
Personally I've never had a lot of luck with long scan strings like that. I think I would split the incoming stream on the date and then turn the remainder of the sample into a 1D array of floats using spreadsheet string to array. You convert the timestamp separately.
Actually, convert the timestamp first.
08-21-2015 12:24 PM
08-21-2015 12:37 PM
Your code worked great, thanks for the help.
Quick question: The output array has extra rows of zeros that I want to delete. What's the easiest way to do this?
08-21-2015 12:43 PM
08-21-2015 12:44 PM
jgraf wrote:
Quick question: The output array has extra rows of zeros that I want to delete. What's the easiest way to do this?
I would probably use Clear White Space to get rid of any spaces or end of line character and then String Subset with the length set to the string length-1 to remove the last comma. If you use the Spreadsheet String To Array after doing that, the extra 0s should go away.
08-24-2015 05:20 AM
This seems to work.
/Y