%% Versuch Komplett-Setup

clc

try delete(instrfind);
end

s = serial('COM1');
set(s,'BaudRate',9600);
set(s,'DataBits',8);
set(s,'Parity','none');
set(s,'StopBits',1);
set(s,'Timeout',0.1);
set(s,'FlowControl','software');
set(s,'Terminator','CR')
fopen(s);




%**************************************************************************
%Burst
%**************************************************************************
temp = sensor_scan(s);


for i = 1:1:10                              %30 pneumatic cylinder double lifts

    while temp ~= 16374                     %while the piston is NOT in the IN position...
        fprintf(s,['#021000' 13]);          %switch off exhaust pressure
        
        while(s.TransferStatus ~= 'idle')   %wait until the end of data transfer
        end
        
        fprintf(s,['#021101' 13]);          %switch on insertion pressure
        
        while(s.TransferStatus ~= 'idle')   %wait until the end of data transfer
        end
        
        temp = sensor_scan(s);              %request sensors
        
        disp(['FOR 1, temp = ' num2str(temp)])
    end
    
    disp('IN position identified')

    while temp ~= 16373                     %while the piston is NOT in the OUT position
        fprintf(s,['#021100' 13]);          %switch off insertion pressure
        
        while(s.TransferStatus ~= 'idle')   %wait until the end of data transfer
        end
        
        fprintf(s,['#021001' 13]);          %switch on exhaust pressure
        
        while(s.TransferStatus ~= 'idle')   %wait until the end of data transfer
        end
            
        temp = sensor_scan(s);              %request sensors
        
        disp(['FOR 2, temp = ' num2str(temp)])
    end
    
    disp('OUT position identified')

end
    

    
    
    




%**************************************************************************
%End
%**************************************************************************
fclose(s);
delete(s);
clear s;

try delete(instrfind)
end

