LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can we initialize type definitions?

Solved!
Go to solution

Good day!

I made a type definition with a cluster. In that cluster I put default values as init. That default data is not passed to the VI I placed the typedef in, no matter if the cluster is a constant or control. And of course it's still connected to the type definition.

 

Wrong thinking?

 

P. S. I noted that when setting to hide controls/indicators which are connected to a typedef they won't hide. Normal?

0 Kudos
Message 1 of 10
(1,411 Views)
Solution
Accepted by MaSta

@MaSta wrote:

Wrong thinking?

 

P. S. I noted that when setting to hide controls/indicators which are connected to a typedef they won't hide. Normal?


Values nor properties are defined in the type def. Only the type is.

 

You can include properties, if you make it a strict type def.

 

If you want a value, either make a VI with a constant and indicator or an indicator with default values. Or a global of course (you still need to make the values default or set the value before reading it).

Message 2 of 10
(1,405 Views)

Hi MaSta,

 


@MaSta wrote:

Wrong thinking?


Yes.

After all it's a "type definition", but not a "type and value definition"!

 

Create a small subVI to output the typedef with your default values…

 


@MaSta wrote:

I noted that when setting to hide controls/indicators which are connected to a typedef they won't hide. Normal?


So you place the typedef'd cluster on your frontpanel and choose "Hide control" in the block diagram, but the cluster isn't hidden afterwards? That would be "not normal"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 10
(1,403 Views)

Hmm, what to do? The reason to use a type definition is that changes on it will be submitted to the placed copies immediately, as long as they remain connected. Using a sub VI with a cluster that's connected to the typedefl would allow to initialize the cluster but wouldn't submit changes to the typedef outside of the sub VI, plus I could only use it as control. OK, better than nothing.

 

0 Kudos
Message 4 of 10
(1,388 Views)

Hi MaSta,

 


@MaSta wrote:

The reason to use a type definition is that changes on it the datatype will be submitted to the placed copies immediately, as long as they remain connected. Using a sub VI with a cluster that's connected to the typedefl would allow to initialize the cluster but wouldn't submit changes to the typedef outside of the sub VI would also forward all datatype changes, plus I could only use it as control/indicator/constant.


I don't understand your problem!

 

  • When you need one (1) default value for your cluster you can use a subVI.
  • When you need more than one (>1) "default" values for your cluster then you can use a subVI with an enum input to select the value…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 10
(1,383 Views)

The weird thing is, when I place the typedef (*.ctl) on a block diagram, LV turns it into a cluster constant - with the initialized values in it!

So it actually works, but somehow didn't a few hours ago when I started the topic.

0 Kudos
Message 6 of 10
(1,349 Views)

LV uses the current values when you create a new constant. These values are fixed for a constant.

 

If you create a control, it has the current values too, but these values are not the default values. So after a reload, the values can be different.

 

If you update the values in the type def, the values don't usually get an update.

Message 7 of 10
(1,339 Views)

Hi MaSta,

 


@MaSta wrote:

The weird thing is, when I place the typedef (*.ctl) on a block diagram, LV turns it into a cluster constant - with the initialized values in it!


It may take the current values of the typedef at the creation time of the constant, but it should not change the values when you change the default values within the typedef…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 10
(1,334 Views)

I think LabVIEW has gotten better since LV 2012(?) with typedefs because now if you change a typedef and the default values change, it will have a dialog with the list of changes that are in mmemory and you can go to each one and see if the value it chose is correct or not.  But I think it is still a good idea to explicitly set a value in a clustered typedef by bundling that value instead of changing a value in a constant.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 10
(1,325 Views)

Something to consider here is that if you were to use a class instead of a cluster, the default values of the class private data are part of the class definition, so putting down a class constant would always get you the same set of default values that update everywhere at once.

 

You also get some other benefits (special class wire type, inheritance options, etc.) but it loses some (can't edit values on a block diagram constant any more) and some that are both good and bad (can't use bundle/unbundle and so have to make accessors, but accessors can sometimes be more helpful in the end).

0 Kudos
Message 10 of 10
(1,306 Views)