From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Default values of cluster created from an empty Variant

Good Evening,

 

I am passing an empty Variant into the "Variant to Data" Function, and with a Type Deffed Cluster as the input to the type field, as shown below. The Type Deffed cluster has "Invalid" set as the default data for the type enum contained in the cluster, although not the 0 value in the enum.

 

When an empty Variant is passed into the function, the outputted cluster doesn't have "INVALID" as the type data. I was expecting INVALID to come out as it is the default option on the cluster. 

 

Whilst I can check for empty cluster before converting to data, am I experiencing known LabVIEW behaviour?

 

Regards

 

M

Download All
0 Kudos
Message 1 of 14
(2,815 Views)

You cannot use variant to data unless the variant data contains the matching data structure. Just use a small case structure wired to the error out and return either the converted cluster or your default cluster.

 

(the upper input specified the "type", not any default values)

Message 2 of 14
(2,801 Views)

Easiest would be to ensure that the variant contain proper and expected data, so change the subVI before it.

Message 3 of 14
(2,774 Views)

@Munchuk wrote:

 

I was expecting INVALID to come out as it is the default option on the cluster. 

That's the problem of course. It doesn't say anywhere that the "type" input is the default output. Not sure why it isn't the default, or if the output is defined when there is an error.

0 Kudos
Message 4 of 14
(2,750 Views)

wiebe@CARYA wrote:

@Munchuk wrote:

 

I was expecting INVALID to come out as it is the default option on the cluster. 

That's the problem of course. It doesn't say anywhere that the "type" input is the default output. Not sure why it isn't the default, or if the output is defined when there is an error.


I would be guessing it would be the "default-default".

 

That function checks that the variant passed to it is of the proper type and throws an error if not. If the data in the variant wire is the wrong type, the output would be empty since the operation is skipped completely. Sorta like the case of a VI set asn sub-routine and the instance marked as "skip if busy". The data returned when the sub-VI is called when it is busy is the "default default".

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 14
(2,742 Views)

wiebe@CARYA wrote:

That's the problem of course. It doesn't say anywhere that the "type" input is the default output. Not sure why it isn't the default, or if the output is defined when there is an error.


Of course the "type" of the output is fully "defined" at compile time. (You get the same wire as whatever you wire to the type). No idea what the "value" would be. What are the default values of the typedef itself? Maybe that's what you should try.

 

(Yes, the value of the wired constant could probably be defined as the default output, but I guess it's not. Not sure if there would be side effects)

0 Kudos
Message 6 of 14
(2,736 Views)

I'm pretty sure the problem here is that you're under the impression that the default value of a type definition is what LabVIEW uses for a default value anywhere.

 

It *IS* the default value when you put a constant on the block diagram, or whatever.

It *IS NOT* the default value when LabVIEW has an error but needs to put something on the wire anyway.

 

When you have a type definition, the default value whenever there's an error is the "LabVIEW default"... empty arrays and strings, and zeroes for all numerics, including enums. 

 

If you want to have this pass out your "alternate" default, you need to do one of two things:

1. Manually look for error 91, and when it occurs, wire out your altered default cluster.

2. Change your type definition to a LVOOP class.  LVOOP classes actually do have their default values kept as part of their type definition.

Message 7 of 14
(2,724 Views)

@Kyle97330 wrote:

 

If you want to have this pass out your "alternate" default, you need to do one of two things:

1. Manually look for error 91, and when it occurs, wire out your altered default cluster.

2. Change your type definition to a LVOOP class.  LVOOP classes actually do have their default values kept as part of their type definition.


Or make the 'invalid' enum value the first value of the enum. That would return 'invalid' as default in case of error. Better put some text comment there though...

0 Kudos
Message 8 of 14
(2,693 Views)

As mentioned in other words, Variant to Data only cares about the data types of your connected Type, not the values. 

You'll have to create the 'default data' like Altenbach mentioned.

Variant to data.png

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 14
(2,685 Views)

@Yamaeda wrote:

As mentioned in other words, Variant to Data only cares about the data types of your connected Type, not the values. 

You'll have to create the 'default data' like Altenbach mentioned.

Variant to data.png

/Y


Or make the 'invalid' enum value the first value of the enum. That would return 'invalid' as default in case of error.

0 Kudos
Message 10 of 14
(2,680 Views)