Ir al contenido principal

Entradas

Mostrando entradas de diciembre, 2017

Coerce to Type

I'm surprised the Coerce to Type primitive hasn't found yet its way to the public front. It was revealed some years ago and since then has proved being a reliable way of converting data types, much better than the classic Type Cast, but it's still not visible in the LabVIEW functions API.Consider the following code example. You're casting an U32 value (2) to U8 (you shouldn't, but shit happens). Type cast just casts it, so the resulting value is 0 (wrong!), but Coerce to Type understands what you are doing and returns 2 (correctly).To use Coerce to Type in your VIs, the easiest way is downloading the VI below into your drive.Download (VI for LabVIEW 2016)Next we're going to place it in the functions palette. So, open any block diagram and click Tools → Advanced → Edit Palette Set. Then select the palette you want to add the VI into (in this case I recommend Programming → Numeric → Data Manipulation) and click Insert → VI(s) and select the path to the VI.Now, im…