LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

what cast type are used for?

In the example attached to this question is a simple VI application that cast, using type cast of LabVIEW, one value to different other type. My understanding of type cast, in C, C++ and to my best knowledge, was an implicit adaptation of a numerical value in a specific format to an other format. The value should remain the same. Unless the type in which the value is assigned is not enough large or adapted to contain such a number ex:

I8 = 500;
U32 = -1;
...

But in my example all the assigned indicator are large enough.

I have the same problem in LabVIEW 5.1.1 and 6.1
If someone could only tell me what it is used for?

Best regards,

Nitrof
0 Kudos
Message 1 of 3
(2,798 Views)
The type cast function is really helpful for typecasting "unusual" data to a more convienient data format. It can also be used to coerce data, like in your example, but coercion is usually not always a good thing because it can cause bad values.

There are lots of good examples of typecasting.
For example, I use the typecast function to change refnums to unsigned 32 integers (U32), just so I can pass the refnums between VI's easier.

Another VERY common typecast is if you want to display the ASCII value of a character. Run the string character "A" into a typecast, and set the output type as a Unsigned 8 bit number (U8), and you will see 0x41. Take a look at my example VI's to see what I mean.

David
Download All
0 Kudos
Message 2 of 3
(2,798 Views)
All a type cast does is tell LV to interpret a specific value in a different way. For example, casting a -5 as a U16 (which isn't valid anyway: no negative values) LV interpretes the bit pattern contained in the input value--or at least the first 16 bits of it--as a U16 and comes up with the correct answer: 65536

In the same way, LV tries to interpret the I32 bit pattern for -5 (1111111111111111111111111111011)as a value of each of the types you specified.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 3
(2,798 Views)