How do I call a .NET method?
10 次查看(过去 30 天)
显示 更早的评论
I am trying to retrieve coordinate positions of equipment produced by Scientifica from its software (LinLab 2) so that it is displayed in MATLAB. I am trying a DLL approach.
The following is the associated Visual Studio Code:
using System;
using Scientifica.LLII_Client;
using Scientifica.LLII_Client.Util;
namespace LinLab2_Client_Example
{
class Program
{
private static LL2Client _Client;
static void Main(string[] args)
{
//You need to include the LLII_Client.dll in your project
//find connection options for connection on the same computer
ConnectionOptions options = ConnectionOptions.GetOptionsFromFile();
_Client = new LL2Client(options); //You need to keep this object whilst you are using the connection do not recreate it everytime
while (true)
{
Console.WriteLine("Press enter to report cards positions");
Console.ReadLine();
//Report position of V1 motion cards
foreach (var card in _Client.Motion1Cards)
{
Position p = card.Position;
Console.WriteLine("Desc:{0}, X:{1}, Y:{2}, Z:{3}", card.Description, p.X, p.Y, p.Z);
}
//Report position of V2 motion cards
foreach (var card in _Client.Motion2Cards)
{
Position p = card.Position;
Console.WriteLine("Desc:{0}, X:{1}, Y:{2}, Z:{3}", card.Description, card.PositionX, card.PositionY, card.PositionZ);
}
}
}
}
}
I am able to load the library, however am not able to call the methods shown below.
>> asm = NET.addAssembly(' C:\Users\paladmin\Documents\PatchStar Coordinate extracting\LinLab2_Client_Example\LinLab2_Client_Example\LLII_Client.dll');
>> asm.Classes
ans =
'Scientifica.LLII_Client.CommandClient'
'Scientifica.LLII_Client.ConnectionOptions'
'Scientifica.LLII_Client.LL2Client'
'Scientifica.LLII_Client.Util.ArgumentErrorException'
'Scientifica.LLII_Client.Util.Error'
'Scientifica.LLII_Client.Util.Position'
'Scientifica.LLII_Client.Util.TypeConvert'
'Scientifica.LLII_Client.Commands.Card'
'Scientifica.LLII_Client.Commands.H1'
'Scientifica.LLII_Client.Commands.H1Volatile'
'Scientifica.LLII_Client.Commands.H2'
'Scientifica.LLII_Client.Commands.H2Volatile'
'Scientifica.LLII_Client.Commands.M1'
'Scientifica.LLII_Client.Commands.M2'
'Scientifica.LLII_Client.Commands.MVolatile'
'Scientifica.LLII_Client.Commands.P1'
'Scientifica.LLII_Client.Commands.P1Volatile'
I have tried the following among other things and get these errors:
>> Scientifica.LLII_Client.LL2Client
Error using Scientifica.LLII_Client.LL2Client
No constructor 'Scientifica.LLII_Client.LL2Client' with matching signature found.
>> electrode = asm.Scientifica.LLII_Client.LL2Client
No appropriate method, property, or field 'Scientifica' for class 'NET.Assembly'.
What is the appropriate command implementation to call the .NET Methods in this case?
1 个评论
Andrew
2023-2-10
For future users - I found it much easier to interact with Scientifica manipulators by opening a serial connection and querying with their native commands:
% Set up connection to Scientifica Patchstar
s = serialport('COM4',9600); % for Motion 1 card (silver control box), baud rate = 38400 for Motion 2 cards (black controller)
configureTerminator(s,'CR');
% Set auto-angle
writeline(s,'ANGLE A');
readline(s);
% Read angle
writeline(s,'ANGLE');
scientifica_angle = readline(s);
% Read position
writeline(s,'P');
scientifica_position = readline(s);
回答(1 个)
Nagarjuna Manchineni
2018-7-19
Hello Gauri,
I see that you are loading the assembly into MATLAB successfully. However, you can use the following way to call the methods that are available in the assembly. Please make3 sure you are passing the constructor arguments properly.
Refer to the following documentation link for more information: https://www.mathworks.com/help/matlab/methods-.html
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!