%MinoltaDemo2.m - Setup and take photometric reading from Minolta CS-100A
%                 Colorimeter/Photometer.  Uses setupCS100A. and
%                 readCS100A.m custom Cogent 2000 scripts

clear all;

%640x480 windowed display mode
config_display(0);
%setup COM1 for access to Minolta CS-100A Chroma meter
port=1;     %use COM1: port
baud=4800;  %4800 bits/sec transfer speed
parity=2;   %2=even parity
nstop=2;    %2 stop bits (0=1 stop bit)
ndata=7;    %7 data bits
config_serial(port,baud,parity,nstop,ndata);
start_cogent;

disp(' ');
disp('Start Minolta CS-100A Demo');
disp(' ');

%send initialization sequence to CS-100A
disp('Initializing meter');
[status,code] = setupCS100A( port );
if(status == 0 )
    disp('CS100A setup was successful');
    disp(' ');
else
    disp('CS100A setup failed!!!');
    disp(['Error code: ',num2str(code)]);
    disp(' ');
    return;    %error exit
end

%take a photometric reading from the Minolta CS-100A
%using custom Cogent 2000 script (readSC100A.m)
disp('Taking photometric measurement');
disp(' ');
[status,code,luminance,xcolor,ycolor]=readCS100A(port);
%display results of photometric reading
if( status == 0) %display results if reading was successful
    disp(['Luminance = ',num2str(luminance),' cd/m^2']);
    disp(['Chromaticity: x=',num2str(xcolor),', y=',num2str(ycolor)]);
    disp(['CS100A code: ',num2str(code)]);
    disp(' ');
else
    disp('A CS100A error has occurred.');
    disp(['Status code: ',num2str(status)]);
    disp(['Error code: ',num2str(code)]);
    disp(' ');
end

%exit Cogent 2000 mode
stop_cogent;

