02-25-2016 04:42 AM
All,
I have a few Arduinos board built into an extensive test setup that I am able to log data from. I now need to be able to see my data in real-time as it comes over the serial port. I found a VI that seems like it should work, my problem is that I cannot seem to get a regular expression to work.
The VI is not mine, but if I can get this to work, I can easily put it into my VI.
Here is my Arduino code; it is time stamp, followed by four data points, with tab delimiters. It prints to the serial port as
190876 762314 814437 1108235 1091719
Serial.print(sTime); //Serial.print(", "); Serial.print("\t"); data = getdata(dataRead); data = data>>4; Serial.print(data); //Serial.print(", "); Serial.print("\t"); data = getdata(dataRead1); data = data>>4; Serial.print(data); //Serial.print(", "); Serial.print("\t"); data = getdata(dataRead2); data = data>>4; Serial.print(data); //Serial.print(", "); Serial.print("\t"); data = getdata(dataRead3); data = data>>4; Serial.println(data);
I think this is mainly an issue with the regular expression. Any tips or pointers would be great.
I wish there was a place to just copy and paste my string into, and obtain a regular expression.
Solved! Go to Solution.
02-25-2016 05:14 AM
Why not just use a spreadsheet string to array?
The Regex is not doing what you think it is doing.
/ \r\n[0-9]+\.[0-9]+\r\n\r\nA/ matches the character literally \r matches a carriage return (ASCII 13) \n matches a line-feed (newline) character (ASCII 10) [0-9]+ match a single character present in the list below Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] 0-9 a single character in the range between 0 and 9 \. matches the character . literally [0-9]+ match a single character present in the list below Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] 0-9 a single character in the range between 0 and 9 \r matches a carriage return (ASCII 13) \n matches a line-feed (newline) character (ASCII 10) \r matches a carriage return (ASCII 13) \n matches a line-feed (newline) character (ASCII 10) A matches the character A literally (case sensitive)
Your data is not in that format!
02-25-2016 12:05 PM
That is what I did in my old code. (See attached)
This process works great, but I cannot see the data on the plot until after I have stopped the VI.
Can I use the "Spreadsheet String to Array Function" inside my main loop?
My problem with this is I would need to split the string at my new line characters so I do not get truncated data.
02-25-2016 12:17 PM
@Austin-Downey wrote:
Can I use the "Spreadsheet String to Array Function" inside my main loop?
Yes.
@Austin-Downey wrote:
My problem with this is I would need to split the string at my new line characters so I do not get truncated data.
Sorry thats not a problem, it is either because you are too lazy to program that in or you are very new to LabVIEW. If it is the latter, please look at some LabVIEW tutorials.
The VI in your first post is waiting for complete data and the conversion happens in the case structure. Please do the same here.
02-25-2016 12:31 PM
Thanks,
Yeah, I am newish to LabVIEW and self-thought.
I think I can split my array with a "Search/Split String Function". I will give that a shot now. Would there be a better way to do that?
My understanding is the VI in the first post is looking for something that matches "xx.xx", once this is found it is sent to the inward case structure. Why can't I do the same thing here?
Thanks again.
02-25-2016 01:33 PM - edited 02-25-2016 01:46 PM
OK,
I think I am back to where I was on the first post. I need to pull the data into my loop, and split the string. What the first code was doing with the regular expression. Here I am trying to do it with a "Search/Split String Function" that searches for a new line indicator, and split the sting at that point.
My thought processes is that I can than read all the data before the new line indicator, and let everything after the new line indicator loop to the shift registers. This however does not seem to work. In the code I have provided, the "Search/Split String Function" lets everything pass. i.e. it splits the string at the last data received, and not at the new line indicator as expressed in the code.
I also tied a \r and \r\n, but I get the same results.
I need to find a way to split my strings at the newline indiactor, or as stated before " waiting for complete data". How can I build a VI that knows when the data is complete (i.e. It sees a new line), and then pass that stiring on.
Here you can see my CI is taking anything in the buffer and letting it pass through the "search/split function"
For completness, here is what the data coming in looks like in notepad++
Thanks in advance.
A
02-25-2016 01:54 PM - edited 02-25-2016 01:57 PM
Just a small observation.
If there is no match then "match + rest of string" is an empty string. In this case you should pass the "read buffer" string to the shift register. If you have a match then you shouldn't pass the "match" part to the shift register, just the "rest of string" part. The first time you have a match the character \n will always return as the first character in the next loop iteration so "substring before match" will always be empty.
Ben64
edit: How does the data in Notepad++ relate to the read buffer data?
02-25-2016 02:03 PM - edited 02-25-2016 02:05 PM
Don't use bytes at port!
Take advantage of the termination character you have. Enable it on the Serial Configure and set it to the linefeed character.
Now the VISA Read will wait until it has the entire line (or timeout if it doesn't come). Then you can parse your data from there.
I think the problem with your code is that you are searching for a backslash n. Not a line feed character. Turn on the the display style for that constant and you'll see it is set for normal display and not backslash display.
02-25-2016 02:12 PM
Ben64,
The data in notepad++ is how the data come in over my VISA. I posted it so everyone would know how the data is coming into the VI. This is what I am trying to split line by line so I can extract each data point.
I tried what you said, see the resulting outputs.
The same problem seems to reamin. It does not seem to split the line at \r or \n.
Maybe I need to search for a real string in my code.
I still don't understand why I can't just search for a regular expression that matches my line....
Thanks for your comments, any other ideas would be welcome.
02-25-2016 02:20 PM