06-20-2007 11:56 AM
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
06-20-2007 12:54 PM
@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.
06-20-2007 07:06 PM
07-23-2007 04:15 AM
07-23-2007 04:45 AM
@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.
07-23-2007 05:12 AM
@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.
07-23-2007 07:28 AM
07-23-2007 07:35 AM
@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?
07-23-2007 07:41 AM
07-23-2007 11:55 AM
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).