10-30-2015 03:10 AM
Hi there
I am currently having a "Call by Reference" subVI problem. I am currently working on a datalog VI that takes a cluster (masked as a variant) and writing the elements to a text string. If the cluster contains a cluster the datalog VI calls itself. When all elements are written to text string it is written to a file and the text string is cleared.
Here i am in need of reentrant execution - so i am currently using "shared clone reentrant execution" VI property and a "Call by Reference" with "Reload at each call" to call the VI from it self. This has been working untill fine, but yesterday after ~5 hours the program got stuck at "Call by Reference". Have I set it up correctly?
Regards
Mark
Solved! Go to Solution.
10-30-2015 04:32 AM
I don't know if you set it up correctly (and it's certainly not easy to tell without code), but I would suggest using existing code rather than reinventing the wheel. Both OpenG and MGI have open source toolkits for saving clusters to INI files, so I would suggest using those.
10-30-2015 08:05 AM
My Crystal Ball that I normally use to look at Poster's VIs so that I can help them find solutions to their problems is having a "Cloudy Screen of Death" today. Could you help by posting your VI (or, if you have several, Zip them together and post the .ZIP file)?
I've written a number of reentrant VIs (I love recursion, when it is appropriate), but I'm not sure I've ever written one using Call by Reference (and I'm even less certain why I'd do it that way). When you do post code, be sure to let us know in sufficient detail what you are trying to accomplish.
Bob Schor
10-30-2015 09:29 AM
My best guess is that you've hit a circumstance that you haven't anticipated in your code and it is recursing indefinitely.
Perhaps an error was thrown and that prevented your recursion from exiting.
11-02-2015 01:27 AM
Hi there!
I have searched the OpenG library but I couldn't find anything that matched my needs for far 🙂
I have attached my code - it requires the Cluster Toolkit 1.0.0.10 from VI package manager - other required/modified files are attached.
There is no check of how many calls it makes but the logging data doesn't change during the operation.
11-02-2015 03:19 AM
The OpenG VIs are in the variant configuration VIs package. The MGI ones are called Read/Write Anything. I haven't looked at your code closely (analyzing recursive calls is not my idea of fun and I don't have the package you're using), but one obvious difference between it and the OpenG code is that the OpenG code explicitly manages the VI references (it has to, because it was written years before LV had native recursion).
11-02-2015 07:14 AM
Mark,
This sounds like a straight-forward recursion problem that should be very simple to solve, needs only "simple recursion" with no need for call by reference, no need for OpenG, but could be easily handled by the Hidden Gems in vi.lib (also part of the LabVIEW Tools Network, accessible using VIPM).
Before I dig myself into a hole solving the "wrong problem", can you tell me if this is what you want --
Given a Variant, list all of its elements by Name and Type. If the Type is a Cluster, list all of the elements of the Cluster by Name and Type.
If this is what you want, I think it can easily be accomplished, and will give it a try.
Bob Schor
11-02-2015 08:55 AM - edited 11-02-2015 08:55 AM
The input is a cluster of variants. The VI has two functions determined by the LogFunction enum - header and data entries. The header takes the names of the cluster elements and combines it to a tab seperated string. If the cluster contains a cluster the name is seperated by a dot. Data entries just writes the cluster element values as strings.
Example: (tabbing in this editor not not possible?)
Time PIDsettings.Kp PIDsettings.Ratelimit.dt
1.0 0.25 1000
I haven't had time to look into MGI's read/write anything - will do it later 🙂
11-02-2015 12:53 PM - edited 11-02-2015 12:57 PM
You don't need recursive calls for this, just build up an array. Each loop cycle you pull one element off the array; if it's another cluster, add all those elements back onto the array. I posted some example code that does this here:
It writes to an INI file, and does the dot-separating as you describe. Wouldn't be hard to write to something other than an INI file.
I haven't looked at your code, I'm still on LabVIEW 2012 here.
EDIT: I should add that the linked code uses a mix of variant functions and control references, but I think it could be done purely with the variant analysis functions. Here's another example, with an image, that gets the names without using any references:
11-03-2015 01:12 AM
Thanks for the reply - That is a great idea.
But my code is running fine and has only glitched once - I'm trying to figure out why 🙂 If I can just reuse the VI I've already written I would save a bunch of time.