11-30-2015 11:11 AM
Hi Everybody,
I'm communicating with a scale, using the Continuous Serial Write and Read sub-vi.
It outputs a string with a format:
ST, GS, + 0.00 g
I want to extract only the number and convert it into a double so I can graph the weight change over time.
The expressions I've been using with Match Regular Expression, have not been working.
I've tried
[0-9]+(\.[0-9]+)*
and
d+(\.\d{2})?
Is there a better way to parcel this data?
Solved! Go to Solution.
11-30-2015 11:23 AM
@smat123 wrote:
Hi Everybody,
I'm communicating with a scale, using the Continuous Serial Write and Read sub-vi.
It outputs a string with a format:
ST, GS, + 0.00 g
I want to extract only the number and convert it into a double so I can graph the weight change over time.
I'm a big fan of Scan From String and Format Into String. I gather that this is the output from a Balance. Are the first two fields always 2 characters long? That is, is the format of all of the strings <2 char>, <2 char>, <number> <unit>?
If so, I would pass the string into a "Scan from String" with format %2s, %2s, %f, %s. If I don't need the first two fields, I can just not wire those outputs. The third output will be the number, and the fourth will be the unit ("g") in your example, but if your balance autoscales, it might become "mg" or "kg").
You can also do some of this with Regular Expressions. If you do, take advantage of the comma separators to skip past the first two fields.
Bob Schor
11-30-2015 11:24 AM
11-30-2015 11:27 AM - edited 11-30-2015 11:33 AM
Damn, you others are too fast, but I'll post what I made all the same:
This reads the sign automatically and outputs the DBL as positive or negative.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'