I would write wrapper MATLAB functions that do the work with your .NET objects and then call those wrappers extrinsically:
function obj = netSpeak
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 50;
Speak(obj,'You can use .NET Libraries in MATLAB')
function block:
function Initialize()
coder.extrinsic('netSpeak');
netSpeak();
That way, you don't need to worry about using extrinsics to do complicated things like getting/setting properties.
As for passing data between the function blocks, you could have a function that maintains a persistent SpeechSynthesizer and provides it on request:
function syn = instance
persistent obj;
if isempty(obj)
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
end
syn = obj;
In your wrapper functions just call instance to get access to your synthesizer. That effectively keeps the .NET data out of Simulink by letting MATLAB work with it.
Best Answer