LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Typecasting References...

Solved!
Go to solution

Hello,

 

I have the following VI:

 

broken vi in rt engine.PNG

 

The reference coming from the Call by Reference VI is of type VI Reference. The Diag Data Ref is a custom type that is really just a VI Reference type underneath, same as what is coming from the Call by Reference VI. Is there a way to "typecast" the reference coming from the Call by Reference VI in to the Diag Data Ref, being that that destination ref type is really the same type underneath. Hope I worded this correctly.

0 Kudos
Message 1 of 9
(4,719 Views)

It would surprise me if typecasting a reference in the situation you describe would ever work.  There are other examples where the type seems valid, but an important detail is missing.

 

You can fix it by deleting your TypeDef'ed Indicator, right-clicking the Ref Out terminal and choosing Create Indicator.  You'll need to use exactly this Wire (or, I suppose, you could create a TypeDef for it, as well) for anything that needs to use it.

 

Bob Schor

0 Kudos
Message 2 of 9
(4,713 Views)

The thing is if I change the indicator type I will have to change inputs and outputs for other VIs that depend on current Diag Data Ref type. Just trying to see if there is a way to make this correction as small as possible...

0 Kudos
Message 3 of 9
(4,696 Views)

To make output terminal a general VI ref (not strict), right click it, select VI server class -> VI -> VI.

 

You can typecast strict vi ref to any vi ref, but you will loose connection panel information, you will not be able to use some functions that require ref to be strict.

 

I would make the output of the VI a strict ref that matches the type: right click it, select VI server class -> Strictly typed VIs -> correct connection panel pattern picture. Then it can be used later in program both by general functions  and by specific functions.

Bob's way gives the same result, but ref terminal will change its name and will not be connected to panel as VI output.

 

 

0 Kudos
Message 4 of 9
(4,691 Views)
Solution
Accepted by topic author swbpnole

The solution was to simple update the base types underlying the custom types.

0 Kudos
Message 5 of 9
(4,668 Views)

@Alexander_Sobolev wrote:

 

You can typecast strict vi ref to any vi ref, but you will loose connection panel information, you will not be able to use some functions that require ref to be strict.


While you can typecast a specific VI reference to a more generic one, doing the opposite was explicitedly disallowed around LabVIEW 8.6 or something like that. So once generic you can't get it (easily) back to the more specific one in order to do a Call By (Async) Reference.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 9
(4,614 Views)

I had an array of string indicator references and wanted to add a ComboBox reference to it.  I used the typecast function to cast the ComboBox reference to a simple string indicator reference and then reversed the process before using the reference to modify the ComboBox programatically.  I don't know if this is a good practice but it seemed to work well.

0 Kudos
Message 7 of 9
(2,111 Views)

@skinnedknuckles wrote:

I had an array of string indicator references and wanted to add a ComboBox reference to it.  I used the typecast function to cast the ComboBox reference to a simple string indicator reference and then reversed the process before using the reference to modify the ComboBox programatically.  I don't know if this is a good practice but it seemed to work well.


The "correct" way to do this would have been to use the  "To more specific class" and "to more generic class" nodes.  String is the parent of Combobox in the GObject hierarchy, so they share almost all properties:

Kyle97330_0-1666387611690.png

Because of this relationship, the type cast works just fine even though it's misleading and doesn't have error wires on it for detecting if you ever tried to downconvert a string control to a combobox.

 

In the case of VIs vs. strictly typed VIs though, they are separate on the hierarchy:

Kyle97330_1-1666387891740.png

So they can't be converted with the class-based conversion nodes.

0 Kudos
Message 8 of 9
(2,082 Views)

Great!  I'll use that from now on.

0 Kudos
Message 9 of 9
(2,075 Views)