Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Calling User-Defined Functions from LabVIEW MathScript (Windows, Not in Base Package)

LabVIEW 8.5 Help
August 2007

NI Part Number:
371361D-01

»View Product Info

After you define and save a function, you can call the function you defined from the LabVIEW MathScript Window or the MathScript Node. To call a user-defined function, the filename for the function must be the same as the name of the function and must have a lowercase .m extension. For example, the filename for the foo function must be foo.m. Also, you must save the function in a directory in the MathScript search path. Use the MathScript: Search Paths Options page to configure the default search path list for MathScript.

LabVIEW identifies user-defined functions by filename. When you call a user-defined function from the LabVIEW MathScript Window, LabVIEW searches the MathScript search path list from top to bottom for a .m file with the specified name. When you call a user-defined function from a MathScript Node, LabVIEW looks in the following three places, in order, for a .m file with the specified name.

  • First, LabVIEW looks to see if a .m file with the specified name is currently in memory.
  • Second, LabVIEW looks in the directory where the .m file was located when you last saved the VI that contains the MathScript Node. Because LabVIEW looks in the directory where the .m file was located when you last saved the VI, you do not need to reconfigure the MathScript search path list when you open the VI on a different computer. However, you must maintain the same relative path between the VI and the .m file.
  • Third, LabVIEW searches the MathScript search path list from top to bottom. If you open the VI on a different computer, the search path list might change because LabVIEW searches the MathScript search path list configured on that computer, not the search path list configured when you last saved the VI.
Note  If a warning glyph appears on the MathScript Node frame, LabVIEW does not look in memory or in the directory where the .m file was last located. Instead, LabVIEW searches only the MathScript search path list for a .m file with the specified name.

If a .m file with the specified name is currently in memory, LabVIEW links the function call to that .m file for execution purposes. The link between the function call and the .m file behaves the same way as links between VIs and subVIs. When you try to reference a subVI and another VI with the same name already exists in memory, LabVIEW references the one already in memory instead of the one you selected. In the same way, if you try to load references to two different .m files with the same name from the same application instance, only one .m file is actually loaded into memory. Because both references to the .m file point to the same file, a problem known as cross-linking occurs.

To avoid cross-linking, use LabVIEW projects. When you reference a .m file from a VI that is part of a project, LabVIEW adds the .m file to the dependencies for the target. You then can configure a unique search path for the .m file. For example, you can build a VI with a MathScript Node that calls a user-defined function named foo that project1.lvproj owns. You also can build a VI with a MathScript Node that calls a different user-defined function named foo that project2.lvproj owns. After you use the MathScript: Search Paths Options page to configure a unique search path for each project, you can save the VIs. When you next open one of the VIs, LabVIEW links the call to the foo function to the appropriate .m file as long as you open only one of the VIs.


Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit