VB .NET function use in matlab
3 views (last 30 days)
Show older comments
Hi all,
I am trying to use a VB .NET dll in matlab. The dll is available from the federal aviation administration website: https://www.airporttech.tc.faa.gov/Products/Airport-Safety-Papers-Publications/Airport-Safety-Detail/ArtMID/3682/ArticleID/2838/ICAO-ACR-13
The dll user guide is attached to this post.
What I tried:
library = NET.addAssembly('[Mypath] \ACRClassLib DLL 2020.12.14 .NET 4.7.2\ACRClassLib.dll');
seems to work. Then:
CalculateACR(1,40000,0.47,4,200,[-15 15 -15 15],[0.0 0.0 55.0 55.0],true)
I get: "Check for incorrect argument data type or missing argument in call to function 'CalculateACR'".
I think the problem is coming from the first argument which is required to be an enumeration member. The enumeration PavementType seems to be included in the library but I don't know how to call it...
Thank you for your answers!
1 Comment
Daniel Gaffney
on 27 Jul 2023
Did you ever find the answer to this question? I am trying to do the exact same thing.
Answers (1)
Saarthak Gupta
on 14 Dec 2023
Hi Jean-Marie,
I understand that you are trying to access an enumeration included in an external .NET Assembly.
In the ‘.NET’ assembly object, ‘PavementType’ is stored as 'ACRClassLib.clsACR+PavementType'.
As per the technical info sheet of the DLL, ‘PavementType’ is an enumeration nested within the clsACR class (which is part of the ACRClassLib namespace), to access such an (nested) enumeration you may use reflection since MATLAB cannot resolve its type.
Reflection is the process of describing the metadata of types, methods, and fields in a code. As per the DOTNET documentation; the classes in the System.Reflection namespace, together with System.Type, enable the user to obtain information about loaded assemblies and the types defined within them, such as classes, interfaces, and value types (that is, structures and enumerations). One can also use reflection to create type instances at run time, and to invoke and access them.
The below code can be used to obtain the required enumeration for your function ‘CalculateACR’:
a = NET.addAssembly("<path-to-file>\ACRClassLib.dll");
% use reflection to get the type of the ‘PavementType’ enumeration
t = a.AssemblyHandle.GetType('ACRClassLib.clsACR+PavementType');
x = ACRClassLib.clsACR;
% construct a 'Flexible' PavementType enumeration object, at runtime
flexiblePavement = System.Enum.ToObject(t,1);
% rigidPavement = System.Enum.ToObject(t,2);
x.CalculateACR(flexiblePavement,0,0,0,0,0,0,0,true);
Please refer to the following MATLAB documentation for further reference:
- Use .NET Nested Classes: https://www.mathworks.com/help/matlab/matlab_external/nested-classes.html
- .NET Enumerations in MATLAB: https://www.mathworks.com/help/matlab/enumerations.html
- Enum.ToObject Method: https://learn.microsoft.com/en-us/dotnet/api/system.enum.toobject
- Type.GetType Method: https://learn.microsoft.com/en-us/dotnet/api/system.type.gettype
Hope this helps!
Best Regards,
Saarthak
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!