04-12-2013 07:14 AM
Hey all,
I want labview to convert a spreadsheet string to an array. This is easy using the 'spreadsheet string to array' tool. The only problem I've got is that I get the string from a RS232 device and it is time critical.
Example:
If I read the data from the buffer it gives me:
+1.50337800E+00,+1.70316300E+00 for two channels, this is converted and accepted
if there is a small delay I get:
+1.50337800E+00,+1.70316
This will also be accepted because +1.70316 is also recognized as a number.
How can program labview to check that every number it reads is according to the Scientific Notation?
Thanks
Solved! Go to Solution.
04-12-2013 07:20 AM - edited 04-12-2013 07:21 AM
Hi Bart,
maybe the problem is not with the string to number conversion?
The problem is your serial port handling!
You should always receive full messages - or otherwise don't use those mangled messages...
For your original question:
Convert to an array of strings (instead of numbers). Check each string to contain an "E" followed by a number...
04-12-2013 07:28 AM
04-12-2013 07:33 AM
Hi Barts,
check for the delimiter "," to be the last char and throw away any string parts after the last delimiter...
When there is a clear scheme for the last number (like ±n.nnnE±mm) you can check for that pattern using some RegEx pattern matching. Wait for one of the RegEx experts here to jump in...
04-12-2013 08:16 AM
This regex seems to work for me for all the cases I tried:
[+/-]\d+\.\d+[Ee][+/-]\d+
Note that it is very restrictive and only follows the form of ±n.nnnE±mm
04-12-2013 10:22 AM
@Don_Phillips wrote:
This regex seems to work for me for all the cases I tried:
[+/-]\d+\.\d+[Ee][+/-]\d+
Note that it is very restrictive and only follows the form of ±n.nnnE±mm
If it was up to me, I'd fix the problem and not the symptom - but many times, it is NOT up to me. MANY times there are artificial constraints (like the time allocated to fix the problem) so you just have to make a band-aid like this. I get grumpy when I'm forced to program a workaround instead of a fix. 😉