02-26-2013 10:29 AM
I have to programs that communicate with each other over the network and share many functionalities. Configuration data is stored in FGVs and read where needed. Some of the FGVs are identical in content, so I could use the same subVI (and the VIs that use it) in both programs. The problem is of course that the FGV is shared between both programs as long as they are on the same computer (which is where developement is done). Is it somehow possible to use the same FGV-SubVI but create a separate instance for each program?
02-26-2013 10:38 AM
Yes, you can change the VI's property to re-entrant. That will cause the VI to maintain its own memory space. File > VI Properties then the Execution category. You may want to read the help on the clone options if you have those options in your version. Hint: You want the pre-allocate option for your FGVs.
02-26-2013 10:47 AM
I doubt you want to make the FGV reenetrant. That would likely counter act the reason for the FGV.
I think if you have the two programs in different projects (LabVIEW projects), the execution namespaces should be different. But I haven't tried doing this with two projects pointing to the same file.
02-26-2013 10:50 AM
How would that work? As far as I understood reentrancy then every call has it's own state (even more if preallocated). If I read a config file at the start of the program and write the parsed values into a FGV and later in another part of the program read that FGV, even if it's the same subVI, it's not the same subVI call, so it wont have the values written into it.
02-27-2013 04:15 AM
LabVIEW works based on VI Names. I see two possible solutions:
-Create and rename a copy of the caller VI as well as the FGV. Since the copy will have a different name they will use different parts of memory
-Create a copy and place it into a project library (*.lvlib). All members of project library run in a different namespace so they will use different parts of memory
More Information on project librarys can be found here:
Sharing Code with the LabVIEW Project Library
http://www.ni.com/white-paper/4067/en
Regards!
Moritz M.
02-27-2013 12:57 PM
-Create and rename a copy of the caller VI as well as the FGV. Since the copy will have a different name they will use different parts of memory
That's pretty much what I've got right now. I have two FGVs and VIs calling them, although the datatype and functionality is the same. I know, if you want to reuse code you normally pass the parameters that are depending on the call from the outside. But that's one of the reasons I used the FGVs in the first place. Often there would be the need to get a parameter from the toplevel VI to the "deepest" subVIs, causing wires through all VIs just for that. But you've seen that anyway I guess.
02-27-2013 01:38 PM
Another possible way you can tackle this problem is to use a FGV that supports multiple items. Since your data is the same you could use a variant attribute list, or an array, to store the individual elements. Use a name to access the data you are interested in. Variant attributes work very nicely in this regard since it handles all of the lookup activities for you. This way if you need to modify your FGV you do not have to propagate the changes to all the copies. You only use one.
02-27-2013 02:55 PM
I have handled this in 2 ways-
1. make a master reentrant copy, then make template wrapper and make multiple wrapped versions. Can be a pain to maintain.
2. use OOP and make a class you can put the class inside of a FG and have many instances of the class.
3. if the FG is only used in one place in the code per instance than a reentrant is ok.