Matlab connection with device by .net library by .dll
조회 수: 20 (최근 30일)
이전 댓글 표시
Hello,
I just bought a hardware that is USB connected to the computer, with a software to control it.
The hardware is a captor, which has an acquisition frequency between 1-100hz. My problem is that from the software that they provide you can choose between 1 or 100 and some of my experiences need acquisition frequencies with values between them.
When I contacted the provider, they told me that if I need another frequency I will need to work around myself. The captor has a .dll (a .NET library) file that was created from the installation of the software, and from its application note there is a MODBUS communication protocol too.
From the application note, the library is a .NET assembly and any .net supporting programming language or program like C#, LabVIEW, IronPython, Visual Basic .net, or Mathworks MATLAB should be able to use it and fully control the detector. From what this phase and as I have no knowledge of the other languages/programs and I have used Matlab and I have a license to use it I thought I would follow that path.
The problem is that I haven’t work with a library before, and the application note only gives more information for C# and IronPython.
From what I read in the matlab forum, matlab needs a header file too (besides the library file .dll) where I don’t have anything else from the provider.
Is it that I am missing something or is there another way to work around?
If any essential information is missing, I excuse myself as it is not at all my field of work and I am doing this to be able to use a captor correctly.
Thanks in advance,
댓글 수: 0
답변 (1개)
Guillaume
2019년 4월 30일
It's actually fairly easy to call .Net functions from matlab. No you don't need a header file for Net assemblies (these don't exist in the .Net world), header files are for non .Net dlls (that use Windows API instead of .Net).
net.addAssembly('C:\somewhere\somefolder\yourdll.dll'); %assuming the assembly has not been added to the GAC, otherwise use the GAC name
Then you use more or less the same code as you'd use in VB.Net, C#, or Python to interact with the assembly. Just instantiate a class and call its methods and properties. If you show an example in any language of the code you want to use we can probably show you the matlab equivalent.
댓글 수: 6
Guillaume
2019년 5월 2일
I probably had a momentary case of blindness. Indeed, the original code was:
Digital Detector = new Digital();
The class name is therefore Digital. So the construction in matlab is
example = clDigital.Digital;
methodsview or methods with the '-full' option will allow you to see all the methods with all their input and output arguments (translated to matlab types):
methodsview('clDigital.Digital'); %displays in a an window
methods('clDigital.Digital', '-full'); %displays at the command prompt
Whatever function would allow you to change the frequency will be a method of that Digital class. The other classes listed in that assembly are just to encapsulate event data. It is also possible that the frequency is a property of the object:
properties('clDigital.Digital'); %displays at the command prompt. There's no pop-up equivalent.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!