LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using type defs

Solved!
Go to solution

I hoped to not have to ask this questiona nd find the answer myself, but no luck...
In a pop-up subvi, I can click some buttons to activate channels on an instrument. In another part of the program, I need to know which channels are active. I store an array of active channels in a type def in my project. (For example, a device has 10 channels and only number 2 and 4 are active, I store:  F T F T F F F F F F). To use the type def in the program, I drag and drop the .ctl file from the project explorer onto the vi. Here I check if the array is empty and if it is not, do some stuff. However, the array seems to always be empty...?! It seems as if the type def doesnt get updated. How can I fix this?
Please see the attached zip. The type defs are written to in SettingsPopUp.vi and they are read in WriteSpectrumToFile.vi
Many Thanks
Doug

0 Kudos
Message 1 of 6
(4,781 Views)
Solution
Accepted by bockdoug

A typedef is not the same thing as a global variable.  It does not automatically update data values.  A typedef is used to define custom data types.  A strict type def controls the appearance of the data type.  You will still need to pass the data value to and from your subVI using the terminal pane connections. 

aputman
Message 2 of 6
(4,773 Views)

What you are doing is missusing a type def.  Type defs are not really for sharing data they only define the data type not the value.

 

what you are looking for is an Action Engine aka Functional Global Variable or LV2 global


"Should be" isn't "Is" -Jay
Message 3 of 6
(4,766 Views)

Type Definitions (known as TypeDefs) are ... Type Definitions.  They define a type using a name that you choose and are used as a convenience and reminder to you.  For example, if you wanted to save Temperature as a "named Type", you could create a TypeDef called, say, Temp.ctl and make it a Double-Precision Float.

 

TypeDefs are especially useful for more complex types, such as Clusters and Enums.  Good LabVIEW Practice is that every time you define a Cluster (a collection of variables, each named and each having its own Type, which can include Arrays, Clusters, Strings, Integers, etc.) or an Enum (an "Enumerated Type", for example, a variable that takes on the values "Red", "Orange", Yellow", "Green", "Blue", "Indigo", and "Violet"), you create a corresponding TypeDef so that you can easily refer to variables of this type later in your code.

 

In your case, you have a Boolean Array that represents Active Channels.  You could create an (empty) Array of Boolean, make it a TypeDef called "Active Channels", then drop a Control or Indicator (depending on your use) of type "Active Channels" and load them up with the values F T F T F F F F F F.  You now have a Wire that holds the Active Channels, which you can save in a Shift Register somewhere, or create a Variable called "My Active Channels" of type Active Channels and hold the results there.

 

Do you get it?  If not, try creating and playing with TypeDefs, look up TypeDefs in the LabVIEW Help, and ask questions.

 

Bob Schofr

Message 4 of 6
(4,763 Views)

Ah ok. I think I get Type defs now. They are not used to store data, but rather to store the data placeholders ("data types"). So type defs make it easier to use clusters across multiple vi as all the "variables" are already in the type def. Very subtle difference, indeed.
Many thanks to you all.

Message 5 of 6
(4,749 Views)

Not very subtle at all, but you seem to get it. 🙂

If you're used to C-derivatives, a Type def is a named Struct{} and you were creating a 2nd instance of the same type.

Quasicode:

 

Struct {

  int a

} NamedStruct;

 

//First use of typedef

NamedStruct X = {3};

 

//Second use of typedef

NamedStruct Y; //Strange, This has a 0 value ...

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 6
(4,714 Views)