LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How let labview to verify string is in Scientific Notation.

Solved!
Go to solution

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

0 Kudos
Message 1 of 6
(4,162 Views)

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...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(4,160 Views)
I know my problem is the serial port handling, but it is an old program, so I just wanted to make a check that all data is there, and if it isn't to make the log frequency slower.

My idea was also to check for the E's, but still something could go wrong there.
For Example:
+1.50337800E+10 is the value is wants to send but you only get +1.50337800E+1
this again results in a bad read value....
0 Kudos
Message 3 of 6
(4,152 Views)

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...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 6
(4,150 Views)
Solution
Accepted by topic author Bart_Aerts

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

 

0 Kudos
Message 5 of 6
(4,141 Views)

@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.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 6
(4,119 Views)