04-07-2009 05:06 AM
I want to put a formula node on the front panel of a LabVIEW execution file, so that user can type their own code in the formula node and get their own output.
I tried this but it seems only feasible before I build the source code to an execution file.
Is there anyone can help me? I appreciate your help.
Solved! Go to Solution.
04-07-2009 05:19 AM
First, how did you place the formula node in the Front panel. A formula node cannot be placed in the Front panel.
If you want user to enter their own code use a string control that will allow the user to type the code and you might need to define the interface for defining the variables.
Variable nodes that are in the borders of formula node cannot be dynamically created
if your agenda is to just evaluate expressions entered by user you can make use of Eval-multi variable array.vi which accepts theexpression as input and variables as 2-d array, evaluates the expression,Post back for queries
04-07-2009 07:24 AM
04-07-2009 07:35 AM
04-07-2009 08:15 AM - edited 04-07-2009 08:22 AM
Here's a not-so-quick example. I'm not sure it's the most efficient way to do it, but it worked for my brief test (except Boolean data comes out as an Integer 1/0). Enter the script into the String control and the variables into the Input Data cluster array. The output data will come from the Python session. It only works with Boolean, Integer, Float and String data now; simply add to the type enum and add cases to both Case Structures to add other types.
You don't need to use the Input Data cluster array for every variable if you don't want to; just initialize them in the script text and they'll show up in the Data. You'll need at least one element in the Input Data or you'll get an error, though. I don't know why...
04-07-2009 08:27 AM - edited 04-07-2009 08:31 AM
New & improved. I got rid of the cluster array; just define your variables in the script text.
The last example required an element in the cluster array because the for loop didn't execute on an empty array so the session reference didn't pass through. I could have fixed that with a case structure testing for an empty array or by using a shift-register instead of an input tunnel. Instead, I realized that I could just use the script text and deleted the cluster array mess.
04-07-2009 08:42 AM - edited 04-07-2009 08:43 AM
Last time, I promise... I thought it'd be nicer to see the results in a String indicator rather than a cluster array.
04-10-2009 08:15 AM
I asked a question about this on the LAVA forum and found that I could simplify the program a bit and handle more data types without modifying the code.
08-11-2009 06:50 AM
03-31-2011 02:33 AM - edited 03-31-2011 02:37 AM
There is another solution with dynamic instanciation.
Because of Formula Node need to be prepared at compile time,
It is necessary to recreate a VI by copy and change the formula before saving.
In fact, thanks to formula node this enable C-like code generation dynamically,
compared to Eval Formula which don't handle conditionnal, loop, etc...
This example can also be execute without the self-callVI but with a template.
Best regards.
Nicolas
(LV2009)