Convert String to instrument.OscilloscopeObject
2 ビュー (過去 30 日間)
古いコメントを表示
I am using MATLAB function in C#. I am trying to get back the value of myScope in C# so that I can use it later on, but the type of myScope is instrument.Oscilloscope which is not recognized by C# and it displays 'null' in result. If I send back the myScope value to C# as string (which I can do) but late on (in code) I have to send it back to Matlab and obviously as "instrument.Oscilloscope" . Is there some way of converting string to instrument.Oscilloscope.
// Create the MATLAB instance
MLApp.MLApp matlab = new MLApp.MLApp();
// Change to the directory where the function is located
matlab.Execute(@"cd c:\MATLABcodevisualstudio");
// Define the output
object result = null;
try {
// Call the MATLAB function myfunc
matlab.Feval("ConfigureScope", 1, out result, "2", "100", "USB::0x0699::0x0367::C057105::INSTR", "CH1", "CH2", "normal", "Falling", "1"); //working
}
catch (InvalidOperationException ex)
{
Console.WriteLine(ex.GetType().FullName);
Console.WriteLine(ex.Message);
}
// Display result
object[] res = result as object[];
%%%%%%%%%%%%%%%%%%Matlab func
function [myScope]= ConfigureScope(ResourceAddress, AcquiringChannel, TriggeringChannel,TriggerMode, TriggerSlope, TriggerLevel)
% Instantiate an instance of the scope.
myScope = oscilloscope();
% Find resources.
availableResources = getResources(myScope);
%connect to availble resources
myScope.Resource = ResourceAddress;
% Connect to the scope.
connect(myScope);
% Enable channel 1.
enableChannel(myScope, AcquiringChannel);
% Set the trigger mode to normal.
set(myScope, 'TriggerMode', TriggerMode);
set(myScope, 'TriggerSlope', TriggerSlope);
set(myScope, 'TriggerSource', TriggeringChannel);
set(myScope, 'TriggerLevel', str2double(TriggerLevel));
myScope
0 件のコメント
採用された回答
Guillaume
2017 年 5 月 8 日
I'm not sure you can pass objects through matlab COM interface. Why don't you use Execute instead of Feval to create the oscilloscope in the matlab workspace. You can then use more Execute to manipulate that oscilloscope and GetVariable or GetFullMatrix to get at the variables of interest.
5 件のコメント
Guillaume
2017 年 5 月 9 日
Execute waits until the command is completed since it must collect its output (if any). So it is sequential (unless you specifically design the matlab command to be asynchronous which would require the parallel processing toolbox or some fancy delegating to Java, mex, or .Net from the matlab side).
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!