PageRenderTime 48ms CodeModel.GetById 35ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/matlab/FlyDetectionMM.m~

http://github.com/Yniold/liftsrc
Unknown | 2099 lines | 1798 code | 301 blank | 0 comment | 0 complexity | ad792bf17e1118268931834da944cd7c MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1function varargout = FlyDetection(varargin)
   2% DETECTION M-file for FlyDetection.fig
   3%      DETECTION, by itself, creates a new DETECTION or raises the existing
   4%      singleton*.
   5%
   6%      H = DETECTION returns the handle to a new DETECTION or the handle to
   7%      the existing singleton*.
   8%
   9%      DETECTION('CALLBACK',hObject,eventData,handles,...) calls the local
  10%      function named CALLBACK in DETECTION.M with the given input arguments.
  11%
  12%      DETECTION('Property','Value',...) creates a new DETECTION or raises the
  13%      existing singleton*.  Starting from the left, property value pairs are
  14%      applied to the GUI before FlyDetection_OpeningFunction gets called.  An
  15%      unrecognized property name or invalid value makes property application
  16%      stop.  All inputs are passed to FlyDetection_OpeningFcn via varargin.
  17%
  18%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  19%      instance to run (singleton)".
  20%
  21% See also: GUIDE, GUIDATA, GUIHANDLES
  22
  23% Copyright 2002-2003 The MathWorks, Inc.
  24
  25% Edit the above text to modify the response to help FlyDetection
  26
  27% Begin initialization code - DO NOT EDIT
  28gui_Singleton = 1;
  29gui_State = struct('gui_Name',       mfilename, ...
  30                   'gui_Singleton',  gui_Singleton, ...
  31                   'gui_OpeningFcn', @FlyDetection_OpeningFcn, ...
  32                   'gui_OutputFcn',  @FlyDetection_OutputFcn, ...
  33                   'gui_LayoutFcn',  [] , ...
  34                   'gui_Callback',   []);
  35if nargin && ischar(varargin{1})
  36    gui_State.gui_Callback = str2func(varargin{1});
  37end
  38
  39if nargout
  40    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  41else
  42    gui_mainfcn(gui_State, varargin{:});
  43end
  44% End initialization code - DO NOT EDIT
  45
  46
  47% --- Executes just before FlyDetection is made visible.
  48function FlyDetection_OpeningFcn(hObject, eventdata, handles, varargin)
  49% This function has no output args, see OutputFcn.
  50% hObject    handle to figure
  51% eventdata  reserved - to be defined in a future version of MATLAB
  52% handles    structure with handles and user data (see GUIDATA)
  53% varargin   command line arguments to FlyDetection (see VARARGIN)
  54
  55% Choose default command line output for FlyDetection
  56handles.output = hObject;
  57
  58% get horus handle
  59if length(varargin)==2 & varargin{1}=='handle'
  60    handles.parenthandle=str2double(varargin{2});
  61end
  62
  63% choose Text size
  64set(double(get(handles.figure1,'Children')),'FontSize',8)
  65
  66%setup Timer function
  67handles.Timer = timer('ExecutionMode','fixedDelay',...
  68      'Period',0.7,...    
  69      'BusyMode','drop',...
  70      'TimerFcn', {@FlyDetRefresh,handles});   
  71
  72data.Timer=handles.Timer;
  73
  74data.calstatus=0; %needed for in-flight calibration
  75data.PitotTime=0; %needed for in-flight calibration
  76data.tglPitot=handles.tglPitot;
  77
  78% Update handles structure
  79guidata(hObject, handles);
  80setappdata(handles.output, 'Detdata', data);
  81start(handles.Timer);
  82
  83
  84function FlyDetRefresh(arg1,arg2,handles)
  85
  86data = getappdata(handles.output, 'Detdata');
  87
  88horusdata = getappdata(handles.parenthandle, 'horusdata');
  89statusData=horusdata.statusData;
  90AvgData=horusdata.AvgData;
  91col=horusdata.col;
  92fcts2val=horusdata.fcts2val;
  93statustime=horusdata.statustime;
  94maxLen=horusdata.maxLen;
  95lastrow=horusdata.lastrow;
  96indexZeit=horusdata.indexZeit;
  97horustxtBlower=horusdata.txtBlower;
  98if ~isequal(get(horustxtBlower,'BackgroundColor'),[0 1 1])
  99    tcpBlower=horusdata.tcpBlower;
 100end
 101
 102PlotWidth=maxLen;
 103stopPlot=maxLen;
 104startPlot=1;
 105iZeit=indexZeit(startPlot:stopPlot);
 106minTime=statustime(iZeit(1));
 107maxTime=statustime(iZeit(size(iZeit,1)));
 108xlim1=str2double(get(handles.editxlim1,'String'));
 109xlim2=str2double(get(handles.editxlim2,'String'));
 110limTime1=maxTime-xlim1./86400.0;
 111limTime2=maxTime-xlim2./86400.0;
 112if limTime2==limTime1
 113    limTime2=limTime1+1/86400.0;
 114end
 115
 116% display system time
 117disptime=statustime(lastrow)-double(statusData(lastrow,6))/86400000.0;
 118set(handles.txtTimer,'String',strcat(datestr(disptime,13),'.',num2str(statusData(lastrow,6)/100)));
 119
 120if statusData(lastrow,col.ValidSlaveDataFlag) % only if Arm is on
 121    % start pitot zero after lamp was switched on or off
 122    if data.calstatus==1 & bitget(statusData(lastrow,col.Valve1armAxis),12)==0 % lamp just switched and pitot zero is not already on
 123        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),12); %switch on pitot zero
 124        system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch
 125        system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
 126        system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to hold solenoids
 127        
 128        data.PitotTime=statustime;
 129        data.calstatus=0;
 130    end
 131    % stop pitot zero after 10 s
 132    if data.PitotTime~=0 %zeroing process active ?
 133        if (statustime-data.PitotTime)*86400>10 % for more than 10 s already ?
 134            Valveword=bitset(statusData(lastrow,col.Valve1armAxis),12,0); %switch off pitot zero
 135            system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch
 136            system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
 137            system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to hold solenoids
 138        
 139            data.PitotTime=0; 
 140        end
 141    end
 142end            
 143            
 144% calculate parameters from ADC counts
 145x=double(statusData(:,col.DiodeUV)); eval(['DiodeUV=',fcts2val.DiodeUV,';']);
 146x=double(statusData(:,col.TDet)); 
 147if x>10000
 148    eval(['TDet=',fcts2val.TDet,';']);
 149else
 150    TDet=statustime; TDet(:)=NaN;
 151end
 152%TDet=double(statusData(:,col.TDet));
 153x=double(statusData(:,col.P20)); eval(['P20=',fcts2val.P20,';']);
 154%x=double(statusData(:,col.P1000)); eval(['P1000=',fcts2val.P1000,';']);
 155x=double(statusData(:,col.DiodeWZ1out)); eval(['DiodeWZ1out=',fcts2val.DiodeWZ1out,';']);
 156x=double(statusData(:,col.DiodeWZ2out)); eval(['DiodeWZ2out=',fcts2val.DiodeWZ2out,';']);
 157x=double(statusData(:,col.DiodeWZ1in)); eval(['DiodeWZ1in=',fcts2val.DiodeWZ1in,';']);
 158x=double(statusData(:,col.DiodeWZ2in)); eval(['DiodeWZ2in=',fcts2val.DiodeWZ2in,';']);
 159x=double(statusData(:,col.PNO)); eval(['PNO=',fcts2val.PNO,';']);
 160x=double(statusData(:,col.MFCFlow)); eval(['MFCFlow=',fcts2val.MFCFlow,';']);
 161if ~isnan(col.TempDetFunnel)
 162    x=double(statusData(:,col.TempDetFunnel)); eval(['TempDetFunnel=',fcts2val.TempDetFunnel,';']);
 163else
 164    TempDetFunnel=statustime; TempDetFunnel(:)=NaN;
 165end
 166if ~isnan(col.TempPenray)
 167    x=double(statusData(:,col.TempPenray)); eval(['TempPenray=',fcts2val.TempPenray,';']);
 168else
 169    TempPenray=statustime; TempPenray(:)=NaN;
 170end
 171x=double(statusData(:,col.PitotAbs)); eval(['PitotAbs=',fcts2val.PitotAbs,';']);
 172x=double(statusData(:,col.PitotDiff)); eval(['PitotDiff=',fcts2val.PitotDiff,';']);
 173x=double(statusData(:,col.MFCC3F6Flow)); eval(['MFCC3F6Flow=',fcts2val.MFCC3F6Flow,';']);
 174x=double(statusData(:,col.MFCPropFlow)); eval(['MFCPropFlow=',fcts2val.MFCPropFlow,';']);
 175x=double(statusData(:,col.MFCShowerFlow)); eval(['MFCShowerFlow=',fcts2val.MFCShowerFlow,';']);
 176
 177set(handles.txtDiodeUV,'String',[num2str(DiodeUV(lastrow),3),' mW']);
 178set(handles.txtWZ1in,'String',[num2str(DiodeWZ1in(lastrow),3),' mW']);
 179set(handles.txtWZ1out,'String',[num2str(DiodeWZ1out(lastrow),3),' mW']);
 180set(handles.txtWZ2in,'String',[num2str(DiodeWZ2in(lastrow),3),' mW']);
 181set(handles.txtWZ2out,'String',[num2str(DiodeWZ2out(lastrow),3),' mW']);
 182set(handles.txtP1000,'String',statusData(lastrow,col.P1000));
 183set(handles.txtP20,'String',[num2str(P20(lastrow),3),' mbar']);
 184set(handles.txtPNO,'String',[num2str(PNO(lastrow),4),' mbar']);
 185set(handles.txtVHV,'String',statusData(lastrow,col.VHV));
 186set(handles.txtTDet,'String',[num2str(TDet(lastrow),3),' C']);
 187set(handles.txtTDetFunnel,'String',[num2str(TempDetFunnel(lastrow),3),' C']);
 188set(handles.txtTLamp,'String',[num2str(TempPenray(lastrow),3),' C']);
 189set(handles.txtMFCC3F6,'String',[num2str(MFCC3F6Flow(lastrow),3),' bar']);
 190set(handles.txtPabs,'String',[num2str(PitotAbs(lastrow),4),' mbar']);
 191set(handles.txtPdiff,'String',[num2str(PitotDiff(lastrow),3),' mbar']);
 192set(handles.txtMFCProp,'String',[num2str(MFCPropFlow(lastrow),3),' sccm']);
 193set(handles.txtMFCShower,'String',[num2str(MFCShowerFlow(lastrow),4),' sccm']);
 194set(handles.txtMFCNO,'String',[num2str(MFCFlow(lastrow),3),' sccm']);
 195
 196% warn for ADC signals out of allowed range for measurements
 197if P20(lastrow)<1 | P20(lastrow)>10
 198    set(handles.txtP20,'BackgroundColor','r');
 199else 
 200    set(handles.txtP20,'BackgroundColor',[0.7 0.7 0.7]);
 201end
 202if DiodeWZ1in(lastrow)<2
 203    set(handles.txtWZ1in,'BackgroundColor','r');
 204else 
 205    set(handles.txtWZ1in,'BackgroundColor',[0.7 0.7 0.7]);
 206end
 207if DiodeWZ1out(lastrow)<0.6*DiodeWZ1in
 208    set(handles.txtWZ1out,'BackgroundColor','y');
 209else 
 210    set(handles.txtWZ1out,'BackgroundColor',[0.7 0.7 0.7]);
 211end
 212if DiodeWZ2in(lastrow)<0.4
 213    set(handles.txtWZ2in,'BackgroundColor','r');
 214else 
 215    set(handles.txtWZ2in,'BackgroundColor',[0.7 0.7 0.7]);
 216end
 217if DiodeWZ2out(lastrow)<0.6*DiodeWZ2in
 218    set(handles.txtWZ2out,'BackgroundColor','y');
 219else 
 220    set(handles.txtWZ2out,'BackgroundColor',[0.7 0.7 0.7]);
 221end
 222if MFCFlow(lastrow)<4 | MFCFlow(lastrow)>9
 223    set(handles.txtMFCNO,'BackgroundColor','r');
 224else 
 225    set(handles.txtMFCNO,'BackgroundColor',[0.7 0.7 0.7]);
 226end
 227if statusData(lastrow,col.VHV)<12400
 228    set(handles.txtVHV,'BackgroundColor','y');
 229else 
 230    set(handles.txtVHV,'BackgroundColor',[0.7 0.7 0.7]);
 231end
 232%if PCuvette(lastrow)>2
 233%    if (bitget(statusData(lastrow,col.Valve1armAxis),13)==1 | bitget(statusData(lastrow,col.Valve1armAxis),13)==1)
 234%        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),13,0);
 235%        Valveword=bitset(Valveword,14,0);
 236%        system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
 237%        system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
 238%        system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
 239%    end
 240%end
 241
 242%if statusData(lastrow,col.PhototubeLamp1)>10010;
 243%    set(handles.txtMFCProp,'BackgroundColor','r');
 244%else 
 245%    set(handles.txtMFCProp,'BackgroundColor',[0.7 0.7 0.7]);
 246%end
 247%if statusData(lastrow,col.PhototubeLamp2)>10010;
 248%    set(handles.txtMFCShower,'BackgroundColor','r');
 249%else 
 250%    set(handles.txtMFCShower,'BackgroundColor',[0.7 0.7 0.7]);
 251%end
 252
 253
 254
 255
 256% plot checked parameters vs. time
 257hold(handles.axes1,'off'); 
 258if get(handles.chkDiodeUV,'Value')
 259    plot(handles.axes1,statustime(iZeit),DiodeUV(iZeit),'b');
 260    hold(handles.axes1,'on');
 261end 
 262if get(handles.chkWZ1in,'Value')
 263    plot(handles.axes1,statustime(iZeit),DiodeWZ1in(iZeit),'b');
 264    hold(handles.axes1,'on');
 265end 
 266if get(handles.chkWZ1out,'Value')
 267    plot(handles.axes1,statustime(iZeit),DiodeWZ1out(iZeit),'b');
 268    hold(handles.axes1,'on');
 269end 
 270if get(handles.chkWZ2in,'Value')
 271    plot(handles.axes1,statustime(iZeit),DiodeWZ2in(iZeit),'g');
 272    hold(handles.axes1,'on');
 273end 
 274if get(handles.chkWZ2out,'Value')
 275    plot(handles.axes1,statustime(iZeit),DiodeWZ2out(iZeit),'g');
 276    hold(handles.axes1,'on');
 277end 
 278if get(handles.chkP1000,'Value')
 279    plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.P1000),'r');
 280    hold(handles.axes1,'on');
 281end 
 282if get(handles.chkP20,'Value')
 283    plot(handles.axes1,statustime(iZeit),P20(iZeit),'r');
 284    hold(handles.axes1,'on');
 285end 
 286if get(handles.chkPNO,'Value')
 287    plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.PNO),'g');
 288    hold(handles.axes1,'on');
 289end 
 290if get(handles.chkVHV,'Value')
 291    plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.VHV),'r');
 292    hold(handles.axes1,'on');
 293end 
 294if get(handles.chkTDet,'Value')
 295    plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.TDet),'r');
 296    hold(handles.axes1,'on');
 297end 
 298if get(handles.chkMFCNO,'Value')
 299    plot(handles.axes1,statustime(iZeit),MFCFlow(iZeit),'r');
 300    hold(handles.axes1,'on');
 301end 
 302if get(handles.chkPabs,'Value')
 303    plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.PitotAbs),'r');
 304    hold(handles.axes1,'on');
 305end 
 306if get(handles.chkPdiff,'Value')
 307    plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.PitotDiff),'r');
 308    hold(handles.axes1,'on');
 309end 
 310if get(handles.chkTDetFunnel,'Value')
 311    if ~isnan(col.TempDetFunnel)
 312        plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.TempDetFunnel),'r');
 313        hold(handles.axes1,'on');
 314    end
 315end 
 316if get(handles.chkTLamp,'Value')
 317    if ~isnan(col.TempPenray)
 318        plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.TempPenray),'r');
 319        hold(handles.axes1,'on');
 320    end
 321end 
 322if get(handles.chkMFCC3F6,'Value')
 323    plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.MFCC3F6Flow),'r');
 324    hold(handles.axes1,'on');
 325end 
 326if get(handles.chkMFCProp,'Value')
 327    plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.PhototubeLamp1),'r');
 328    hold(handles.axes1,'on');
 329end 
 330if get(handles.chkMFCShower,'Value')
 331    plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.PhototubeLamp2),'r');
 332    hold(handles.axes1,'on');
 333end 
 334xlim(handles.axes1,[limTime1 limTime2]);
 335grid(handles.axes1);
 336
 337%plot PMT and MCP signals
 338
 339PMTBase=col.ccData0;
 340MCP1Base=col.ccData1;
 341MCP2Base=col.ccData2;
 342PMTMaskBase=col.ccMask0;
 343MCP1MaskBase=col.ccMask1;
 344MCP2MaskBase=col.ccMask2;
 345
 346% PMT: Has the counter mask changed ? Then read in new mask.
 347if ~isfield(data,'PMTMask')| ...
 348        ~isequal(statusData(lastrow,PMTMaskBase:PMTMaskBase+9),statusData(lastrow-5,PMTMaskBase:PMTMaskBase+9))
 349    data.PMTMask=ones(1,160);
 350    for a = 0:9,
 351        data.PMTMask((a*16+1):(a*16+16))=bitget(statusData(lastrow,PMTMaskBase+a),1:16);
 352    end
 353end
 354    
 355PMTSumCounts=statusData(:,col.ccCounts0);
 356
 357% MCP1: Has the counter mask changed ? Then read in new mask.
 358if ~isfield(data,'MCP1Mask')| ...
 359        ~isequal(statusData(lastrow,MCP1MaskBase:MCP1MaskBase+9),statusData(lastrow-5,MCP1MaskBase:MCP1MaskBase+9))
 360    data.MCP1Mask=ones(1,160);
 361    for a=0:9
 362        data.MCP1Mask((a*16+1):(a*16+16))=bitget(statusData(lastrow,MCP1MaskBase+a),1:16);
 363    end
 364end
 365
 366MCP1SumCounts=statusData(:,col.ccCounts1);
 367
 368% MCP2: Has the counter mask changed ? Then read in new mask.
 369if ~isfield(data,'MCP2Mask')| ...
 370        ~isequal(statusData(lastrow,MCP2MaskBase:MCP2MaskBase+9),statusData(lastrow-5,MCP2MaskBase:MCP2MaskBase+9))
 371    data.MCP2Mask=ones(1,160);
 372    for a=0:9
 373        data.MCP2Mask((a*16+1):(a*16+16))=bitget(statusData(lastrow,MCP2MaskBase+a),1:16);
 374    end
 375end
 376
 377MCP2SumCounts=statusData(:,col.ccCounts2);
 378
 379% display counts and pulses
 380set(handles.txtPMTCounts,'String',num2str(statusData(lastrow,col.ccCounts0),3));
 381set(handles.txtMCP1Counts,'String',num2str(statusData(lastrow,col.ccCounts1),2));
 382set(handles.txtMCP2Counts,'String',num2str(statusData(lastrow,col.ccCounts2),2));
 383
 384set(handles.txtPMTPulses,'String',num2str(statusData(lastrow,col.ccPulses0),4));
 385set(handles.txtMCP1Pulses,'String',num2str(statusData(lastrow,col.ccPulses1),4));
 386set(handles.txtMCP2Pulses,'String',num2str(statusData(lastrow,col.ccPulses2),4));
 387
 388% calculate running averages for online and both offlines
 389PMTOnlineAvg=AvgData(:,1);  
 390PMTOfflineLeftAvg=AvgData(:,2);
 391PMTOfflineRightAvg=AvgData(:,3);
 392
 393PMTOfflineAvg(1:size(statusData,1))=NaN;
 394PMTOfflineAvg=PMTOfflineAvg';
 395PMTOfflineAvg(statusData(:,col.RAvgOnOffFlag)==1)=PMTOfflineRightAvg(statusData(:,col.RAvgOnOffFlag)==1);
 396PMTOfflineAvg(statusData(:,col.RAvgOnOffFlag)==2)=PMTOfflineLeftAvg(statusData(:,col.RAvgOnOffFlag)==2);
 397
 398PMTAvg(statusData(:,col.RAvgOnOffFlag)==3)=PMTOnlineAvg(statusData(:,col.RAvgOnOffFlag)==3);
 399PMTAvg(statusData(:,col.RAvgOnOffFlag)==2)=PMTOfflineLeftAvg(statusData(:,col.RAvgOnOffFlag)==2);
 400PMTAvg(statusData(:,col.RAvgOnOffFlag)==1)=PMTOfflineRightAvg(statusData(:,col.RAvgOnOffFlag)==1);
 401PMTAvg(statusData(:,col.RAvgOnOffFlag)==0)=NaN;
 402
 403MCP1OnlineAvg=AvgData(:,4);
 404MCP1OfflineLeftAvg=AvgData(:,5);
 405MCP1OfflineRightAvg=AvgData(:,6);
 406
 407MCP1OfflineAvg(1:size(statusData,1))=NaN;
 408MCP1OfflineAvg=MCP1OfflineAvg';
 409MCP1OfflineAvg(statusData(:,col.RAvgOnOffFlag)==1)=MCP1OfflineRightAvg(statusData(:,col.RAvgOnOffFlag)==1);
 410MCP1OfflineAvg(statusData(:,col.RAvgOnOffFlag)==2)=MCP1OfflineLeftAvg(statusData(:,col.RAvgOnOffFlag)==2);
 411
 412MCP1Avg(statusData(:,col.RAvgOnOffFlag)==3)=MCP1OnlineAvg(statusData(:,col.RAvgOnOffFlag)==3);
 413MCP1Avg(statusData(:,col.RAvgOnOffFlag)==2)=MCP1OfflineLeftAvg(statusData(:,col.RAvgOnOffFlag)==2);
 414MCP1Avg(statusData(:,col.RAvgOnOffFlag)==1)=MCP1OfflineRightAvg(statusData(:,col.RAvgOnOffFlag)==1);
 415MCP1Avg(statusData(:,col.RAvgOnOffFlag)==0)=NaN;
 416
 417MCP2OnlineAvg=AvgData(:,7);
 418MCP2OfflineLeftAvg=AvgData(:,8);
 419MCP2OfflineRightAvg=AvgData(:,9);
 420
 421MCP2OfflineAvg(1:size(statusData,1))=NaN;
 422MCP2OfflineAvg=MCP2OfflineAvg';
 423MCP2OfflineAvg(statusData(:,col.RAvgOnOffFlag)==1)=MCP2OfflineRightAvg(statusData(:,col.RAvgOnOffFlag)==1);
 424MCP2OfflineAvg(statusData(:,col.RAvgOnOffFlag)==2)=MCP2OfflineLeftAvg(statusData(:,col.RAvgOnOffFlag)==2);
 425
 426MCP2Avg(statusData(:,col.RAvgOnOffFlag)==3)=MCP2OnlineAvg(statusData(:,col.RAvgOnOffFlag)==3);
 427MCP2Avg(statusData(:,col.RAvgOnOffFlag)==2)=MCP2OfflineLeftAvg(statusData(:,col.RAvgOnOffFlag)==2);
 428MCP2Avg(statusData(:,col.RAvgOnOffFlag)==1)=MCP2OfflineRightAvg(statusData(:,col.RAvgOnOffFlag)==1);
 429MCP2Avg(statusData(:,col.RAvgOnOffFlag)==0)=NaN;
 430
 431% display offline and online averages
 432set(handles.txtPMTOffline,'String',num2str(PMTOfflineAvg(lastrow),3));
 433set(handles.txtMCP1Offline,'String',num2str(MCP1OfflineAvg(lastrow),2));
 434set(handles.txtMCP2Offline,'String',num2str(MCP2OfflineAvg(lastrow),2));
 435set(handles.txtPMTOnline,'String',num2str(PMTOnlineAvg(lastrow),4));
 436set(handles.txtMCP1Online,'String',num2str(MCP1OnlineAvg(lastrow),4));
 437set(handles.txtMCP2Online,'String',num2str(MCP2OnlineAvg(lastrow),4));
 438
 439% warn if Offline Signals are zero, possible problem with MCPs
 440if MCP1OnlineAvg(lastrow)==0
 441    set(handles.txtMCP1Online,'BackgroundColor','r');
 442else
 443    set(handles.txtMCP1Online,'BackgroundColor',[0.7 0.7 0.7]);
 444end
 445if MCP2OnlineAvg(lastrow)==0
 446    set(handles.txtMCP2Online,'BackgroundColor','r');
 447else
 448    set(handles.txtMCP2Online,'BackgroundColor',[0.7 0.7 0.7]);
 449end
 450
 451% warn if PMTOnline is too low for valid online Signal
 452if PMTOnlineAvg(lastrow)<2*PMTOfflineAvg
 453    set(handles.txtPMTOnline,'BackgroundColor','r');
 454else
 455    set(handles.txtPMTOnline,'BackgroundColor',[0.7 0.7 0.7]);
 456end
 457
 458%calculate OH and HO2 mixing ratios
 459if statusData(lastrow,col.ValidSlaveDataFlag)
 460    radlife=1.45e6;			% Radiative lifetime (Hz) from D. Heard data
 461    % THESE PARAMETERS NEED TO BE CONSIDERED WHEN RUNNING THE INSTRUMENT IN A
 462    % DIFFERENT SETUP
 463    gate1=136e-9;			   % Approximate gate setting for rising edge (sec)
 464    gate2=596e-9;		   	% ...for falling edge (sec)
 465    Tcal=299;			      % Cell Temperature during lab calibration (K)
 466    Pcal=3.7;
 467    PowCal=10;		%OHUVPower during lab calibration (mW)
 468    PowCalb=1.75;		%HO2UVPower during lab calibration (mW)
 469    wmrcal=8E-3;	         % Calibration reference water concentration
 470
 471    k_qcal=getq(Tcal,wmrcal);
 472    GAMMAcal= k_qcal*Pcal + radlife;  
 473    densCal=(6.022E+23/22400)*273/Tcal*Pcal/1013;
 474
 475    bc=boltzcorr(Tcal,TDet(lastrow)+273);
 476    k_q=getq(TDet(lastrow)+273,str2double(get(handles.editH2O,'String')));
 477    GAMMA = k_q*P20(lastrow) + radlife;
 478
 479    quen = (1/GAMMA).*((exp(-gate1*GAMMA)-exp(-gate2*GAMMA)));
 480    quencal = (1/GAMMAcal).*((exp(-gate1*GAMMAcal)-exp(-gate2*GAMMAcal)));
 481
 482    Dens=6.023E23/22400*273./(TDet(lastrow)+273)*P20(lastrow)/1013; %Converting to density
 483
 484    COH=quen.*bc.*(str2double(get(handles.editC,'String'))/quencal/densCal)*Dens;
 485    COH=COH.*(DiodeWZ1in(lastrow)+DiodeWZ1out(lastrow))/2;
 486
 487    CHO2b=quen.*bc.*(str2double(get(handles.editC,'String'))/quencal/densCal)*Dens;
 488    CHO2b=CHO2b.*(DiodeWZ2in(lastrow)+DiodeWZ2out(lastrow))/2;
 489    if ~isnan(COH)
 490        if rank(COH)~=0
 491             XOH = (MCP1OnlineAvg-MCP1OfflineAvg).*5./COH';
 492        end
 493    else
 494        XOH = MCP1OnlineAvg; XOH(:)=NaN;
 495    end
 496    if ~isnan(COH)
 497        if rank(CHO2b)~=0
 498            XHOx = (MCP2OnlineAvg-MCP2OfflineAvg).*5./CHO2b';
 499        end
 500    else
 501        XHOx = MCP1OnlineAvg; XHOx(:)=NaN;
 502    end
 503else
 504    XOH = MCP1OnlineAvg; XOH(:)=NaN;
 505    XHOx = MCP1OnlineAvg; XHOx(:)=NaN;
 506end    
 507
 508% make plots 
 509hold(handles.axeRay,'off');
 510hold(handles.axeFluo,'off');
 511hold(handles.axeCounts,'off');
 512
 513if get(handles.chkPMT,'Value')
 514    plot(handles.axeRay,statusData(lastrow,PMTBase+1:PMTBase+160),'r'); 
 515    hold(handles.axeRay,'on'); 
 516    z=find(data.PMTMask==0);
 517    PMTdata1=double(statusData(lastrow,PMTBase+1:PMTBase+160));
 518    PMTdata1(z)=NaN;
 519    plot(handles.axeRay,PMTdata1); 
 520    xlim(handles.axeRay,[1,160]); 
 521    
 522    xaxis=[40:160];
 523    plot(handles.axeFluo,xaxis,statusData(lastrow,PMTBase+40:PMTBase+160),'r');
 524    hold(handles.axeFluo,'on');
 525    y=data.PMTMask(40:160);
 526    z=find(y==0);
 527    PMTdata2=double(statusData(lastrow,PMTBase+40:PMTBase+160));
 528    PMTdata2(z)=NaN;
 529    plot(handles.axeFluo,xaxis,PMTdata2); 
 530    xlim(handles.axeFluo,[40,160]); 
 531    
 532    WhichPlot=get(handles.popPMTPlot,'Value');
 533    switch WhichPlot
 534        case 1
 535           plot(handles.axeCounts,statustime(iZeit),PMTSumCounts(iZeit)); %statusData(iZeit,PMTBase+204));
 536           xlim1=str2double(get(handles.editxlim1,'String'));
 537           xlim2=str2double(get(handles.editxlim2,'String'));
 538           limTime1=maxTime-xlim1./86400.0;
 539           limTime2=maxTime-xlim2./86400.0;
 540           xlim(handles.axes1,[limTime1 limTime2]);
 541
 542           hold(handles.axeCounts,'on');
 543        case 2           
 544           plot(handles.axeCounts,statustime(30:end),PMTAvg(30:end),'b');   
 545           hold(handles.axeCounts,'on');
 546    end
 547    hold(handles.axeCounts,'on');
 548end
 549
 550if get(handles.chkMCP1,'Value')
 551    plot(handles.axeRay,statusData(lastrow,MCP1Base+1:MCP1Base+160),'r'); 
 552    hold(handles.axeRay,'on'); 
 553    z=find(data.MCP1Mask==0);
 554    MCP1data1=double(statusData(lastrow,MCP1Base+1:MCP1Base+160));
 555    MCP1data1(z)=NaN;
 556    plot(handles.axeRay,MCP1data1); 
 557    xlim(handles.axeRay,[1,160]); 
 558    
 559    xaxis=[40:160];
 560    plot(handles.axeFluo,xaxis, statusData(lastrow,MCP1Base+40:MCP1Base+160),'r');
 561    hold(handles.axeFluo,'on');
 562    y=data.MCP1Mask(40:160);
 563    z=find(y==0);
 564    MCP1data2=double(statusData(lastrow,MCP1Base+40:MCP1Base+160));
 565    MCP1data2(z)=NaN;
 566    plot(handles.axeFluo,xaxis,MCP1data2); 
 567    xlim(handles.axeFluo,[40,160]); 
 568
 569    WhichPlot=get(handles.popMCP1Plot,'Value');
 570    switch WhichPlot
 571        case 1
 572           plot(handles.axeCounts,statustime(iZeit),MCP1SumCounts(iZeit)); %statusData(iZeit,MCP1Base+204));
 573           hold(handles.axeCounts,'on');
 574        case 2           
 575           plot(handles.axeCounts,statustime(30:end),MCP1Avg(30:end),'b');   
 576           hold(handles.axeCounts,'on');
 577        case 3           
 578           plot(handles.axeCounts,statustime(30:end),XOH(30:end),'b');   
 579           hold(handles.axeCounts,'on');
 580    end
 581    hold(handles.axeCounts,'on');
 582end
 583
 584if get(handles.chkMCP2,'Value')
 585    plot(handles.axeRay,statusData(lastrow,MCP2Base+1:MCP2Base+160),'r'); 
 586    hold(handles.axeRay,'on'); 
 587    z=find(data.MCP2Mask==0);
 588    MCP2data1=double(statusData(lastrow,MCP2Base+1:MCP2Base+160));
 589    MCP2data1(z)=NaN;
 590    plot(handles.axeRay,MCP2data1); 
 591    xlim(handles.axeRay,[1,160]); 
 592    
 593    xaxis=[40:160];
 594    plot(handles.axeFluo,xaxis,statusData(lastrow,MCP2Base+40:MCP2Base+160),'r');
 595    hold(handles.axeFluo,'on');
 596    y=data.MCP2Mask(40:160);
 597    z=find(y==0);
 598    MCP2data2=double(statusData(lastrow,MCP2Base+40:MCP2Base+160));
 599    MCP2data2(z)=NaN;
 600    plot(handles.axeFluo,xaxis,MCP2data2); 
 601    xlim(handles.axeFluo,[40,160]); 
 602
 603    WhichPlot=get(handles.popMCP2Plot,'Value');
 604    switch WhichPlot
 605        case 1
 606           plot(handles.axeCounts,statustime(iZeit),MCP2SumCounts(iZeit),'r'); %statusData(iZeit,MCP2Base+204));
 607           hold(handles.axeCounts,'on');
 608        case 2           
 609           plot(handles.axeCounts,statustime(30:end),MCP2Avg(30:end),'r');   
 610           hold(handles.axeCounts,'on');
 611        case 3           
 612           plot(handles.axeCounts,statustime(30:end),XHOx(30:end),'r');   
 613           hold(handles.axeCounts,'on');
 614    end
 615    hold(handles.axeCounts,'on');
 616end
 617
 618xlim(handles.axeCounts,[limTime1 limTime2]);
 619grid(handles.axeCounts);
 620
 621% check HV
 622if bitget(statusData(lastrow,col.Valve2armAxis),8)==0
 623    %    set(handles.togHV,'Value',0)
 624    set(handles.togHV,'BackgroundColor','c','String','HV OFF');
 625else
 626    if bitget(statusData(lastrow,col.ccGateDelay1),16)==0 ...
 627            | bitget(statusData(lastrow,col.ccGateDelay2),16)==0
 628        set(handles.togHV,'BackgroundColor','y','String','HV ON');
 629    else
 630    %    set(handles.togHV,'Value',1)
 631        set(handles.togHV,'BackgroundColor','g','String','HV ON');
 632    end
 633end
 634
 635% check Pump, Bit 10 is Leybold, Bit 7 is Scroll Pump
 636if ~isequal(get(handles.togPump,'BackgroundColor'),[1 1 0])  % if Pump is not just being switched
 637    if ~isequal(get(horustxtBlower,'BackgroundColor'),[0 1 1]) % Blower connected via tcp (ground configuration)
 638        % no actual check is done, to recheck push button in horus has to be used
 639        BlowerStatus=get(horustxtBlower,'String');
 640        if (strcmp(BlowerStatus,'Pump ON') | strcmp(BlowerStatus,'Blower ON'))
 641            set(handles.togPump,'BackgroundColor','g','String','Pump ON');
 642        else 
 643            set(handles.togPump,'BackgroundColor','c','String','Pump OFF');
 644        end
 645    else % Blower connected directly to ARMaxis (air configuration)
 646        if (bitget(statusData(lastrow,col.Valve2armAxis),10) & bitget(statusData(lastrow,col.Valve2armAxis),7))
 647            set(handles.togPump,'BackgroundColor','g','String','Pump ON');
 648        else
 649            set(handles.togPump,'BackgroundColor','c','String','Pump OFF');
 650        end
 651    end
 652end
 653
 654% check Blower
 655if ~isequal(get(handles.togBlower,'BackgroundColor'),[1 1 0])  % if Blower is not just being switched
 656    if ~isequal(get(horustxtBlower,'BackgroundColor'),[0 1 1]) % Blower connected via tcp (ground configuration)
 657        % no actual check is done, to recheck push button in horus has to be used
 658        BlowerStatus=get(horustxtBlower,'String');
 659        if strcmp(BlowerStatus,'Blower ON')
 660            set(handles.togBlower,'BackgroundColor','g','String','Blower ON');
 661        else
 662            set(handles.togBlower,'BackgroundColor','c','String','Blower OFF');
 663        end
 664    else % Blower connected directly to ARMaxis (air configuration)
 665        if ((bitget(statusData(lastrow,col.Valve2armAxis),9) & ...
 666            bitget(statusData(lastrow,col.Valve2armAxis),1)))
 667            set(handles.togBlower,'BackgroundColor','g','String','Blower ON');
 668        else
 669            set(handles.togBlower,'BackgroundColor','c','String','Blower OFF');
 670        end
 671    end
 672end
 673
 674% check Butterfly
 675% Butterfly with relay
 676if bitget(statusData(lastrow,col.Valve2armAxis),2)==1
 677        set(handles.togButterfly,'BackgroundColor','c','String','Butterfly CLOSED');
 678else
 679        set(handles.togButterfly,'BackgroundColor','g','String','Butterfly OPEN');
 680end
 681% end Butterfly with relay
 682
 683% Butterfly with stepper motor
 684%if statusData(lastrow,col.ButterflyPositionValid)==0
 685%    set(handles.togButterfly,'BackgroundColor','r','String','Butterfly INIT');
 686%else
 687%    if statusData(lastrow,col.ButterflyCurrentPosition)==42
 688%        set(handles.togButterfly,'BackgroundColor','c','String','Butterfly CLOSED');
 689%    elseif statusData(lastrow,col.ButterflyCurrentPosition)==(625+42)
 690%        set(handles.togButterfly,'BackgroundColor','g','String','Butterfly OPEN');
 691%    else
 692%        set(handles.togButterfly,'BackgroundColor','r','String','MOVING');
 693%    end
 694%end
 695% end Butterfly with stepper motor
 696
 697% check Lamp
 698if bitget(statusData(lastrow,col.Valve2armAxis),11)
 699    set(handles.tglLamp,'BackgroundColor','r','String','Lamp ON');
 700else
 701    set(handles.tglLamp,'BackgroundColor','c','String','Lamp OFF');
 702end
 703
 704% check Pitot Zeroing Valve
 705if bitget(statusData(lastrow,col.Valve1armAxis),12)
 706    set(handles.tglPitot,'BackgroundColor','y','String','Pitot 0 ON');
 707else
 708    set(handles.tglPitot,'BackgroundColor','c','String','Pitot 0 OFF');
 709end
 710
 711% check Heaters
 712% Heater Lamp
 713if bitget(statusData(lastrow,col.Valve2armAxis),3)
 714    set(handles.tglHeatLamp,'BackgroundColor','g');
 715else
 716    set(handles.tglHeatLamp,'BackgroundColor','y');
 717end
 718% Heater Prallplatte
 719if bitget(statusData(lastrow,col.Valve2armAxis),4)
 720    set(handles.tglHeatPrall,'BackgroundColor','g');
 721else
 722    set(handles.tglHeatPrall,'BackgroundColor','y');
 723end
 724% Heater Phototube 2
 725if bitget(statusData(lastrow,col.Valve2armAxis),5)
 726    set(handles.tglHeatPhoto2,'BackgroundColor','g');
 727else
 728    set(handles.tglHeatPhoto2,'BackgroundColor','y');
 729end
 730
 731% check solenoids
 732if bitget(statusData(lastrow,col.Valve1armAxis),4)==0
 733    set(handles.toggleC3F6,'BackgroundColor','c');
 734else 
 735    set(handles.toggleC3F6,'BackgroundColor','r');
 736end
 737if bitget(statusData(lastrow,col.Valve1armAxis),3)==0
 738    set(handles.toggleN2,'BackgroundColor','c');
 739else 
 740    set(handles.toggleN2,'BackgroundColor','r');
 741end
 742if bitget(statusData(lastrow,col.Valve1armAxis),2)==0
 743    set(handles.toggleHO2Inj,'BackgroundColor','c');
 744else 
 745    set(handles.toggleHO2Inj,'BackgroundColor','g');
 746end
 747if bitget(statusData(lastrow,col.Valve1armAxis),1)==0
 748    set(handles.toggleOHInj,'BackgroundColor','c');
 749else 
 750    set(handles.toggleOHInj,'BackgroundColor','r');
 751end
 752if bitget(statusData(lastrow,col.Valve1armAxis),7)==0
 753    set(handles.toggleNO1,'BackgroundColor','c');
 754else 
 755    set(handles.toggleNO1,'BackgroundColor','g');
 756end
 757if bitget(statusData(lastrow,col.Valve1armAxis),6)==0
 758    set(handles.toggleNO2,'BackgroundColor','c');
 759else 
 760    set(handles.toggleNO2,'BackgroundColor','g');
 761end
 762if bitget(statusData(lastrow,col.Valve1armAxis),5)==0
 763    set(handles.toggleNOPurge,'BackgroundColor','c');
 764else 
 765    set(handles.toggleNOPurge,'BackgroundColor','g');
 766end
 767if bitget(statusData(lastrow,col.Valve1armAxis),14)==0
 768    set(handles.tglN2O,'BackgroundColor','c');
 769else 
 770    set(handles.tglN2O,'BackgroundColor','g');
 771end
 772if bitget(statusData(lastrow,col.Valve1armAxis),13)==0
 773    set(handles.tglVac,'BackgroundColor','c');
 774else 
 775    set(handles.tglVac,'BackgroundColor','g');
 776end
 777%if bitget(statusData(lastrow,col.Valve2armAxis),12)==0
 778%    set(handles.tglKuv,'BackgroundColor','c');
 779%else 
 780%    set(handles.tglKuv,'BackgroundColor','g');
 781%end
 782if bitget(statusData(lastrow,col.Valve1armAxis),4)==0
 783    set(handles.tglVent,'BackgroundColor','c');
 784else 
 785    set(handles.tglVent,'BackgroundColor','r');
 786end
 787
 788data.lastrow=lastrow;
 789setappdata(handles.output, 'Detdata', data);
 790
 791% --- Outputs from this function are returned to the command line.
 792function varargout = FlyDetection_OutputFcn(hObject, eventdata, handles) 
 793% varargout  cell array for returning output args (see VARARGOUT);
 794% hObject    handle to figure
 795% eventdata  reserved - to be defined in a future version of MATLAB
 796% handles    structure with handles and user data (see GUIDATA)
 797
 798% Get default command line output from handles structure
 799varargout{1} = handles.output;
 800
 801
 802% --- Executes on button press in chkPMT.
 803function chkPMT_Callback(hObject, eventdata, handles)
 804% hObject    handle to chkPMT (see GCBO)
 805% eventdata  reserved - to be defined in a future version of MATLAB
 806% handles    structure with handles and user data (see GUIDATA)
 807
 808% Hint: get(hObject,'Value') returns toggle state of chkPMT
 809
 810
 811% --- Executes on button press in chkMCP2.
 812function chkMCP2_Callback(hObject, eventdata, handles)
 813% hObject    handle to chkMCP2 (see GCBO)
 814% eventdata  reserved - to be defined in a future version of MATLAB
 815% handles    structure with handles and user data (see GUIDATA)
 816
 817% Hint: get(hObject,'Value') returns toggle state of chkMCP2
 818
 819
 820% --- Executes on button press in chkMCP1.
 821function chkMCP1_Callback(hObject, eventdata, handles)
 822% hObject    handle to chkMCP1 (see GCBO)
 823% eventdata  reserved - to be defined in a future version of MATLAB
 824% handles    structure with handles and user data (see GUIDATA)
 825
 826% Hint: get(hObject,'Value') returns toggle state of chkMCP1
 827
 828
 829% --- Executes on button press in pshExit.
 830function pshExit_Callback(hObject, eventdata, handles)
 831% hObject    handle to pshExit (see GCBO)
 832% eventdata  reserved - to be defined in a future version of MATLAB
 833% handles    structure with handles and user data (see GUIDATA)
 834
 835% Hint: get(hObject,'Value') returns toggle state of pshExit
 836horusdata = getappdata(handles.parenthandle, 'horusdata');
 837statusData=horusdata.statusData;
 838data = getappdata(handles.output, 'Detdata');
 839lastrow=data.lastrow;
 840col=horusdata.col;
 841
 842%close N2 valves to detection tubes
 843if statusData(lastrow,col.ValidSlaveDataFlag)
 844    Valveword=bitset(statusData(lastrow,col.Valve1armAxis),13,0);
 845    Valveword=bitset(Valveword,14,0);
 846    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
 847    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
 848    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
 849end
 850
 851stop(handles.Timer);
 852delete(handles.Timer);
 853close(handles.figure1);
 854
 855
 856% --- Executes on selection change in popPMTPlot.
 857function popPMTPlot_Callback(hObject, eventdata, handles)
 858% hObject    handle to popPMTPlot (see GCBO)
 859% eventdata  reserved - to be defined in a future version of MATLAB
 860% handles    structure with handles and user data (see GUIDATA)
 861
 862% Hints: contents = get(hObject,'String') returns popPMTPlot contents as cell array
 863%        contents{get(hObject,'Value')} returns selected item from popPMTPlot
 864
 865
 866% --- Executes during object creation, after setting all properties.
 867function popPMTPlot_CreateFcn(hObject, eventdata, handles)
 868% hObject    handle to popPMTPlot (see GCBO)
 869% eventdata  reserved - to be defined in a future version of MATLAB
 870% handles    empty - handles not created until after all CreateFcns called
 871
 872% Hint: popupmenu controls usually have a white background on Windows.
 873%       See ISPC and COMPUTER.
 874if ispc
 875    set(hObject,'BackgroundColor','white');
 876else
 877    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
 878end
 879
 880
 881% --- Executes on selection change in popMCP1Plot.
 882function popMCP1Plot_Callback(hObject, eventdata, handles)
 883% hObject    handle to popMCP1Plot (see GCBO)
 884% eventdata  reserved - to be defined in a future version of MATLAB
 885% handles    structure with handles and user data (see GUIDATA)
 886
 887% Hints: contents = get(hObject,'String') returns popMCP1Plot contents as cell array
 888%        contents{get(hObject,'Value')} returns selected item from popMCP1Plot
 889
 890
 891% --- Executes during object creation, after setting all properties.
 892function popMCP1Plot_CreateFcn(hObject, eventdata, handles)
 893% hObject    handle to popMCP1Plot (see GCBO)
 894% eventdata  reserved - to be defined in a future version of MATLAB
 895% handles    empty - handles not created until after all CreateFcns called
 896
 897% Hint: popupmenu controls usually have a white background on Windows.
 898%       See ISPC and COMPUTER.
 899if ispc
 900    set(hObject,'BackgroundColor','white');
 901else
 902    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
 903end
 904
 905
 906% --- Executes on selection change in popMCP2Plot.
 907function popMCP2Plot_Callback(hObject, eventdata, handles)
 908% hObject    handle to popMCP2Plot (see GCBO)
 909% eventdata  reserved - to be defined in a future version of MATLAB
 910% handles    structure with handles and user data (see GUIDATA)
 911
 912% Hints: contents = get(hObject,'String') returns popMCP2Plot contents as cell array
 913%        contents{get(hObject,'Value')} returns selected item from popMCP2Plot
 914
 915
 916% --- Executes during object creation, after setting all properties.
 917function popMCP2Plot_CreateFcn(hObject, eventdata, handles)
 918% hObject    handle to popMCP2Plot (see GCBO)
 919% eventdata  reserved - to be defined in a future version of MATLAB
 920% handles    empty - handles not created until after all CreateFcns called
 921
 922% Hint: popupmenu controls usually have a white background on Windows.
 923%       See ISPC and COMPUTER.
 924if ispc
 925    set(hObject,'BackgroundColor','white');
 926else
 927    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
 928end
 929
 930
 931% --- Executes on button press in chkWZ1out.
 932function chkWZ1out_Callback(hObject, eventdata, handles)
 933% hObject    handle to chkWZ1out (see GCBO)
 934% eventdata  reserved - to be defined in a future version of MATLAB
 935% handles    structure with handles and user data (see GUIDATA)
 936
 937% Hint: get(hObject,'Value') returns toggle state of chkWZ1out
 938
 939
 940% --- Executes on button press in chkWZ1in.
 941function chkWZ1in_Callback(hObject, eventdata, handles)
 942% hObject    handle to chkWZ1in (see GCBO)
 943% eventdata  reserved - to be defined in a future version of MATLAB
 944% handles    structure with handles and user data (see GUIDATA)
 945
 946% Hint: get(hObject,'Value') returns toggle state of chkWZ1in
 947
 948
 949% --- Executes on button press in chkPNO.
 950function chkPNO_Callback(hObject, eventdata, handles)
 951% hObject    handle to chkPNO (see GCBO)
 952% eventdata  reserved - to be defined in a future version of MATLAB
 953% handles    structure with handles and user data (see GUIDATA)
 954
 955% Hint: get(hObject,'Value') returns toggle state of chkPNO
 956
 957
 958% --- Executes on button press in chkP20.
 959function chkP20_Callback(hObject, eventdata, handles)
 960% hObject    handle to chkP20 (see GCBO)
 961% eventdata  reserved - to be defined in a future version of MATLAB
 962% handles    structure with handles and user data (see GUIDATA)
 963
 964% Hint: get(hObject,'Value') returns toggle state of chkP20
 965
 966
 967% --- Executes on button press in chkP1000.
 968function chkP1000_Callback(hObject, eventdata, handles)
 969% hObject    handle to chkP1000 (see GCBO)
 970% eventdata  reserved - to be defined in a future version of MATLAB
 971% handles    structure with handles and user data (see GUIDATA)
 972
 973% Hint: get(hObject,'Value') returns toggle state of chkP1000
 974
 975
 976% --- Executes on button press in togglebutton3.
 977function togBlower_Callback(hObject, eventdata, handles)
 978% hObject    handle to togglebutton3 (see GCBO)
 979% eventdata  reserved - to be defined in a future version of MATLAB
 980% handles    structure with handles and user data (see GUIDATA)
 981
 982% Hint: get(hObject,'Value') returns toggle state of togglebutton3
 983horusdata = getappdata(handles.parenthandle, 'horusdata');
 984statusData=horusdata.statusData;
 985data = getappdata(handles.output, 'Detdata');
 986lastrow=data.lastrow;
 987col=horusdata.col;
 988horustxtBlower=horusdata.txtBlower;
 989if ~isequal(get(horustxtBlower,'BackgroundColor'),[0 1 1]) % blower connected via tcpip (ground configuration)
 990    set(hObject,'BackgroundColor','y');
 991    tcpBlower=horusdata.tcpBlower;
 992    % check Blower and Pump status 
 993    fprintf(tcpBlower,'status'); 
 994    pause(0.5);
 995    BlowerStatus=tcpBlower.UserData;
 996    tcpBlower.UserData=[];
 997    if BlowerStatus(strfind(BlowerStatus,'Pump')+7)=='f'
 998        PumpSwitch=0;
 999    elseif BlowerStatus(strfind(BlowerStatus,'Pump')+7)=='n'
1000        PumpSwitch=1;
1001    else PumpSwitch=-1;
1002    end
1003    if BlowerStatus(strfind(BlowerStatus,'Inverter')+11)=='f'
1004        InverterSwitch=0;
1005    elseif BlowerStatus(strfind(BlowerStatus,'Inverter')+11)=='n'
1006        InverterSwitch=1;
1007    else InverterSwitch=-1;
1008    end
1009    if BlowerStatus(strfind(BlowerStatus,'Ramp')+7)=='f'
1010        RampSwitch=0;
1011    elseif BlowerStatus(strfind(BlowerStatus,'Ramp')+7)=='n'
1012        RampSwitch=1;
1013    else RampSwitch=-1;
1014    end
1015end
1016
1017if statusData(lastrow,col.ValidSlaveDataFlag) % only if armaxis is active
1018    if get(hObject,'Value') % switch on
1019        if ~isequal(get(horustxtBlower,'BackgroundColor'),[0 1 1]) % Blower connected via tcp (ground configuration)
1020                set(hObject,'BackgroundColor','y','String','switching Blower ON');
1021                % switch on Blower only when pump is on and cell pressure P1000
1022                % is low enough and Butterfly has been initialized
1023   %             if (PumpSwitch==0 | statusData(lastrow,col.P1000)>10300 | statusData(lastrow,col.ButterflyPositionValid)==0)
1024%                    set(handles.txtP1000,'BackgroundColor','r');
1025%                    disp('Pressure too high or Butterfly not initialized');
1026%                    set(hObject,'BackgroundColor','c','String','Blower OFF');                
1027    %            else
1028                    set(handles.txtP1000,'BackgroundColor',[0.7 0.7 0.7]);
1029                    fprintf(tcpBlower,'inverter on');
1030                    pause(0.5)
1031                    tcpBlower.UserData=[];
1032                    fprintf(tcpBlower,'ramp on');
1033                    pause(0.5)
1034                    tcpBlower.UserData=[];
1035     %           end
1036
1037        else % Blower connected directly to armaxis (air configuration)
1038            if isequal(get(hObject,'BackgroundColor'),[0 1 1])
1039                set(hObject,'BackgroundColor','y','String','switching Blower ON');
1040                % switch on Blower only when pump is on and cell pressure
1041                % P1000
1042                % is low enough and Butterfly has been initialized
1043% Butterfly with stepper motor
1044                %                if ( (bitget(statusData(lastrow,col.Valve2armAxis),10)==0 | bitget(statusData(lastrow,col.Valve2armAxis),7)==0) ...
1045%                    | statusData(lastrow,col.P1000)>10300 | statusData(lastrow,col.ButterflyPositionValid)==0)
1046% end Butterfly with stepper motor
1047% Butterfly with relay
1048                                if ( (bitget(statusData(lastrow,col.Valve2armAxis),10)==0 | bitget(statusData(lastrow,col.Valve2armAxis),7)==0) ...
1049                    | statusData(lastrow,col.P1000)>10300)
1050% end Butterfly with relay
1051                    set(handles.txtP1000,'BackgroundColor','r');
1052                    disp('Pressure too high or Butterfly not initialized');
1053                    set(hObject,'BackgroundColor','c','String','Blower OFF');                
1054                else
1055                    set(handles.txtP1000,'BackgroundColor',[0.7 0.7 0.7]);
1056                    Valveword=bitset(statusData(lastrow,col.Valve2armAxis),10);  % make sure Leybold pump is not switched off
1057                    Valveword=bitset(Valveword,7);  % make sure Scroll pump is not switched off
1058                    Valveword=bitset(Valveword,9); % switch on blower
1059                    Valveword=bitset(Valveword,1); % ramp blower up 
1060                    system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to switch
1061                    system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1062                    set(hObject,'BackgroundColor','g','String','Blower ON');
1063                end
1064            end
1065        end
1066    else % switch off
1067        if ~isequal(get(horustxtBlower,'BackgroundColor'),[0 1 1]) % Blower connected via tcp (ground configuration)
1068                set(hObject,'BackgroundColor','y','String','switching Blower OFF');
1069% Butterfly with stepper motor
1070                system(['/lift/bin/eCmd @armAxis s butterflyposition ',num2str(42)]); % close Butterfly 
1071% end Butterfly with stepper motor
1072% Butterfly with relay
1073                Valveword=bitset(statusData(lastrow,col.Valve2armAxis),2,1); % close Butterfly
1074                system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1075% end Butterfly with relay
1076
1077                set(handles.togButterfly,'BackgroundColor','r','String','MOVING');
1078                fprintf(tcpBlower,'ramp off');  % ramp blower down
1079                pause(0.5);
1080                tcpBlower.UserData=[];
1081                pause(10);
1082                fprintf(tcpBlower,'inverter off');  % switch off blower
1083                tcpBlower.UserData=[];
1084
1085        else % Blower connected directly to armaxis (air configuration)
1086            if isequal(get(hObject,'BackgroundColor'),[0 1 0]) | isequal(get(hObject,'BackgroundColor'),[1 0 0])
1087                set(hObject,'BackgroundColor','y','String','switching Blower OFF');
1088% Butterfly with stepper motor                
1089                system(['/lift/bin/eCmd @armAxis s butterflyposition ',num2str(42)]); % close Butterfly 
1090% end Butterfly with stepper motor
1091% Butterfly with relay
1092                Valveword=bitset(statusData(lastrow,col.Valve2armAxis),2,1); % close Butterfly
1093                system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1094% end Butterfly with relay
1095                set(handles.togButterfly,'BackgroundColor','r','String','MOVING');
1096                Valveword=bitset(statusData(lastrow,col.Valve2armAxis),1,0); % ramp blower down
1097    %            Valveword=bitset(Valveword,13); % ventilate Pump
1098                system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1099                system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1100                system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to other valves working
1101    %            set(handles.tglVent,'BackgroundColor','r');
1102                pause(5);
1103                Valveword=bitset(statusData(lastrow,col.Valve2armAxis),1,0); % make sure ramp down switch is set
1104    %            Valveword=bitset(Valveword,13); % ventilate Pump
1105                Valveword=bitset(Valveword,9,0); % switch off blower
1106                system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to switch
1107                system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1108                set(hObject,'BackgroundColor','c','String','Blower OFF');
1109            end
1110        end
1111    end
1112end
1113
1114%for ground configuration, recheck pump status
1115if ~isequal(get(horustxtBlower,'BackgroundColor'),[0 1 1])
1116    fprintf(tcpBlower,'status'); 
1117    pause(0.5);
1118    BlowerStatus=tcpBlower.UserData;
1119    tcpBlower.UserData=[];
1120    if BlowerStatus(strfind(BlowerStatus,'Pump')+7)=='f'
1121        PumpSwitch=0;
1122    elseif BlowerStatus(strfind(BlowerStatus,'Pump')+7)=='n'
1123        PumpSwitch=1;
1124    else PumpSwitch=-1;
1125    end
1126    if BlowerStatus(strfind(BlowerStatus,'Inverter')+11)=='f'
1127        InverterSwitch=0;
1128    elseif BlowerStatus(strfind(BlowerStatus,'Inverter')+11)=='n'
1129        InverterSwitch=1;
1130    else InverterSwitch=-1;
1131    end
1132    if BlowerStatus(strfind(BlowerStatus,'Ramp')+7)=='f'
1133        RampSwitch=0;
1134    elseif BlowerStatus(strfind(BlowerStatus,'Ramp')+7)=='n'
1135        RampSwitch=1;
1136    else RampSwitch=-1;
1137    end
1138   
1139    if PumpSwitch==0
1140        set(horustxtBlower,'String','Pump OFF'); 
1141    else
1142        set(horustxtBlower,'String','Pump ON'); 
1143    end
1144    if (RampSwitch==0 | InverterSwitch==0)
1145        set(hObject,'BackgroundColor','c','String','Blower OFF');
1146    else
1147        set(horustxtBlower,'String','Blower ON','BackgroundColor','g');
1148        set(hObject,'BackgroundColor','g','String','Blower ON');
1149    end
1150    if (PumpSwitch==-1 | RampSwitch==-1 | InverterSwitch==-1)
1151        set(hObject,'BackgroundColor','r','String','Blower ERR');
1152        set(horustxtBlower,'String','Blower ERROR','BackgroundColor','r');
1153    end
1154end
1155
1156
1157
1158% --- Executes on button press in togHV.
1159function togHV_Callback(hObject, eventdata, handles)
1160% switches HV and Gain
1161
1162% hObject    handle to togHV (see GCBO)
1163% eventdata  reserved - to be defined in a future version of MATLAB
1164% handles    structure with handles and user data (see GUIDATA)
1165
1166% Hint: get(hObject,'Value') returns toggle state of togHV
1167horusdata = getappdata(handles.parenthandle, 'horusdata');
1168statusData=horusdata.statusData;
1169data = getappdata(handles.output, 'Detdata');
1170lastrow=data.lastrow;
1171col=horusdata.col;
1172
1173if statusData(lastrow,col.ValidSlaveDataFlag)
1174    if get(hObject,'Value')
1175        if isequal(get(hObject,'BackgroundColor'),[0 1 1]) | isequal(get(hObject,'BackgroundColor'),[1 1 0])
1176            set(hObject,'BackgroundColor','g','String','HV ON');
1177            Valveword=bitset(statusData(lastrow,col.Valve2armAxis),8);  % switch HV on
1178            % switch gain on for MCP1
1179            word1=bitset(statusData(lastrow,col.ccGateDelay1),16);
1180            % switch gain on for MCP2
1181            word2=bitset(statusData(lastrow,col.ccGateDelay2),16);
1182            system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to switch HV
1183            system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1184            system(['/lift/bin/eCmd @armAxis w 0xa318 ',num2str(word1)]);
1185            system(['/lift/bin/eCmd @armAxis w 0xa31c ',num2str(word2)]);
1186        end
1187    else
1188        if isequal(get(hObject,'BackgroundColor'),[0 1 0])  | isequal(get(hObject,'BackgroundColor'),[1 1 0])
1189            set(hObject,'BackgroundColor','c','String','HV OFF');
1190            Valveword=bitset(statusData(lastrow,col.Valve2armAxis),8,0);  % switch HV off
1191            % switch gain off for MCP1
1192            word1=bitset(statusData(lastrow,col.ccGateDelay1),16,0);
1193            % switch gain off for MCP2
1194            word2=bitset(statusData(lastrow,col.ccGateDelay2),16,0);
1195            system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to switch HV
1196            system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1197            system(['/lift/bin/eCmd @armAxis w 0xa318 ',num2str(word1)]);
1198            system(['/lift/bin/eCmd @armAxis w 0xa31c ',num2str(word2)]);
1199        end
1200    end 
1201end
1202
1203
1204
1205
1206% --- Executes on button press in togglebutton5.
1207function tglLamp_Callback(hObject, eventdata, handles)
1208% hObject    handle to togglebutton5 (see GCBO)
1209% eventdata  reserved - to be defined in a future version of MATLAB
1210% handles    structure with handles and user data (see GUIDATA)
1211
1212% Hint: get(hObject,'Value') returns toggle state of togglebutton5
1213horusdata = getappdata(handles.parenthandle, 'horusdata');
1214statusData=horusdata.statusData;
1215data = getappdata(handles.output, 'Detdata');
1216lastrow=data.lastrow;
1217col=horusdata.col;
1218if statusData(lastrow,col.ValidSlaveDataFlag)
1219    if get(hObject,'Value')
1220        Valveword=bitset(statusData(lastrow,col.Valve2armAxis),11);
1221        set(hObject,'BackgroundColor','r','String','Lamp ON');
1222    else
1223        Valveword=bitset(statusData(lastrow,col.Va…

Large files files are truncated, but you can click here to view the full file