LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
christine123

Programmatically change numeric (FXP) information during run time

Status: New

It would be useful if you could change the numeric (FXP) information (signed, word length, integer word length) of a data type during run time.

Since all diagram types must be known at compile time, there is no way to dynamically decide the type of a wire. Variants are the only way to handle dynamic types at runtime. However, variants do not expose any way to take data of one type and convert it to a different type within the variant.

 

This functionality would be useful for example, if you use the 'Get Fixed-Point Information - NI VI' to extract fixed-point numeric (FXP) information from a data type stored in a variant, and then could use that information to caste it into a variant. This is solved in the image attached using a case structure, but this is not a very elegant solution. 

 

image003.png

5 Comments
Intaris
Proven Zealot

Just have Variant be the output of your case.

Then handle the individual types within.

christine123
Member

Hi, if I understood you correctly, I would still have the issue of a large case structure within the VI:

 

christine123_0-1693816917010.png

 

wiebe@CARYA
Knight of NI

Set Fixed-Point Information (same dir as the get, use CTRL+i to get it's path) creates a fixed point data type variant with given properties: 

 

Set Fixed Point Variant Type.png

 

At a glance the variant to data seems to convert as expected.

 

In this example, it's rather silly (the output variant is the input variant), but the fixed point data can be modified, for instance to output a fixed point with higher resolution.

christine123
Member

Thank you! I could not find the Set Fixed-Point Information vi, and I could not find any documentation on it online.

raphschru
Active Participant

Hi Christine,

 

While "Set Fixed-Point Information" can change the FXP representation in a variant, this is not helpful in your example, because it only acts on the type, but erases all data contained in the variant.

 

Here is how I would do for your example, using "Get Fixed-Point Information" and the flatten/unflatten functions:

Convert Double to Variant Fixed-Point.png

 

The "False" case of the leftmost structure has the same code, but with a "to U64" instead of a "to I64".

The "False" case of the rightmost structure is just a pass-through wire.

 

Here I first compute the internal 64-bit integer that is equivalent to the FXP value by shifting the decimal place of the DBL value by the size of the fractional part in the FXP type. Then I add the overflow status if present (always set to OFF), then I rebuild the variant from the raw data and the type code of the given FXP type.

 

Regards,

Raphaël.