%% FLUO TEST

close all
clear all

disp('---------------- START ---------------------');
close all;
clear all;
%% Repertoires

%% Create a serial port object for FLUO.
obj3 = instrfind('Type', 'serial', 'Port', 'COM10', 'Tag', '');
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj3);
    obj3 = serial('COM10');
else
    fclose(obj3);
    obj3 = obj3(3);
end
% Set the BaudRate
obj3.BaudRate = 19200;
obj3.Timeout= 20;

%% Settings 2010/08
scale_factor = 0.0077; %µg/L/count
darkcounts = 49;

% 
for u = 1:50;
    %% Lecture Fluo
    fopen(obj3);
    %disp('FLUO port open');
    
    % 99/99/99	99:99:99	695	74	524
    datafluo = '';
    while isempty(strmatch('99/99/99',datafluo))
        datafluo = fscanf(obj3);
    end
    %   pause(1);
    fclose(obj3);
    
    % Lecture de la valeur capteur FLUO
    if size(datafluo,2) > 27
        % Champ fluorescence
        sep= datafluo(18);
            [a,dataf1] = strtok(datafluo,sep);
            [ab,dataf2] = strtok(dataf1,sep);
            [abc,dataf4] = strtok(dataf2,sep);
            [tfluo,a] = strtok(dataf4,sep);
            fluo = str2num(char(tfluo));
            % Conversion mg/m3
            calfluo = (fluo-darkcounts)*scale_factor;
            calfluo = double(calfluo);
    end
    disp(['Fluo = ',num2str(fluo),'  CalFluo = ',num2str(calfluo),' mg/m3']);
end

disp('------------------ END ------------------------');


