LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Keeping the .Net refnum alive for calling methods

I am working on a Labview project that provides an user freindly interface to methods and
properties that a .Net assembly provides. I created an Initialization.vi that calls the
class constructor and on its output terminal it returns the .Net refnum for the class.
Al my vi's basically take this .Net refnum as an input and passes it right back out as is,
so that the vi's can be used in a daisy chain fashion. I did verify that things work as they
should be when I daisy chain them. But my problem is that I can't daisy chain the vi's, I am
creating an HMI that will show examples of almost all of my supported vi's with button press.
An event structure is the right choice in this case and I want to use it just like another
another C dll based project that I worked on.

I tried many ways to pass the .Net refnum back to other vi's that execute in different time
frame by the user's button press event, but I could not get anything to work. It almost
seems like I have to call the constructor for every little vi's that uses the class method,
but then things will not work properly because a constructor will re-initialize some of the
private members that other methods depend on. Is there any work around for keeping the refnum
alive? I really want to use the event structures for button press events, and if its
possible to somehow pass the refnums thru event structures and call the class methods
off of it, that would be terrific.

Thanks a lot for reading this big problem description.

Ratin
0 Kudos
Message 1 of 4
(2,805 Views)
Hi Ratin!

It doesn't sound like you're having any trouble specific to the .NET refnum datatype, but just passing data in general between event cases in the Event Structure. If that's the case here are a couple suggestions:

1) I'm assuming you have an Event Structure inside of a while loop. If this is the case, the best way to "keep" the refnum would be to attach it to a shift register on the side of the while loop (right-click the side of the while loop and choose "add shift register"). Once the refnum is produced, you can write it to the shift register. Note: Make sure to initialize the shift register AND make sure to pass the refnum through in each event case.

2) Another method would be to write the refnum to a local variable and then read from a corresponding local variable when you need it.

Usually it is best to avoid local variables when possible, and in this case it is easy to avoid (using method 1), so I would go with method 1!

Hope this helps!

Travis H.
National Instruments
Travis H.
LabVIEW R&D
National Instruments
0 Kudos
Message 2 of 4
(2,787 Views)
Thanks Travis, I was trying the 1st method all along (even structures), I did add the
shift registers but I didnt pass it along for all events (specially the timeout event)
so what happenning was as soon as first timeout hapenned, the refnum got invalid and
I started getting error. Anyways everything is working now, thanks a lot for your help.
By the way I was wondering if its possible to add an even structure case which will be
executed when two or more controls change value. For example two buttons executing the
same event case. Is it possible?

Thanks

ratin
0 Kudos
Message 3 of 4
(2,772 Views)
Hi Ratin!

I'm glad you got everything working with the Refnum issue!! Let me make sure I understand your second question. You have two (or more) controls on your front panel, and if the user changes the value of either one of the controls you want to be able to execute Event X. Basically, you want to be able to configure more than one Event for a single Event case, right?

If this is the question, then, of course you can! 🙂 Just right-click on the Event Structure and choose "Edit Events Handled by this Case". Then at the top of the window, click the "+" button. This will allow you to configure another Event for the same Event Case!!

Hope this helps, Ratin!

Travis H.
National Instruments
Travis H.
LabVIEW R&D
National Instruments
0 Kudos
Message 4 of 4
(2,762 Views)