LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use a .NET assembly generated in Matlab

Solved!
Go to solution

@Rogueone wrote:

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.


You said the inputs to your DLL were all arrays, but you're passing in just one value to the "To .NET object" VI.  Are your inputs actually just a single number each?  If they're actually arrays, then you have to pass in a single-element array just like in the picture to get it to create an array.

 

Also, can you confirm the exact type that the inputs of your DLL are?  If you have the context help enabled and hover over the wires leading from the constant to the conversion node, and screenshot that context help window, that would do it.  Sometimes class names are long and you have to stretch out the context help window to see it all.

 

Or, just post the DLL and we can help a lot more...

0 Kudos
Message 11 of 21
(2,273 Views)
0 Kudos
Message 12 of 21
(2,268 Views)

Tyk007,

 

I hadn’t seen that before. But now that I have, I still don’t know specifically what to do in Labview to successfully call the functions in my .NET assembly. Any suggestions?

0 Kudos
Message 13 of 21
(2,262 Views)

Frankly we're guessing without the assembly. Please post it if you need more specific advice. Don't worry, we won't judge.

0 Kudos
Message 14 of 21
(2,259 Views)

Tip1 : When exporting a .NET assembly from MATLAB , you can also have the Native DLL Generated. Else you have to use the MWArray Datatype instead of the regular VariantDatatype.

 

Using the MWArray Dayatype - Using the MWArray.dll ( found in the MATLAB runtime folder ) .you can create the Array types as refs and then pass them to your .NET Call. 

 

In attachment is a "redacted" of a current implemented .NET dll

 

Floris Reinders
Senior Project Engineer / CLA
Message 15 of 21
(2,247 Views)

Mr Builder,

 

Thanks. So I wrote a simple "Hello World" function in MATLAB that adds x and y with a single output z, then generated a .NET assembly containing the function "Rogue_sum". I found the MWArray.dll buried in the root directory of MATLAB, and used it to create this LabVIEW code. It runs without error, but the output is some HEX string I don't know how to parse. How do I read the output? Do I need to invoke something from the MWArray dll? Can you please show the output side of the example you provided? I figure if I can get this working I should be able to figure out how to call the actual MATLAB functions I'm working with.

NET.PNG

0 Kudos
Message 16 of 21
(2,231 Views)

Because we are not using the native .dll the return value is also mxarray ( and not a .net variant ). So use method of MxArray to get the correct value type.  Monday I can post an actual example

Floris Reinders
Senior Project Engineer / CLA
Message 17 of 21
(2,220 Views)

I would very much appreciate that. Thanks.

0 Kudos
Message 18 of 21
(2,213 Views)

Unfortunately , the .NET I used did not return any value for me to decode. But the datatype is MXArray .

So any property or method node should work. I tried an to make an example of how to convert to the scalar value , but you have to try and see if it works. ( I could not test it yet )

Floris Reinders
Senior Project Engineer / CLA
Message 19 of 21
(2,198 Views)
Solution
Accepted by Rogueone

Floris,

 

Your last post was very useful. I used your approach to construct a working VI for the simple "Rogue_sum" test function, and I think I can now generalize the approach to all of my actual MATLAB functions. Thank you!

 

RogueoneNET 2.PNG

Message 20 of 21
(2,191 Views)