LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

matscript node void ouputs when calling user-defined functions

Hi,

 

I have a (for most of you, probably simple) problem with calling user defined function within a mathscript node.

 

I have a script inside a MathScript node which calls three UD functions. When I try to output variables, LabView sets their type to void, so I cannot use them further. this would imply, that the script is nondeterministic, (since the types would get set at runtime). However, if I replace the call to the UD function with the actual contents of the function, the variable becomes deterministic. Now, since I have several call to these functions, I have no desire in writing all of them many time, introducing many variables etc. What would you advise me to do?

 

Find attached my scripts and functions.

 

I need this script running on a RT Target, and have been battling this for weeks, with almost no success!

 

Thanks, Regards,

Luka

 

 

 

 

 

0 Kudos
Message 1 of 8
(7,850 Views)

Hi LukaAmbrozic,

I reviewed attached files. The thing is that for determining the output data type of m file is needed to run the code because MATLAB does not use strict data type assignment. But in LabVIEW you have to strictly define data type. You can do it by right clicking on particular output variable (created on the edge of MathScript Node using right click and selecting Add Output) and in "Choose Data Type" select data type you want to use in LabVIEW (in most cases I32 or DBL). Is that what you want? If not do not hesitate to write here.

Best regards

Martin

0 Kudos
Message 2 of 8
(7,823 Views)

Martin, HI!

 

I already know that the data type must be set if LabView doesn't detect it itself.

 

The problem is, that LabView sets the output variable to type void (black color) which makes it impossible to change it's type (every type is greyed out). This happens even with the simplest, one line function, as cvecrep(v,c) (attached with previous post).

 

Whe I try to call this function from a MathScript node, in which i define the inputs as such, for example:

 

v = ones(3,3);

c = ones(1,3);

 

and then call

m = cvecrep(v,c);

 

The function cvecrep is on the path, that is set both in the VI and in the MathScript Window.

 

For reference i have attache an image:

 

MathScript Node void.png

This behaviour makes the use of MS node outputs useless, since i cannot connect them further, because they have no data type.

 

If I use the function contents - the one line, within the node, the data type is set normally.

 

Hope this explains the problem more thoroughly.

 

Cheers, Luka

 

0 Kudos
Message 3 of 8
(7,821 Views)

Hi LukaAmbrozic,

Thank you for deeper explanation so I understood the difficulty you have. Determining of the output data type is done by reviewing the code. If the code contains some error (syntax error or e.g. missing function file) LabVIEW cannot determine the data type. So make sure that LabVIEW is able to access your UDFs (adding command "path" in MathScript Node, I hope it is enough to add it only once, run it and it should link the folder also for future usage). Then LabVIEW will choose the data type according to your UDF or you will be able to change it manually. I also saved the VI and it works for me. So please try it and post if it works.

Best regards

Martin

0 Kudos
Message 4 of 8
(7,817 Views)

MArtin, hello!

 

As far as I know, LabView checks the syntax as you write in the MS Node, and since there is no X mark next to the line number, it indicates, that the syntax is correct. Since i have set the path to the UDF in both the VI options and in the general MAthScript setting, how does adding the path command help? even if I add path('directory') command, a yellow exclamation mark appears, saying the command is slowing down performance.

(this is the original help explanation:

The warning glyph indicates that LabVIEW operates with reduced error checking at edit time and slower run-time performance for the MathScript Node. The following conditions cause the warning glyph to appear. To remove the warning glyph from the MathScript Node and improve run-time performance, modify your script as follows to resolve the condition in your script:

  • Your script calls addpath or pathremove (legacy name rmpath), or calls cd, path, or userpath with one or more inputs, which change the MathScript search path list at run time. Remove these functions and use the MathScript page to configure the default search path)

 

 Could you please post a screenshot of your VI, just to see, if you've got anything different set up?

I am running LV2012.

 

Luka

0 Kudos
Message 5 of 8
(7,813 Views)

Forgot to write down, that the variable does now offer type selection! And yet, it should work without the path command?!

0 Kudos
Message 6 of 8
(7,811 Views)

Hi LukaAmbrozic,

 

in the attached image you can see that type detection works for me. I have LabVIEW 2012. I think that you have to run the VI first without outputs (LabVIEW be able to recognize the data types) and after that adding the output should work fine.

Regarding to the path() function, it should have the same functionality as the configuration dialog you talked about. I run the code with path() function only once (just for adding the folder) and then I changed it to comment using % symbol.


Snippet.png

Best regards

Martin

0 Kudos
Message 7 of 8
(7,794 Views)

AECMartin,

 

There is a significant difference between adding the search path statically through the Tools > Options page and dynamically calling the path command from within the node or a user-defined .m file.  The dynamic call only changes the search path for the particular node that it is called from (and its hierarchy) for that run. Once the VI stops, the search path reverts back to the static setting. Commenting out the search path command also reverts back to the static setting.The path command exists as a option that should be used very rarely when the search path really needs to be dynamic at run-time.

 

LukaAmbrozic,

 

Going back to the original question, I used the scripts that you attached in 2012. MathScript node automatically detected the outputs for me. I suspect that your .m file implementation may have got into a bad state. You can do two of the following things to clear them out. (1) Change the .m file (by adding a space and removing it) and resave it while LabVIEW is not in memory OR (2) Go to LabVIEW Data > MathScript VIs and delete the contents of the folder.

 

Let me know if you still see the problem.

 

Regards,

Rishi Gosalia

Senior Software Engineer

National Instruments

0 Kudos
Message 8 of 8
(7,785 Views)