LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Refnum is No Longer Valid

I am trying to use "Functional Globals" to set up a device driver for a device via a .net driver.

 

The VI in its init state calls the Constructor Node, but the next time the VI is called the .net Refnum is No Longer Valid from the uninitialized shift register.

 

Screen shot 1:Run the VI the first time and get a valid .net reference.

 

Screen shot 2:Run the VI a 2nd time and the uninitialized shift register still contains the pointer to 0x81C00001, but the Refnum is No Longer Valid. 

 

This technique of using uninitialized shift register work for other type of references. It seems that LabView is "helping" me out by clearing my reference when the VI exits.

We had a simular problem with DACmx that is solved by a low level setting telling LabView not to clear refnum on it's on but wait for the close command. Is there also something like that for .net?

 

Thanks

 

Download All
0 Kudos
Message 1 of 23
(7,668 Views)


@OmarGator wrote:


It seems that LabView is "helping" me out by clearing my reference when the VI exits.


Yes, that's correct. When the top level VI in the hierarchy which opened a reference goes idle or out of memory, LabVIEW does garbage collection and closes all open references. The simple (and correct) solution is not to call the functional global by itself, but only to call it as a subVI. Another option is to run it dynamically as a seperate process so that it stays in memory, but that is too complicated.

I don't know the setting you mentioned, but I wouldn't rely on that anyway. There is a setting like that for VISA, but I don't know of one for DAQmx.


___________________
Try to take over the world!
Message 2 of 23
(7,655 Views)
In addition to tst's recommendations, you should also test references carried in uninitialized shift registers for validity before trying to use them.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 23
(7,639 Views)
I have the same problem as described, i.e. a functional global with a .net refnum.
 
I do use it as a sub vi and it works as intended as long as the program is not stopped. Naturally, it is stopped often when I develop my code 🙂
 
To me, the problem is that I have to exit labview completely (including the friendly "getting started" menu), before I am allowed to reinitialise my .net controls.
 
Is there a work-around as to how I may reinitialise the .net control without exiting labview?
Are there any tweaking possibilities for the garbage collection? Might be dangerous, but it would be useful during debugging.
0 Kudos
Message 4 of 23
(7,559 Views)


@mbn123 wrote:
the problem is that I have to exit labview completely before I am allowed to reinitialise my .net controls.

What do you mean by that?

I never had a problem in calling a constructor of a DLL I used previously. In my experience, the only time you need to exit LV is when you want to replace the DLL, and that's because LV keeps a reference to it.

Can you post a simple example demonstrating your problem with exact explanations?

P.S. I use LV 7.0, where embedded .NET controls were not available, so I don't really know about those if that's what you're using.


___________________
Try to take over the world!
0 Kudos
Message 5 of 23
(7,556 Views)


@tst wrote:


@mbn123 wrote:
the problem is that I have to exit labview completely before I am allowed to reinitialise my .net controls.

What do you mean by that?


I haven't tested it completely, but it seems that labview (8.2) handles .net exceptions badly sometimes.

I have succeeded in starting and stopping my labview application, without corrupting the .net object. But most of the time, it is unable to load the object (showing a square around an empty control).  When I exit labview, it (sometimes) gives me an error arising in DotNetDomain.cpp and, at next startup, offers to investigate the error.

The .net controls are fairly buggy, as they are in active development, and I suspect that they fail in a way that is incompatible with labview. I use exceptions in my .net code, and labview reports it properly, but apparently it is not enough.

In my oppinion, it is a bug in labview 8.2. It may be circumvented by proper .net coding, but it is annoying during development.


@tst wrote:

I never had a problem in calling a constructor of a DLL I used previously. In my experience, the only time you need to exit LV is when you want to replace the DLL, and that's because LV keeps a reference to it.

Can you post a simple example demonstrating your problem with exact explanations?

P.S. I use LV 7.0, where embedded .NET controls were not available, so I don't really know about those if that's what you're using.


The first construction of the .net object of not an issue. The "exit labview" part is annoying, but helps avoid other problems.

I am currently converting vb6 activeX component to vb.net, and once you get a handle on how to handle property and method return values, it works nicely. You have easy access to methods and properties. I have never liked ActiveX components, so I recomment the transition.

0 Kudos
Message 6 of 23
(7,547 Views)
Are closing all the .net references before you stop your application? If so, then I would agree that it's a LV problem. If on the other hand you are simply punching the abort button you are creating the problem yourself. Even when doing development, you should stop code in an orderly manner whenever possible.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 7 of 23
(7,540 Views)


@mikeporter wrote:
Are closing all the .net references before you stop your application? If so, then I would agree that it's a LV problem. If on the other hand you are simply punching the abort button you are creating the problem yourself. Even when doing development, you should stop code in an orderly manner whenever possible.

Mike...


I think you are right. Following your earlier remark about uninitialised references, I looked briefly at checking the validity of my .net refnums, but I didn't suceed.

So, how do I check for uninitialised refs and how do I close my .net references?

0 Kudos
Message 8 of 23
(7,535 Views)
To test a reference the Comparison menu contains the function Not a Number/Path/Refnum. Likewise on the .NET menu there is a Close Reference function.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 9 of 23
(7,530 Views)

Mike, the references should be closed (especially .NET references), but even so, LV should do full garbage collection when the hierarchy is destroyed. Without being able to see it, I would guess it is either a problem in the implementation of the .NET control or a bug in LabVIEW.

mbn, to report a bug, select the email option here, and I would still suggest that you upload an actual example.

P.S. For more on .NET in LV, you should check out Brian Tyler's blog (who used to be the head of the LV .NET team).


___________________
Try to take over the world!
0 Kudos
Message 10 of 23
(7,517 Views)