Convert String to instrument.OscilloscopeObject
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
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 Kommentare
Akzeptierte Antwort
  Guillaume
      
      
 am 8 Mai 2017
        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 Kommentare
  Guillaume
      
      
 am 9 Mai 2017
				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).
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
