LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW class and handling of .net refnums

Hi,

For a new project we will use XML documents to transfer data between different stations. Within the last weeks I was busy in creating the appropriate XML schema files. Today I started the first tests with the System.XML classes of .net 2.0. The validating process works fine and I'm also able to parse the XML to grab some random data. I think that I will use this framework instead of MSXML or the functions which are delivered within the Internet Toolkit.

To get an easier handling and re-usable code I want to create a LabVIEW class which should wrap the .net interaction. Therefor I have to create a private member which holds a refnum from the .net class XmlDocument. All actions like reading and writing set up on that refnum. So I have to be sure that it is initialized correctly. But LabVIEW doesn't have a constructor which can do the initialization. That's why I have to create a method which is called e.g. Init. How can I be sure that developers who will use my class use that method to initialize the refnum? Is that possible or do I have to check it on each call within my methods Read/Write?

What's happen with the refnum if  I don't need the created instance anymore? Does LabVIEW have a garbage collector which closes the .net refnum for me? Or do I also have to do it for myself by calling an additionally added method 'Destroy'?

I'm a bit weird  to do all the things without a constructor/destructor. I hope someone could help me and tell me what's the best way to implement the renum handling.

Regards
Henrik
0 Kudos
Message 1 of 6
(3,895 Views)

I have done this already.  I used the .net MSXML XMLdoc class to both create and parse XML docs it is not too hard but make sure you always keep a reference to the .net object because once it goes out of scope you loose it and it becomes invalid.  To tell if an object has been constructed, you might be able to keep a boolean flag in a shift register.  Are you wrapping each function or are you trying to use an action engine?  The problem with the action engine (functional globals) is the scope of the object.  Other approaches it to see if the object refnum is valid with a method call and trap the error (not sure if you can trap the .net errors silently).

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 2 of 6
(3,890 Views)

My intension is to create a LabVIEW class which handles the needed refnums itself. The XmlDocument refnum will be a private member of my class. So I don't need an action engine (is it the same like a global variable in the LabVIEW2.0 style?) or boolean flags. To check if its a valid refnum I could use the comparision "Not a number/path/refnum?". So each of my member VIs has to do this check first before it operates on the refnum. Each instance of the class has it's own refnum and I don't have to take care about the scope.

Thx for your answer but my questions are still open.

 

0 Kudos
Message 3 of 6
(3,872 Views)

If the programmer does not use the init function you will not have a valid refnum.  This is a programming error which will only be caught at runtime.  One method for forced initialization is to use the first call and have the class initialize the XMLdom with a constructor call.  Are you using the 8.2 class structure?  I haven't played too much with this so I am not sure how the first call works in this.  From a pure OO standpoint you can add an isInitialized class private member.  By default this is false and is toggled true on the init method.  As for garbage collection, the .net references seem to stay active if a caller of the .net node is referenced,  they are collected when their instance is nolonger in LV's mamory (ie pass a wire with the reference throughout the code where the .net is needed).  Good luck, I like the msxml .net library and have found it increasingly used in my code.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 4 of 6
(3,852 Views)
I don't like the way to force developers to use that init function before any other call will be made. But due to the missing constructor this part won't be transparent and he simply has to do it. The first call VI can't be used because than I have to include this check into each of my member VIs of the LabVIEW class. Now I simply dropped a valid refnum check into my Init VI and if it returns false than I create a new reference. Otherwise I call RemoveAll to reset the DOM. And yes I make use of the class feature of LabVIEW 8.20. To your comment for garbage collection: all the collected references will be removed automatically? I think to remember that e.g. for ActiveX components all used references have to be closed manually. Is it different for .net?

You talked about the MSXML .net library already twice. What do you mean exactly? I know about the MSXML OCX which is based on ActiveX and the System.Xml classes of the .net framework but no MSXML for .net.

Thx,
Henrik
0 Kudos
Message 5 of 6
(3,845 Views)

I have not found too much on memory management using .net, but from my experience you can force a manual close of a .net object just as done with active X but I have also found that if a .net object in not referenced and you try to call that instance again you will get an error so I concluded that the garbage collector deallocated this object.  In c# the .net runtime engine is susposed to keep a count of the references to the object, when the grabage collector runs and sees this count =0 then the object is deallocated.  I would guess that if the object is not referenced by any labview vi then the object is marked for outomatic collection as well.  I could be wrong though.  You can also call an objects destructor and invoke the GC but usually ythis is not necessary.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 6 of 6
(3,843 Views)