
function [sys,x0,str,ts] = closeOPC(t,x,u,flag)

%closeOPC S-function for closing an OPC server

%openOPC: s-FUNCTION NEEDED TO CLOSE THE LOOP
%OUT: -RECOVERS TIME SLEEP
%FIN: -CLOSE OPC SERVER

switch flag,
case 0
   [sys,x0,str,ts]=mdlInitializeSizes(t,x,u);
case { 1, 2,4}
    sys=[];
case 3
   sys=mdlOutputs(t,x,u);   
case 9
    sys=mdlTerminate(t,x,u);
otherwise
    error(['Unhandled flag = ',num2str(flag)]);
end

function [sys,x0,str,ts]=mdlInitializeSizes(t,x,u)
sizes = simsizes;
sizes.NumContStates  = 0;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 0;
sizes.NumInputs      = 0;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;   
sys = simsizes(sizes);
x0  = [];
ts  = [-1 0];
str=[];


function sys=mdlOutputs(t,x,u)
nm=mxopc('sleep');
%toc
sys = [];

function sys=mdlTerminate(t,x,u)
mxopc('close');
sys = [];



   


