LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange Problem - Cluster of References

Solved!
Go to solution

Hello guys

 

I had a strange problems using a cluster with references.

 

How to reproduce the problem:

 

- open a blank VI;

- create two graphs in the front panel;

- in the block diagram, create references for both graphs;

- connect these references to a bundle (not bundle by name);

- create an indicator for the bundle;

- run the VI once;

- right click on the bundle indicator and change it to a control;

- delete references and bundle;

- select the control in the front panel, go to EDIT, CUSTOMIZE CONTROL;

- change to strict type def;

- save this control as Control1.ctl;

- connect the control to a unbundle by name;

- right click on the unbundle by name and select one of the two graphs as an item (doesn't matter which one you select);

- create a property node and feed its reference terminal with the reference from the unbundle by name;

- use the property "Label.Text" in the property node;

- create an indicator for the the property node;

- run the VI;

- the indicator will show the correct label for that graph;

- perfect!!!

 

 

If you save the VI and run it again, everything is fine.

 

But............... if you close it, open again and run.... you will get an error 1055 "Object reference is invalid".

 

Why it was working before closing?

 

Find attached the VI and the Control.

 

Thanks

 

Dan07

Download All
0 Kudos
Message 1 of 8
(10,545 Views)

I would not expect this to work after a save.

 

What are you actually trying to achieve with this? Maybe there is a better way.

0 Kudos
Message 2 of 8
(10,519 Views)

I have a Main VI with several indicators and controls. This Main VI has a lot of SubVIs with small pieces of code and sometimes I need the references of some of the indicators or controls to access information by property nodes. I am trying to create a cluster with all references, set this cluster as a Strict Type Def and use copies of this cluster in each SubVI (to have all of them updated at the same time, if the original one is modified).

 

 

0 Kudos
Message 3 of 8
(10,514 Views)

Create the ref, bundle it and pass it to the sub-VI to use.

 

I think you got away with that trick but under normal conditions I would have bet againts it working.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 8
(10,476 Views)

Ben, I understood what you said but I would like to use a cluster (saved as strict typedef) with all references because I have several subvis and would be great to have this cluster connected to all the subvis, and each subvi having a copy of this cluster (as a control), as the input of the subvi. If I update the cluster with the references, all controls in all subvis will be updated too, since they are all connected to the same strict typedef.

 

Nevertheless, this works great until I close and open again the main VI. After that I start getting a lot of "Objetct Reference invalid" messages.

 

I changed a little bit my procedures. Here are the steps that I am following:

 

 

- open a blank VI;

- create two graphs in the front panel;

- in the block diagram, create references for both graphs;

- connect these references to a bundle (not bundle by name);

- create an indicator for the bundle;

- run the VI once;

- right click on the bundle indicator and change it to a control;

- delete references and bundle;

- select the control in the front panel, go to EDIT, CUSTOMIZE CONTROL;

- change to strict type def;

- save this control as Control1.ctl and close it;

- convert this control into a constant;

- right click on this constant and create some controls from this constant;

- Put these controls (that were created from the constant of the main VI) into the subvis (to be the control connected to the input terminal of the subvi);

- connect the constant of the main VI to all these subvis;

- inside each subvi put some property nodes to get information from the references (i.e. Label.Text);

- run the main VI.

 

Everything works great. The constant that is linked to the Control1.ctl (strict typedef) will feed all the subvis (that have controls created from the constant of the main VI, and because of that all these controls are also linked to the Control1.ctl (strict typedef). All the subvis run their codes properly.

 

but........................................................

 

If I save the main VI and all the subvis, close everything and open again the main VI and run it, I get a lot of 'Object reference is invalid messages'.

 

Why?

 

Why it was working before?

 

 

This code is very important for me because since I have a lot of subvis, if I have a constant into the main VI (as s strict typedef) with all the references, and copies of this constant into each one of the subvis (as controls), when I update the main constant into the main VI (adding a new reference for a new object that I've just created, for example), all the controls inside all the subvis will be updated properly.

 

What am I doing wrong?

 

Thanks

 

Dan07

Message Edited by dan07 on 04-12-2010 10:49 PM
0 Kudos
Message 5 of 8
(10,447 Views)
Solution
Accepted by dan07

Let see if I can answer before I have to start working.

 

Do a quick experiment.

 

Use a Type cast to cast your ref as a U32 and show that value on the FP.

Save the VI run it and record the number on the FP.

Mod the vi save it clsoe it open it and run again. The number should have changed.

That is the issue you facing, the ref number changes so you need one that is valid when you run.

 

How I do it;

 

I use an Action Engine (see this Nugget to learn what an Action Engine is) that servse as a GUI controller and lets me get at refs where even I need them. The following is a case study.

 

 

First I collect all of th refs I will need and bundle them in a type def. I sue a state machine to do the bundling if there are a lot.

1_Bundle_Refs.PNG

 

THe bundled clsuter get passed to an GUI Controller Action Engine

 

2_Init_GUI_Controller.PNG

 

Inside the Init I check the refs to make sure they are vlid. THis has saved a lot of wated time chasing invalid refs. Smiley Wink

 

3_Check_Valid.PNG

 

If they were valid I cache the refs.

 

4_Cache_Refs.PNG

 

For major mode changes that demand a lot of GUI punching I create sub-VI to do the dirty work.

 

5_Set_Visability.PNG

 

When ever other codes needs a ref to the GUI I have a method that returns the refs.

 

6_Get_Refs.PNG

 

THe following shows another VI using those GUI refs.

 

7_Get_Refs_In_Use.PNG

 

I hope that helps,

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 8
(10,412 Views)

Ben

 

Thanks for the help. I did something very similar to your first picture and my code is working very well.

 

Dan07

0 Kudos
Message 7 of 8
(10,313 Views)

This is a very help post however I cannot find the example code. 
In MVS_Test.vi

1. In upper left, box says Gui Refs. Is that a control or VI

2. what are the other states?

In Analysis_Mode.vi: 

1. You have a vi with icon "get refs". Why not use use the Gui_Controller_Core.vi action engine to get the refs?

2. You show and event handler for the unbundled control events. What happens if more than one subvi acts registers on the same control's event?

 

Could you post it?

0 Kudos
Message 8 of 8
(1,474 Views)