From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use a .NET assembly generated in Matlab

Solved!
Go to solution

I'm new to using .NET Assemblies in Labview. I generated a dll in Matlab, and then  used a "constructor" to point to that Matlab dll.  I then connect that to an "invoke node" which seems to correctly know all the inputs to the function "Setup" contained in the dll. The problem is that the inputs should be all numerical arrays and instead show up in Labview as .NET refnums which cant be wired up. The output of the "Setup" function is also several arrays, but in Labview shows up as a single output. What am I missing here?

0 Kudos
Message 1 of 21
(3,408 Views)

Posting the .NET assembly would be helpful to give you some more pointed advice.

 

But from your description I can guess that parameters for the Setup function are not the Array type but of a different type such as ArrayList, IEnumerable<T> or one of the other collection classes / generic collections.

 

Also in .NET there are only two ways of returning information - via the reference modifiers (called "ref" and "out" in C#) or via the return value of the method. It looks like your Setup method only has a single return value but of what type I can't say without the assembly on hand.

0 Kudos
Message 2 of 21
(3,406 Views)

You could try one or both of these options:

 

Create arrays in NET.png

 

The "Double" and "Array" types are in the "mscorlib" assembly.  "To .NET object.vi" is in the ".NET" palette.

Message 3 of 21
(3,383 Views)

Kyle,

I tried your second suggested method, but get an error message. Any further suggestion? Meanwhile I'll try your first method. I appreciate your help.

0 Kudos
Message 4 of 21
(3,349 Views)

Kyle,

 

Meanwhile which "object" in the mscorelib contains the "double" and "array" constructors that you used in your first example? There is a lot in that library. Thanks.

0 Kudos
Message 5 of 21
(3,346 Views)

Look under "System" and you will find those classes.

0 Kudos
Message 6 of 21
(3,344 Views)

Tyk007,

 

All the input parameters to the "Setup" method show up as "MWArray" in the pull-down menu for selecting the method for the class. I assume this is because Matlab is a  MathWorks (MW) product, and Matlab was used to create the .NET assembly. Is there something special I need to do? The Setup function in Matlab returns several arrays, and I want all of them when I invoke the method in Labview.

0 Kudos
Message 7 of 21
(3,343 Views)

Tyk007,

I found "double in "system", however "array" is problematic.

0 Kudos
Message 8 of 21
(3,342 Views)

If you re-check Kyle97330's post the Array is created using a static method on Array. Check that you aren't trying to find a constructor and a browsing for an Invoke node.

0 Kudos
Message 9 of 21
(3,334 Views)

@Rogueone wrote:

Tyk007,

 

All the input parameters to the "Setup" method show up as "MWArray" in the pull-down menu for selecting the method for the class. I assume this is because Matlab is a  MathWorks (MW) product, and Matlab was used to create the .NET assembly. Is there something special I need to do? The Setup function in Matlab returns several arrays, and I want all of them when I invoke the method in Labview.


I'm not familiar with Matlab's .NET assembly creation functionality so I would assume that the "MWArray" type exposes some properties and methods to help you access the individual elements. Posting your .NET assembly (try zipping it) would make it easier for me to help you.

0 Kudos
Message 10 of 21
(3,332 Views)