From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SI Notation in Scan Value and Scan from String issue

I was a bit surprised when I found out that the Scan Value function will not scan the SI unit prefix when there is characters following the SI prefix.  For example in the following snippet I expected the output to be a double value of 0.205 and remaining output string to be "A" but is stops before the "m" in its scan and provides 205 with "mA" remaining.  It does scan the "m" if there isn't anything after it in the imput string. Is there something else I should add to the format string?  Would this be considered a bug?

0 Kudos
Message 1 of 14
(5,915 Views)

if you try to type '205mA' into a numeric control or indicator, it will revert to the default value.

 

You will need to remove the units and leave only the value and SI magnitude.

 

SI standard formatting normally places a space between the value and units (magnitude is prefix to units).

 

This example should work for other locales where the , is used as the decimal separator 

 

si.png


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Message 2 of 14
(5,893 Views)

@Phillip Brooks wrote:

if you try to type '205mA' into a numeric control or indicator, it will revert to the default value.

 

You will need to remove the units and leave only the value and SI magnitude.

 

SI standard formatting normally places a space between the value and units (magnitude is prefix to units).

 

This example should work for other locales where the , is used as the decimal separator 

 


Why is that true for the %p format and not for the %e?  I would expect this example to produce the same value after the scan but they don't.  Why does the %p scan stop if there is anything after the magnitude?

 

0 Kudos
Message 3 of 14
(5,887 Views)

Hi Paul, this is also Paul, with National Instruments.

 

http://zone.ni.com/reference/en-XX/help/371361G-01/lvconcepts/format_specifier_syntax/

 

http://zone.ni.com/reference/en-XX/help/371361G-01/lvhowto/characters_numeric_control/

 

It looks like your problem is that your A for Amps is not recognized as an accepted character per the second link.

 

As you stated, with A removed the function works correctly. Are you always expecting a unit on the end of the string?  If so could you not just remove the last character?

 

Per the way our functions are set up to handle this syntax, I do not see this as a bug.  It may be worthy to submit to our idea exchange if you would like this implemented as a future feature:  http://ni.com/ideas

Paul Davidson
National Instruments
Product Owner - ni.com Chat
0 Kudos
Message 4 of 14
(5,854 Views)
0 Kudos
Message 5 of 14
(5,846 Views)

Paul,

 

I am currently in the process of looking into this further.  It seems like it may be unexpected behavior, but I will dig a little deeper and see what I can find.  

 

Thanks for your feedback!

 

Drew T.

Drew T.
Camber Ridge, LLC.
0 Kudos
Message 6 of 14
(5,781 Views)

Thank you, and all please excuse my bad attitude in my previous post.  Just a little frustration venting.

0 Kudos
Message 7 of 14
(5,772 Views)

Paul,

 

I have spoken with several LabVIEW experts on this issue, and have determined that this is not unexpected behavior.  When the Scan Value function looks at the string, it takes all of the characters after the number and compares them to its know list of SI prefixes.  It does not search character by character.

 

However, I can see where this might be useful and would encourage you to post it on the Idea Exchange as Paul D. suggested earlier.

 

You could look into the Format into String function to account for units.  See the {Unit} tag in the following link for more info.

 

http://zone.ni.com/reference/en-XX/help/371361G-01/lvconcepts/format_specifier_syntax/

 

Best

 

Drew T.

 

 

Drew T.
Camber Ridge, LLC.
0 Kudos
Message 8 of 14
(5,745 Views)

I have spoken with several LabVIEW experts on this issue, and have determined that this is not unexpected behavior.  


 

Well I didn't expect it.  I actually could not find an good example of %p in the help examples but did find examples for %e and %f as in here and here.  So, can you answer this; if I can expect (for scaning %e):

 

 

 

stringoffsetdefaultoffset past numbernumberComments
–4.7e–3x 0 0 7 –0.0047 x is not allowed, so conversion stops there.

 

 

why can I not expect 200mX to equal 0.200 when scanning %p?

 

 


... When the Scan Value function looks at the string, it takes all of the characters after the number and compares them to its know list of SI prefixes.  


Yes that seems to describe the behavior but in my opinion that implementation was very short sighted and also doesn't seem to fit with the other format specifiers (like %f and %e). 


You could look into the Format into String function to account for units.  See the {Unit} tag in the following link for more info.

 

http://zone.ni.com/reference/en-XX/help/371361G-01/lvconcepts/format_specifier_syntax/


{Unit} (optional) Overrides the original unit of a VI when you use a function to convert a physical quantity (a value with an associated unit). You must use a compatible unit. You can use this syntax element only with the Format Into String function.

 

Thought for a second that this might work for me but read the fine detail...  I need to scan from string not format to string.

0 Kudos
Message 9 of 14
(5,739 Views)

One more example of "expected behavior"...

 

Personally I would expect the follow three outputs to produce the same value when executed.  Wouldn't you?

 

 

0 Kudos
Message 10 of 14
(5,738 Views)