LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

A 'dynamic' formula node in a LabVIEW execution file

Solved!
Go to solution

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. 

0 Kudos
Message 1 of 12
(12,114 Views)

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

With regards,
JK
(Certified LabVIEW Developer)
Give Kudos for Good Answers, and Mark it a solution if your problem is solved.
0 Kudos
Message 2 of 12
(12,110 Views)
Try the OpenG LabPython tools.  You can put a String control on the front panel for the user's code and feed it to Python.
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 3 of 12
(12,081 Views)
Oops.  I spoke too soon.  I've gotten stuck trying to throw together a "quick" example.
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 4 of 12
(12,076 Views)

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...

 

Message Edited by jcarmody on 04-07-2009 08:16 AM
Message Edited by jcarmody on 04-07-2009 08:22 AM
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Download All
0 Kudos
Message 5 of 12
(12,069 Views)
Solution
Accepted by Joaquin Chien

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.

Message Edited by jcarmody on 04-07-2009 08:31 AM
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Download All
Message 6 of 12
(12,059 Views)

Last time, I promise...  I thought it'd be nicer to see the results in a String indicator rather than a cluster array.

 

Message Edited by jcarmody on 04-07-2009 08:43 AM
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Download All
0 Kudos
Message 7 of 12
(12,049 Views)

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.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 8 of 12
(11,950 Views)
Hi, I need to try your solution, but have no access to version 8.6, is there any chance you could leave an 8.5 version? Cheers
0 Kudos
Message 9 of 12
(11,586 Views)

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)

Download All
0 Kudos
Message 10 of 12
(10,981 Views)