LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ActiveX Object Creation method to pass to an Invoke Node

 

Hi!

 

I'm trying to optimize the way in which I use MathCAD from LabVIEW.  One of my VIs is having really poor performance in terms of execution speed and memory usage.

 

My VI converts a 2D LabVIEW array of doubles into a 2d Mathcad matrix and puts that matrix into a Mathcad worksheet.  The issue is that you do not just pass the 2d array of doubles into the SetValue invoke node as a variant.  You have to create a Mathcad.MatrixValue object, and then pass the object to the SetValue invoke node.

 

Here is the example code provided in the Mathcad developers manual:

SetElement Method var m = CreateObject("Mathcad.MatrixValue");
for(row = 49; row >= 0; --row)
for(col = 9; col >= 0; --col)
{
var val = row + col;
m.SetElement(row, col, val);
} 

 

Here is my implimentation in LabVIEW:

 

Here is my SubVI

 Convert 2d LabVIEW array to MathCAD Variant Matrix.png

 

 Here is my main VI:

 

MainVI.png

 

My SubVI is running out of memory and throwing the following error:

 Exception occured in mplrun: Exception of type 'System.OutOfMemoryException' was thrown. in NL SubVIs Library.lvlib:Convert LabVIEW 2d Array to MathCAD Variant Matrix (SubVI).vi->test.vi

 

It doesn't always throw the error.  When I watch the memory consumption of LabVIEW it goes up to about 250k and then drops to 90k and slowly builds back up to 250k.  Initialy starting the code takes awhile too on my computer.  From start of VI until first loop iteration it is about 20 seconds, and then about 150-250ms after that.  Not very good performance.

 

Any advice on how to optimize this code would be appreciated.  I'm not really sure when I should close some of these references.  I tried closing the reference in my converting SubVI, but I guess that destroys it so MathCAD can't use it.

 

I'm in LabVIEW 2009.  Any help is appreciated. 

 

Thanks for your time and input!

-Nic

 

0 Kudos
Message 1 of 2
(3,233 Views)

I'm not sure this will solve your problems but it should help.  You need to close ALL of your references to Mathcad objects when you're done using them.  That means you need to close the reference to the Mathcad MatrixValue after you pass it to Mathcad (to do this you'll need to convert it back from a variant, or pass the reference directly out of your subVI), and you should also close the reference to the matrix that you get back after you've converted it to a LabVIEW array.  Otherwise you'll continuously allocate more and more memory rather than allowing it to be reused.

 

Less importantly, you should also close your references to IMathcadWorksheets and IMathcadWorksheet (but since you only open them once it's not causing your memory problems).

0 Kudos
Message 2 of 2
(3,213 Views)