LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

dynamically load script

Hi everybody,

Is it possible to load a different m file by browsing it once I have made an executable out of my LV program?

I'll try to explain :
I have 24 data acquisition channels on my bench and I want to make combinations between them (linear or not). I know I will have a maximum number of 5 calculated channels but I don't know neither which channels will be used as inputs nor what operation has to be made.

Example :
Ch_calc_1 = ch5*ch9; Ch_calc_2 = ch1+ch5 +ch8*ch15.
Ch_calc_1 = ch1+ch9+ch14; Ch_calc_2 = ch1*ch5 +ch8*ch15.
Ch_calc_1 = sin(ch9)+cos(ch12+ch19); Ch_calc_2 = ch1+ch5 +ch8*ch15
And so on.

I already know the number of inputs can not be managed dynamically and I think about a swhich (limiting number of input  from 2 to 10). But I don't know how I can load  a  different formula  when ever  I want.

By the way, I do not necessarly need an m file. Using a simple text box on my front panel where I can directly type my formula would be good also.

Thanks for help.


Raoul Chodziesner-Bonne
Ingénieur Instrumentation
CRIL TECHNOLOGY - Groupe ALYOTECH

"Celui qui pose une question peut paraitre idiot sur le moment, celui qui n'en pose pas le reste toute sa vie!"
0 Kudos
Message 1 of 10
(10,776 Views)
Hello Raoul,

The short answer to your question is no, it is not possible to load a different .m file in a built executable.  Providing a text box for string input to the MathScript node will not work either.

The difficulty lies in the fact that MathScript is a compiled language.  In order to create executable code from an arbitrary .m file, we would need to first compile it.  This functionality is not provided in the run-time engine.  This question comes up frequently and, honestly, we are a little puzzled as to the usefulness.  Could you elaborate more about your application?  What MathScript functions would you expect to be able to call?  Would you need the performance to be similar to a compiled MathScript?

A simple workaround is to use a development version of LabVIEW at each location you would have used a built executable.  The development version has the necessary functionality to do what you wish.  You could have a string control on the front panel, pass in this string to the MathScript node, and call the "eval" function.

However, if you wish to use a built executable, there are a couple other workarounds possible.  The first is if you can predefine the set of all possible computations you wish to perform.  You can then write LabVIEW code to choose among them as well as provide a mechanism for ensuring the right channel data gets to the MathScript node.  See the screenshot below and attached VI for an example of what I mean.

The other workaround is to use the LabVIEW formula parsing and evaluation VIs.  These VIs are available on the Mathematics >> Script & Formula palette.  These all take a formula string input that you can specify from a front panel control.  However, these VIs do not provide as much functionality as the MathScript node.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments




Message Edited by GrantM on 01-23-2008 05:02 PM
Download All
0 Kudos
Message 2 of 10
(10,742 Views)

Dear all,

Maybe another workaround would be to call a user defined function from within the Mathscript node. The user defined function, would be a .m file that can be changed in execution time by the user.

Best regards

Miguel

0 Kudos
Message 3 of 10
(10,620 Views)
Sorry for not answering the first response but I have no much time these last weeks.
I understood I can not change dinamically the contents of the mathscript structure and, after discussion with my client, found another solution.

But Miguel's idea sound very interesting. Is it possible to have more explanations about it? Is it possible to call an external calculation file (*.m or whatever) and to programmatically choose which file to open?

Thanks for your help.


Raoul Chodziesner-Bonne
Ingénieur Instrumentation
CRIL TECHNOLOGY - Groupe ALYOTECH

"Celui qui pose une question peut paraitre idiot sur le moment, celui qui n'en pose pas le reste toute sa vie!"
0 Kudos
Message 4 of 10
(10,606 Views)

Hello,

My approach is simply to have a mathscript node calling a function made by the programmer. That function is a ".m" file with the same name. If you change the ".m" file without changing its name, and I/O parameters, the functinality will change. I have to say that I have not tried it in a executable.

Example:

------------------------------

Mathscript node:

out=myfunction(in1, in2);

-----------------------------

myfunction.m file

function out=myfunction(in1,in2)

out=in1*in2;      %this can be changed from one run to another with a text editor.

--------------------------

 

Best regards

Miguel

 

 

 

 

 

0 Kudos
Message 5 of 10
(10,603 Views)
Hello Miguel,

The method you outline should work fine in a regular LabVIEW VI.  Unfortunately, it will not work in a built executable.  The explanation is the same as I outlined above; namely, that in order to execute any script, LabVIEW first needs to compile it.  The LabVIEW compiler is not provided in the run-time engine.  However, a method that would work in the run-time engine is to have a set of user-defined functions that each implement a separate calculation that you will use.  In the MathScript node, you can make a run-time determination as to which function to call (using a switch statement, for example).

If one desires a truly dynamic behavior of the node, (1) we would really like to learn more about the use case and (2) it isn't possible in a built executable at this time.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 6 of 10
(10,595 Views)
Dear Grant,
 
Thanks for your explanation.
 
In answer to your demand of use case, I am going to expose mine.
 
I am developping a software that, among other tasks, is able to command an external actuator with values provided by the user. If the amount of values introduced by the user is short, he can write a text file and that would be the input. But sometimes the amount of values is huge, and I had thouht that a good way for the user to introduce the values would be in an algorithm, so that he could write a file similar to:
 
For index=1:1000000
    output=index*3+2+;
end
For index=1:1000000
    output=index*2+9;
end
 
The nice thing is that the user normally would check firstly its script in the Matscript window or in Matlab, and it could inmediately use the same .m file as input for my software.
 
Changing this file to an exhaustive list of values is not easy to manage when the list is too long. Sometimes is 1e8 long of i32 values.
 
I have to provide the client an executable.
 
Now I know I can not do what I prentended, so I will choose the best workaround.
 
Thanks and best regards
Miguel
0 Kudos
Message 7 of 10
(10,581 Views)
I am in need of a dynamically loaded script file.  I could use the formula parsing functions however I need to do some logic functions as well as math functions. I need to the flexibility of changing the equations remotely while keeping strict control of the executable code.

 

0 Kudos
Message 8 of 10
(9,584 Views)

Hi All,

 

     I am aware the with 8.2 you could not build an executable when a vi used a Mathscript node containing a call to a function in a .m file.  More precisely, the actual build would complete, but there would be error(s) upon execution of the .exe.

 

     I haven't been able to find any literature stating this issue has been fixed in 8.6, but I hoping.  Is the above still the case in 8.6?  

 

     I discovered the problem when building the Riemann example to experiment with running it on various PCs as a .exe.   

 

Thanks,

Mike MItchell

RF Micro Devices, Carlsbad
0 Kudos
Message 9 of 10
(9,092 Views)
Hello Mike,

You can build such an executable in 8.2.  However, additional steps are necessary.  You need to add any .m files you use in the MathScript node to the project.  When you are configuring the application properties, go to the Advanced settings and click the "Enable MathScript support" option.  This has changed in LabVIEW 8.5 and later.  You no longer need to explicitly add the .m files to your project.  However, you must set the path to search for the .m files through the project settings.  Right-click on "My Computer" and select "Properties."  Go to "MathScript: Search Paths" and add the paths in there.  When you are not working in a project, you can access the search path settings from Tools >> Options.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 10 of 10
(9,069 Views)