
%**************************************************************************
%read digital input
%**************************************************************************
function sensor_output = sensor_scan(s)
    
sensor_output = 0;                        

while sensor_output == 0                    %while no reasonable signal has been read...
    try
        fprintf(s,['@01' 13]);              %"send me your digital input" 
        
        while(s.TransferStatus ~= 'idle')   %wait until the end of data transfer
        end 

        temp = fscanf(s);                   %read the response 
        
        while(s.TransferStatus ~= 'idle')   %wait until the end of data transfer
        end
        
        temp = hex2dec(temp(2:5));          %data conversion
        sensor_output = temp;
    end
end


