LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I programmatically execute a function?

Hi all, I have a text box, a command button, and a numerical indicator to program a power supply. One of the numerical indicators is the desired voltage level, and the command button "SEND" takes the value and sends the value to a function called "SET_VOLTAGE(double voltage);" So for 2.00 Volts, I set the indicator to two volts and press "SEND". Pretty simple. When I do this I echo to the textbox the command as I would send it to the function, for this example pressing the send button would display SET_VOLTAGE(2.00); I have a similar function for setting the current as well. SET_CURRENT(.001);

 

Here is my question: I would like to read the text line "SET_VOLTAGE(2.00);" and execute that function. Is there a simple way to do this? The closest way that I can figure out is to analyze the line and then execute the corresponding function like:

 

if (line[4]=='V')

   SET_VOLTAGE(here I would have to pick apart the line to figure out what value to send);

if (line[4]=='C')

   SET_CURRENT(here I would have to pick apart the line to figure out what value to send);

 

as you can see this is pretty limiting and takes lots of analytical code.

 

What I really want is:

GetTextBoxLine (commandpanel, COMMAND_P_TEXTBOX, index, buf); 

ExecuteTheFunction(buf);

 

or something like this.

 

Thanks for the help,

Bruce

 

0 Kudos
Message 1 of 4
(3,151 Views)

Provided that the optimal scenario would be to have the SEND button to preset the supplier, if you absolutely want / need to have the operato set the command and a separate function to issue it to the instrument I can think of different solutions.

 

You have already thought on scanning the string and operating accordingly to the informations retrieved.

An alternative solution could be to have: a ring that states "Current", "Voltage" with different values, a single numeric control to set the set point and a single SEND button; the button builds up the command string based on the value read from the numeric and the signal selection made in the ring; the separate function can do exactly the same thing, ignoring textbox content.

Alternatively, you can use a listbox instead of a textbox: the listbox can have values associated to items, so you can write the command string, insert it in the listbox with InsertListItem associating the corresponding set point. An appropriate value set in listbox callbackData attribute can state the type of operation; the separate function in this scenario can retrieve the value with GetCtrlVal and the type of operation with GetCtrlAttribute and issue the appropriate command.

 

I am probably making things more complicated that they could be: if you can deteil a little more what you are trying to do we can probably find a better solution.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,136 Views)

Thanks for the help, I sure appreciate it! Actually the application is really not important, what I need is a way to execute a function that is already written in my code that I type into a textbox. Lets say I have a function to get an array of random numbers called "GETNUM" and another to plot those values called "PLOTVAL". What I want is to write GETNUM(200): in my text box and push go and have that function get executed. The only way that I can see is too write some code to look for specific strings in the text line and execute that function. But to do this I need to write some kind of string compare line for each possible function. What I need is a something that goes; read the line, does it match a function that is in some *.h file, if so execute that function and pass the variables as well. Maybe some kind of pointer to function and pointers to variables? Anyway thanks if you can help further...

 

Bruce 

0 Kudos
Message 3 of 4
(3,118 Views)

I see. An easy option could be to design a "program" panel for the end user where he can choose among a limited set of available commands using for example a ring; you will next need to add / enable an appropriate number of input fields on the panel for the user to enter command parameters; after he clicks on a 'Execute' button, read the ring of commands first, then generate the actual command.

 

The exact approach you are thinking of is as far as I can understand to build a 'command parser': read the string, search for a specific command in the string and then execute it appropriately. This is not a trivial task: on the parsing side of the matter you can find a powerful help in using the 'regular expression' instrument available in CVI ( <cvifolder>\toolslib\toolbox\regexpr.fp); you will then need to scan for specific parameter values, add input-error detection (*very* important!) and then execute the command.

 

Searching the forum for 'regular expression' or 'parser' can give you some useful discussion to read about. As an example, take a look at this function parser from msaxon.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(3,108 Views)