LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to test if property has changed?

Is there a simpler way to the attached, to test if a property has changed?

 

I have a vi that closes powerpoint and all the references used along the way. Some are used, some might not be, so I'd like to check and choose which references to close. 

 

 

Thanks  

 

 

 

 

0 Kudos
Message 1 of 9
(3,903 Views)

Hello graham,

 

I am not sure if I understand your question correctly.

 

If I understood you correctly, that you want to find out if a reference was initialized at all, or not. That's simple. Simplified, references are memory addresses. Non-initialized are always 0, whereas used ones have a number >0. See attached example (in LabVIEW 2018 and 2015 code version). However, this comparison is basically what your current code is doing, just on a different level.

 

If this is not the answer you were looking for: What exactly is what you want to optimize? Do you want to get rid of the second case structure?


Ingo – LabVIEW 2013, 2014, 2015, 2016, 2017, 2018, NXG 2.0, 2.1, 3.0
CLADMSD
Download All
0 Kudos
Message 2 of 9
(3,856 Views)

The "Not a Number/Path/Reference" primitive will return true only if the reference is valid. It won't just check if the value is !0. A closer reference will still result in a false.

 

Not sure if that's helpful, to me it's also not entirely clear what the question means.

 

Also, why not just close all references, and ignore their errors? Who cares if a 0 ref gets closed...

0 Kudos
Message 3 of 9
(3,851 Views)

wiebe@CARYA wrote:

 

Also, why not just close all references, and ignore their errors? Who cares if a 0 ref gets closed...


I assume graham either wants to optimize his code, or to see other, "real" errors between all the errors that closing non-references will generate. In his example, both the Invoke node calling Powerpoint and the Close Reference will generate errors. In case he has like 100s of references, I can understand the original question.

 

Graham, can you give us more insight please?

 


Ingo – LabVIEW 2013, 2014, 2015, 2016, 2017, 2018, NXG 2.0, 2.1, 3.0
CLADMSD
0 Kudos
Message 4 of 9
(3,846 Views)

@grahamwebb wrote:

 

Some are used, some might not be, so I'd like to check and choose which references to close. 


It doesn't really matter if the references are used or not. If they are valid (check with Non A Number/Path/Reference) they should be closed. The will only be valid if they are opened properly, and that will probably also mean that they are !0.

 


@ikaiser wrote:

Graham, can you give us more insight please?


 That would be useful.

 

0 Kudos
Message 5 of 9
(3,835 Views)

Hi, 

 

When I come to exit the vi, there might be some references that weren't used and some that were. If I ignore the open ones NI suggests they'll take up memory - https://www.ni.com/en/support/documentation/supplemental/13/closing-references-in-labview.html.

 

So would you normally test and close each one? I've not seen this before.  

 

The attached code isn't complete, but it gives the general idea. 

 

 

Thanks

Graham

 

 

 

 

0 Kudos
Message 6 of 9
(3,783 Views)

Hello graham,


When I come to exit the vi, there might be some references that weren't used and some that were. If I ignore the open ones NI suggests they'll take up memory  


That is absolutely correct, close them all.

 

Regarding the code you posted, you indeed have to either test each reference (as this is done during clean-up of your application, performance should not matter, right?), or try to close them and clear the error that could come up when trying to close non-references (1045) afterwards:

closing references_BD.png

 

 

Apart from that, your code should not run into this issue at all, if you change the architecture of your application. Currently, a user could press your "Next slide" button before "Open" or "Play". What happens in such a case? I don't know. What happens if he/she presses "Open" or "Play" five times? Do you get five references (of which your code will only close the latest one?)?.

I recommend to use a state machine architecture for your code. Only after pressing "Open", "play" is available, and "open" is not available anymore. Only after pressing "play", "next slide" is available. "Close" will perform the correct action(s) needed to close the application from the respective state it is in.


Ingo – LabVIEW 2013, 2014, 2015, 2016, 2017, 2018, NXG 2.0, 2.1, 3.0
CLADMSD
0 Kudos
Message 7 of 9
(3,767 Views)

wiebe@CARYA wrote:

The "Not a Number/Path/Reference" primitive will return true only if the reference is valid. It won't just check if the value is !0. A closer reference will still result in a false.

As the name of the primitive suggests the boolean logic is actually the reverse of what you state. But the principal idea is indeed how to work, if you want to see if a refnum is invalid or not.

 

Also, why not just close all references, and ignore their errors? Who cares if a 0 ref gets closed...


I would recommend that too. Closing an invalid refnum will throw an error in the error cluster but that is usually simply something to ignore. I seldom care if the Close was successful or not.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 9
(3,752 Views)

@rolfk wrote:

wiebe@CARYA wrote:

The "Not a Number/Path/Reference" primitive will return true only if the reference is valid. It won't just check if the value is !0. A closer reference will still result in a false.

As the name of the primitive suggests the boolean logic is actually the reverse of what you state. But the principal idea is indeed how to work, if you want to see if a refnum is invalid or not.


Yes, obviously (head bump). Valid returns false, invalid returns true.

0 Kudos
Message 9 of 9
(3,727 Views)