MATLAB: Convert String to instrument​.Oscillosc​opeObject

coscilloscope

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

Best Answer

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.