PageRenderTime 56ms CodeModel.GetById 29ms app.highlight 15ms RepoModel.GetById 2ms 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
   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.Valve2armAxis),11,0);
1224        set(hObject,'BackgroundColor','c','String','Lamp OFF');
1225    end
1226    system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to switch
1227    system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1228    data.calstatus=1;
1229    setappdata(handles.output, 'Detdata', data);
1230end
1231
1232
1233% --- Executes on button press in chkTDet.
1234function chkTDet_Callback(hObject, eventdata, handles)
1235% hObject    handle to chkTDet (see GCBO)
1236% eventdata  reserved - to be defined in a future version of MATLAB
1237% handles    structure with handles and user data (see GUIDATA)
1238
1239% Hint: get(hObject,'Value') returns toggle state of chkTDet
1240
1241
1242% --- Executes on button press in chkVHV.
1243function chkVHV_Callback(hObject, eventdata, handles)
1244% hObject    handle to chkVHV (see GCBO)
1245% eventdata  reserved - to be defined in a future version of MATLAB
1246% handles    structure with handles and user data (see GUIDATA)
1247
1248% Hint: get(hObject,'Value') returns toggle state of chkVHV
1249
1250
1251
1252% --- Executes on button press in toggleOHInj.
1253function toggleOHInj_Callback(hObject, eventdata, handles)
1254% hObject    handle to toggleOHInj (see GCBO)
1255% eventdata  reserved - to be defined in a future version of MATLAB
1256% handles    structure with handles and user data (see GUIDATA)
1257
1258% Hint: get(hObject,'Value') returns toggle state of toggleOHInj
1259horusdata = getappdata(handles.parenthandle, 'horusdata');
1260statusData=horusdata.statusData;
1261col=horusdata.col;
1262data = getappdata(handles.output, 'Detdata');
1263lastrow=data.lastrow;
1264
1265if statusData(lastrow,col.ValidSlaveDataFlag)
1266    if get(hObject,'Value')
1267        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),1);
1268        set(hObject,'BackgroundColor','r');
1269    else
1270        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),1,0);
1271        set(hObject,'BackgroundColor','c');
1272    end
1273    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1274    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
1275    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
1276end
1277
1278
1279% --- Executes on button press in toggleHO2Inj.
1280function toggleHO2Inj_Callback(hObject, eventdata, handles)
1281% hObject    handle to toggleHO2Inj (see GCBO)
1282% eventdata  reserved - to be defined in a future version of MATLAB
1283% handles    structure with handles and user data (see GUIDATA)
1284
1285% Hint: get(hObject,'Value') returns toggle state of toggleHO2Inj
1286horusdata = getappdata(handles.parenthandle, 'horusdata');
1287statusData=horusdata.statusData;
1288col=horusdata.col;
1289data = getappdata(handles.output, 'Detdata');
1290lastrow=data.lastrow;
1291
1292if statusData(lastrow,col.ValidSlaveDataFlag)
1293    if get(hObject,'Value')
1294        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),2);
1295        set(hObject,'BackgroundColor','g');
1296    else
1297        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),2,0);
1298        set(hObject,'BackgroundColor','c');
1299    end
1300    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1301    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
1302    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
1303end
1304
1305
1306% --- Executes on button press in toggleN2.
1307function toggleN2_Callback(hObject, eventdata, handles)
1308% hObject    handle to toggleN2 (see GCBO)
1309% eventdata  reserved - to be defined in a future version of MATLAB
1310% handles    structure with handles and user data (see GUIDATA)
1311
1312% Hint: get(hObject,'Value') returns toggle state of toggleN2
1313horusdata = getappdata(handles.parenthandle, 'horusdata');
1314statusData=horusdata.statusData;
1315col=horusdata.col;
1316data = getappdata(handles.output, 'Detdata');
1317lastrow=data.lastrow;
1318
1319if statusData(lastrow,col.ValidSlaveDataFlag)
1320    if get(hObject,'Value')
1321        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),3);
1322        set(hObject,'BackgroundColor','r');
1323    else
1324        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),3,0);
1325        set(hObject,'BackgroundColor','c');
1326    end
1327    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1328    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
1329    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
1330end
1331
1332
1333% --- Executes on button press in toggleC3F6.
1334function toggleC3F6_Callback(hObject, eventdata, handles)
1335% hObject    handle to toggleC3F6 (see GCBO)
1336% eventdata  reserved - to be defined in a future version of MATLAB
1337% handles    structure with handles and user data (see GUIDATA)
1338
1339% Hint: get(hObject,'Value') returns toggle state of toggleC3F6
1340horusdata = getappdata(handles.parenthandle, 'horusdata');
1341statusData=horusdata.statusData;
1342col=horusdata.col;
1343data = getappdata(handles.output, 'Detdata');
1344lastrow=data.lastrow;
1345
1346if statusData(lastrow,col.ValidSlaveDataFlag)
1347    if get(hObject,'Value')
1348        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),4);
1349        set(hObject,'BackgroundColor','r');
1350    else
1351        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),4,0);
1352        set(hObject,'BackgroundColor','c');
1353    end
1354    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1355    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
1356    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
1357end
1358
1359
1360% --- Executes on button press in toggleNO1.
1361function toggleNO1_Callback(hObject, eventdata, handles)
1362% hObject    handle to toggleNO1 (see GCBO)
1363% eventdata  reserved - to be defined in a future version of MATLAB
1364% handles    structure with handles and user data (see GUIDATA)
1365
1366% Hint: get(hObject,'Value') returns toggle state of toggleNO1
1367horusdata = getappdata(handles.parenthandle, 'horusdata');
1368statusData=horusdata.statusData;
1369col=horusdata.col;
1370data = getappdata(handles.output, 'Detdata');
1371lastrow=data.lastrow;
1372
1373if statusData(lastrow,col.ValidSlaveDataFlag)
1374    if get(hObject,'Value')
1375        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),7);
1376        set(hObject,'BackgroundColor','g');
1377    else
1378        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),7,0);
1379        set(hObject,'BackgroundColor','c');
1380    end
1381    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1382    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
1383    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
1384end
1385
1386% --- Executes on button press in toggleNO2.
1387function toggleNO2_Callback(hObject, eventdata, handles)
1388% hObject    handle to toggleNO2 (see GCBO)
1389% eventdata  reserved - to be defined in a future version of MATLAB
1390% handles    structure with handles and user data (see GUIDATA)
1391
1392% Hint: get(hObject,'Value') returns toggle state of toggleNO2
1393horusdata = getappdata(handles.parenthandle, 'horusdata');
1394statusData=horusdata.statusData;
1395col=horusdata.col;
1396data = getappdata(handles.output, 'Detdata');
1397lastrow=data.lastrow;
1398
1399if statusData(lastrow,col.ValidSlaveDataFlag)
1400    if get(hObject,'Value')
1401        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),6);
1402        set(hObject,'BackgroundColor','g');
1403    else
1404        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),6,0);
1405        set(hObject,'BackgroundColor','c');
1406    end
1407    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1408    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
1409    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
1410end
1411
1412
1413% --- Executes on button press in toggleNOPurge.
1414function toggleNOPurge_Callback(hObject, eventdata, handles)
1415% hObject    handle to toggleNOPurge (see GCBO)
1416% eventdata  reserved - to be defined in a future version of MATLAB
1417% handles    structure with handles and user data (see GUIDATA)
1418
1419% Hint: get(hObject,'Value') returns toggle state of toggleNOPurge
1420horusdata = getappdata(handles.parenthandle, 'horusdata');
1421statusData=horusdata.statusData;
1422col=horusdata.col;
1423data = getappdata(handles.output, 'Detdata');
1424lastrow=data.lastrow;
1425
1426if statusData(lastrow,col.ValidSlaveDataFlag)
1427    if get(hObject,'Value')
1428        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),5);
1429        set(hObject,'BackgroundColor','g');
1430    else
1431        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),5,0);
1432        set(hObject,'BackgroundColor','c');
1433    end
1434    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1435    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
1436    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
1437end
1438
1439
1440
1441function editxlim1_Callback(hObject, eventdata, handles)
1442% hObject    handle to editxlimit1 (see GCBO)
1443% eventdata  reserved - to be defined in a future version of MATLAB
1444% handles    structure with handles and user data (see GUIDATA)
1445
1446% Hints: get(hObject,'String') returns contents of editxlimit1 as text
1447%        str2double(get(hObject,'String')) returns contents of editxlimit1 as a double
1448xlim1=uint16(str2double(get(hObject,'String')));
1449if (xlim1>600) set(hObject,'String','600');
1450else set(hObject,'String',num2str(xlim1));
1451end
1452
1453
1454
1455function editxlim2_Callback(hObject, eventdata, handles)
1456% hObject    handle to editxlim2 (see GCBO)
1457% eventdata  reserved - to be defined in a future version of MATLAB
1458% handles    structure with handles and user data (see GUIDATA)
1459
1460% Hints: get(hObject,'String') returns contents of editxlim2 as text
1461%        str2double(get(hObject,'String')) returns contents of editxlim2 as a double
1462xlim2=uint16(str2double(get(hObject,'String')));
1463if xlim2>600 set(hObject,'String','600');
1464else set(hObject,'String',num2str(xlim2));
1465end
1466
1467
1468% --- Executes on button press in chkWZ2out.
1469function chkWZ2out_Callback(hObject, eventdata, handles)
1470% hObject    handle to chkWZ2out (see GCBO)
1471% eventdata  reserved - to be defined in a future version of MATLAB
1472% handles    structure with handles and user data (see GUIDATA)
1473
1474% Hint: get(hObject,'Value') returns toggle state of chkWZ2out
1475
1476
1477% --- Executes on button press in chkWZ2in.
1478function chkWZ2in_Callback(hObject, eventdata, handles)
1479% hObject    handle to chkWZ2in (see GCBO)
1480% eventdata  reserved - to be defined in a future version of MATLAB
1481% handles    structure with handles and user data (see GUIDATA)
1482
1483% Hint: get(hObject,'Value') returns toggle state of chkWZ2in
1484
1485
1486
1487function editH2O_Callback(hObject, eventdata, handles)
1488% hObject    handle to editH2O (see GCBO)
1489% eventdata  reserved - to be defined in a future version of MATLAB
1490% handles    structure with handles and user data (see GUIDATA)
1491
1492% Hints: get(hObject,'String') returns contents of editH2O as text
1493%        str2double(get(hObject,'String')) returns contents of editH2O as a double
1494
1495
1496function editC_Callback(hObject, eventdata, handles)
1497% hObject    handle to editC (see GCBO)
1498% eventdata  reserved - to be defined in a future version of MATLAB
1499% handles    structure with handles and user data (see GUIDATA)
1500
1501% Hints: get(hObject,'String') returns contents of editC as text
1502%        str2double(get(hObject,'String')) returns contents of editC as a double
1503
1504
1505
1506
1507function editMFC_Callback(hObject, eventdata, handles)
1508% hObject    handle to editMFC (see GCBO)
1509% eventdata  reserved - to be defined in a future version of MATLAB
1510% handles    structure with handles and user data (see GUIDATA)
1511
1512% Hints: get(hObject,'String') returns contents of editMFC as text
1513%        str2double(get(hObject,'String')) returns contents of editMFC as a double
1514MaxFlow=20;
1515setMFC=str2double(get(hObject,'String'));
1516if setMFC<0 | isnan(setMFC) setMFC=0; end
1517if setMFC>MaxFlow setMFC=MaxFlow; end
1518set(hObject,'String',num2str(setMFC));
1519
1520Value=setMFC/MaxFlow*255;
1521%system(['/lift/bin/eCmd @armAxis w 0xa404 0xFF']); % initialise
1522system(['/lift/bin/eCmd @armAxis w 0xa440 ', num2str(uint16(Value))]);
1523
1524
1525
1526% --- Executes on button press in chkMFCNO.
1527function chkMFCNO_Callback(hObject, eventdata, handles)
1528% hObject    handle to chkMFCNO (see GCBO)
1529% eventdata  reserved - to be defined in a future version of MATLAB
1530% handles    structure with handles and user data (see GUIDATA)
1531
1532% Hint: get(hObject,'Value') returns toggle state of chkMFCNO
1533
1534
1535% --- Executes on button press in chkDiodeUV.
1536function chkDiodeUV_Callback(hObject, eventdata, handles)
1537% hObject    handle to chkDiodeUV (see GCBO)
1538% eventdata  reserved - to be defined in a future version of MATLAB
1539% handles    structure with handles and user data (see GUIDATA)
1540
1541% Hint: get(hObject,'Value') returns toggle state of chkDiodeUV
1542
1543
1544
1545
1546% --- Executes on button press in chkTDetFunnel.
1547function chkTDetFunnel_Callback(hObject, eventdata, handles)
1548% hObject    handle to chkTDetFunnel (see GCBO)
1549% eventdata  reserved - to be defined in a future version of MATLAB
1550% handles    structure with handles and user data (see GUIDATA)
1551
1552% Hint: get(hObject,'Value') returns toggle state of chkTDetFunnel
1553
1554
1555% --- Executes on button press in chkPabs.
1556function chkPabs_Callback(hObject, eventdata, handles)
1557% hObject    handle to chkPabs (see GCBO)
1558% eventdata  reserved - to be defined in a future version of MATLAB
1559% handles    structure with handles and user data (see GUIDATA)
1560
1561% Hint: get(hObject,'Value') returns toggle state of chkPabs
1562
1563
1564% --- Executes on button press in tglN2O.
1565function tglN2O_Callback(hObject, eventdata, handles)
1566% hObject    handle to tglN2O (see GCBO)
1567% eventdata  reserved - to be defined in a future version of MATLAB
1568% handles    structure with handles and user data (see GUIDATA)
1569
1570% Hint: get(hObject,'Value') returns toggle state of tglN2O
1571horusdata = getappdata(handles.parenthandle, 'horusdata');
1572statusData=horusdata.statusData;
1573col=horusdata.col;
1574data = getappdata(handles.output, 'Detdata');
1575lastrow=data.lastrow;
1576
1577if statusData(lastrow,col.ValidSlaveDataFlag)
1578    if get(hObject,'Value')
1579        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),14);
1580        set(hObject,'BackgroundColor','g');
1581    else
1582        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),14,0);
1583        set(hObject,'BackgroundColor','c');
1584    end
1585    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1586    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
1587    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
1588end
1589
1590% --- Executes on button press in tglVac.
1591function tglVac_Callback(hObject, eventdata, handles)
1592% hObject    handle to tglVac (see GCBO)
1593% eventdata  reserved - to be defined in a future version of MATLAB
1594% handles    structure with handles and user data (see GUIDATA)
1595
1596% Hint: get(hObject,'Value') returns toggle state of tglVac
1597horusdata = getappdata(handles.parenthandle, 'horusdata');
1598statusData=horusdata.statusData;
1599col=horusdata.col;
1600data = getappdata(handles.output, 'Detdata');
1601lastrow=data.lastrow;
1602
1603if statusData(lastrow,col.ValidSlaveDataFlag)
1604    if get(hObject,'Value')
1605        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),13);
1606        set(hObject,'BackgroundColor','g');
1607    else
1608        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),13,0);
1609        set(hObject,'BackgroundColor','c');
1610    end
1611    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1612    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
1613    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
1614end
1615
1616
1617% --- Executes on button press in tglKuv.
1618%function tglKuv_Callback(hObject, eventdata, handles)
1619% hObject    handle to tglKuv (see GCBO)
1620% eventdata  reserved - to be defined in a future version of MATLAB
1621% handles    structure with handles and user data (see GUIDATA)
1622
1623% Hint: get(hObject,'Value') returns toggle state of tglKuv
1624%horusdata = getappdata(handles.parenthandle, 'horusdata');
1625%statusData=horusdata.statusData;
1626%col=horusdata.col;
1627%data = getappdata(handles.output, 'Detdata');
1628%lastrow=data.lastrow;
1629
1630%if statusData(lastrow,col.ValidSlaveDataFlag)
1631%    if get(hObject,'Value')
1632%        Valveword=bitset(statusData(lastrow,col.Valve2armAxis),12);
1633%        set(hObject,'BackgroundColor','g');
1634%    else
1635%        Valveword=bitset(statusData(lastrow,col.Valve2armAxis),12,0);
1636%        set(hObject,'BackgroundColor','c');
1637%    end
1638%    system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1639%    system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1640%    system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to other valves working
1641%end
1642
1643
1644% --- Executes on button press in tglKuvN2.
1645%function tglKuvN2_Callback(hObject, eventdata, handles)
1646% hObject    handle to tglKuv (see GCBO)
1647% eventdata  reserved - to be defined in a future version of MATLAB
1648% handles    structure with handles and user data (see GUIDATA)
1649
1650% Hint: get(hObject,'Value') returns toggle state of tglKuv
1651%if statusData(lastrow,col.ValidSlaveDataFlag)
1652%    if get(hObject,'Value')
1653%        Valveword=bitset(statusData(lastrow,col.Valve2armAxis),13);
1654%        set(hObject,'BackgroundColor','g');
1655%    else
1656%        Valveword=bitset(statusData(lastrow,col.Valve2armAxis),13,0);
1657%        set(hObject,'BackgroundColor','c');
1658%    end
1659%    system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1660%    system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1661%    system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18 needed to keep other valves working%
1662%end
1663
1664
1665% --- Executes on button press in chkMFCProp.
1666function chkMFCProp_Callback(hObject, eventdata, handles)
1667% hObject    handle to chkMFCProp (see GCBO)
1668% eventdata  reserved - to be defined in a future version of MATLAB
1669% handles    structure with handles and user data (see GUIDATA)
1670
1671% Hint: get(hObject,'Value') returns toggle state of chkMFCProp
1672
1673
1674% --- Executes on button press in chkMFCShower.
1675function chkMFCShower_Callback(hObject, eventdata, handles)
1676% hObject    handle to chkMFCShower (see GCBO)
1677% eventdata  reserved - to be defined in a future version of MATLAB
1678% handles    structure with handles and user data (see GUIDATA)
1679
1680% Hint: get(hObject,'Value') returns toggle state of chkMFCShower
1681
1682
1683
1684
1685% --- Executes on button press in tglPitot.
1686function tglPitot_Callback(hObject, eventdata, handles)
1687% hObject    handle to tglPitot (see GCBO)
1688% eventdata  reserved - to be defined in a future version of MATLAB
1689% handles    structure with handles and user data (see GUIDATA)
1690% Hint: get(hObject,'Value') returns toggle state of tglPitot
1691horusdata = getappdata(handles.parenthandle, 'horusdata');
1692statusData=horusdata.statusData;
1693data = getappdata(handles.output, 'Detdata');
1694lastrow=data.lastrow;
1695col=horusdata.col;
1696if statusData(lastrow,col.ValidSlaveDataFlag)
1697    if get(hObject,'Value')
1698        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),12);
1699        set(hObject,'BackgroundColor','y','String','Pitot 0 ON');
1700    else
1701        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),12,0);
1702        set(hObject,'BackgroundColor','c','String','Pitot 0 OFF');
1703    end
1704    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch
1705    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
1706    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to hold solenoids
1707end
1708
1709% --- Executes on button press in tglHeatLamp.
1710function tglHeatLamp_Callback(hObject, eventdata, handles)
1711% hObject    handle to tglHeatLamp (see GCBO)
1712% eventdata  reserved - to be defined in a future version of MATLAB
1713% handles    structure with handles and user data (see GUIDATA)
1714% Hint: get(hObject,'Value') returns toggle state of tglHeatLamp
1715horusdata = getappdata(handles.parenthandle, 'horusdata');
1716statusData=horusdata.statusData;
1717data = getappdata(handles.output, 'Detdata');
1718lastrow=data.lastrow;
1719col=horusdata.col;
1720if statusData(lastrow,col.ValidSlaveDataFlag)
1721    if get(hObject,'Value')
1722        Valveword=bitset(statusData(lastrow,col.Valve2armAxis),3);
1723    else
1724        Valveword=bitset(statusData(lastrow,col.Valve2armAxis),3,0);
1725    end
1726    system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to switch
1727    system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1728end
1729
1730% --- Executes on button press in chkTLamp.
1731function chkTLamp_Callback(hObject, eventdata, handles)
1732% hObject    handle to chkTLamp (see GCBO)
1733% eventdata  reserved - to be defined in a future version of MATLAB
1734% handles    structure with handles and user data (see GUIDATA)
1735
1736% Hint: get(hObject,'Value') returns toggle state of chkTLamp
1737
1738
1739% --- Executes on button press in chkMFCC3F6.
1740function chkMFCC3F6_Callback(hObject, eventdata, handles)
1741% hObject    handle to chkMFCC3F6 (see GCBO)
1742% eventdata  reserved - to be defined in a future version of MATLAB
1743% handles    structure with handles and user data (see GUIDATA)
1744
1745% Hint: get(hObject,'Value') returns toggle state of chkMFCC3F6
1746
1747
1748% --- Executes on button press in tglHeatPrall.
1749function tglHeatPrall_Callback(hObject, eventdata, handles)
1750% hObject    handle to tglHeatPrall (see GCBO)
1751% eventdata  reserved - to be defined in a future version of MATLAB
1752% handles    structure with handles and user data (see GUIDATA)
1753
1754% Hint: get(hObject,'Value') returns toggle state of tglHeatPrall
1755horusdata = getappdata(handles.parenthandle, 'horusdata');
1756statusData=horusdata.statusData;
1757data = getappdata(handles.output, 'Detdata');
1758lastrow=data.lastrow;
1759col=horusdata.col;
1760if statusData(lastrow,col.ValidSlaveDataFlag)
1761    if get(hObject,'Value')
1762        Valveword=bitset(statusData(lastrow,col.Valve2armAxis),4);
1763    else
1764        Valveword=bitset(statusData(lastrow,col.Valve2armAxis),4,0);
1765    end
1766    system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to switch
1767    system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1768end
1769
1770
1771% --- Executes on button press in tglHeatPhoto2.
1772function tglHeatPhoto2_Callback(hObject, eventdata, handles)
1773% hObject    handle to tglHeatPhoto2 (see GCBO)
1774% eventdata  reserved - to be defined in a future version of MATLAB
1775% handles    structure with handles and user data (see GUIDATA)
1776% Hint: get(hObject,'Value') returns toggle state of tglHeatPhoto2
1777horusdata = getappdata(handles.parenthandle, 'horusdata');
1778statusData=horusdata.statusData;
1779data = getappdata(handles.output, 'Detdata');
1780lastrow=data.lastrow;
1781col=horusdata.col;
1782if statusData(lastrow,col.ValidSlaveDataFlag)
1783    if get(hObject,'Value')
1784        Valveword=bitset(statusData(lastrow,col.Valve2armAxis),5);
1785    else
1786        Valveword=bitset(statusData(lastrow,col.Valve2armAxis),5,0);
1787    end
1788    system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to switch
1789    system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1790end
1791
1792
1793% --- Executes on button press in tglVent.
1794function tglVent_Callback(hObject, eventdata, handles)
1795% hObject    handle to tglVent (see GCBO)
1796% eventdata  reserved - to be defined in a future version of MATLAB
1797% handles    structure with handles and user data (see GUIDATA)
1798horusdata = getappdata(handles.parenthandle, 'horusdata');
1799statusData=horusdata.statusData;
1800col=horusdata.col;
1801data = getappdata(handles.output, 'Detdata');
1802lastrow=data.lastrow;
1803
1804if statusData(lastrow,col.ValidSlaveDataFlag)
1805    if get(hObject,'Value')
1806        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),4);
1807        set(hObject,'BackgroundColor','r');
1808    else
1809        Valveword=bitset(statusData(lastrow,col.Valve1armAxis),4,0);
1810        set(hObject,'BackgroundColor','c');
1811    end
1812    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1813    system(['/lift/bin/eCmd @armAxis w 0xa408 ', num2str(Valveword)]);
1814    system(['/lift/bin/eCmd @armAxis w 0xa460 ', num2str(uint16(15*140))]); % 15V needed to keep Pitot Zero open
1815end
1816
1817
1818% --- Executes on button press in togButterfly.
1819function togButterfly_Callback(hObject, eventdata, handles)
1820% hObject    handle to togButterfly (see GCBO)
1821% eventdata  reserved - to be defined in a future version of MATLAB
1822% handles    structure with handles and user data (see GUIDATA)
1823
1824% Hint: get(hObject,'Value') returns toggle state of togButterfly
1825horusdata = getappdata(handles.parenthandle, 'horusdata');
1826statusData=horusdata.statusData;
1827data = getappdata(handles.output, 'Detdata');
1828lastrow=data.lastrow;
1829col=horusdata.col;
1830% Butterfly with stepper motor
1831%if statusData(lastrow,col.ButterflyPositionValid)==0
1832%    system('/lift/bin/eCmd @armAxis s butterflyposition 2500'); % move to find index position
1833%    set(hObject,'BackgroundColor','r','String','MOVING');
1834%    pause(2);
1835%    system(['/lift/bin/eCmd @armAxis s butterflyposition ',num2str(625+42)]); % open Butterfly 
1836%    set(hObject,'Value',1);
1837%else
1838%    if get(hObject,'Value')
1839%        system('/lift/bin/eCmd @armAxis s butterflyposition 2500'); % move to find index position
1840%        set(hObject,'BackgroundColor','r','String','MOVING');
1841%        pause(2);
1842%        system(['/lift/bin/eCmd @armAxis s butterflyposition ',num2str(625+42)]); % open Butterfly 
1843%    else
1844%        system(['/lift/bin/eCmd @armAxis s butterflyposition ',num2str(42)]); % close Butterfly 
1845%        set(hObject,'BackgroundColor','r','String','MOVING');
1846%    end
1847%end
1848% end Butterfly with stepper motor
1849
1850% Butterfly with relay
1851if get(hObject,'Value')
1852    Valveword=bitset(statusData(lastrow,col.Valve2armAxis),2,0); % open Butterfly
1853    set(hObject,'BackgroundColor','r','String','MOVING');
1854else
1855    Valveword=bitset(statusData(lastrow,col.Valve2armAxis),2,1); % close Butterfly
1856    set(hObject,'BackgroundColor','r','String','MOVING');
1857end
1858    system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1859% end Butterfly with relay
1860
1861
1862
1863% --- Executes on button press in togPump.
1864function togPump_Callback(hObject, eventdata, handles)
1865% hObject    handle to togPump (see GCBO)
1866% eventdata  reserved - to be defined in a future version of MATLAB
1867% handles    structure with handles and user data (see GUIDATA)
1868
1869% Hint: get(hObject,'Value') returns toggle state of togPump
1870
1871horusdata = getappdata(handles.parenthandle, 'horusdata');
1872statusData=horusdata.statusData;
1873data = getappdata(handles.output, 'Detdata');
1874lastrow=data.lastrow;
1875col=horusdata.col;
1876horustxtBlower=horusdata.txtBlower;
1877if ~isequal(get(horustxtBlower,'BackgroundColor'),[0 1 1])
1878    set(hObject,'BackgroundColor','y');
1879    tcpBlower=horusdata.tcpBlower;
1880    % check if Blower and/or pump are on or off
1881    fprintf(tcpBlower,'status'); 
1882    pause(0.5);
1883    BlowerStatus=tcpBlower.UserData;
1884    tcpBlower.UserData=[];
1885    if BlowerStatus(strfind(BlowerStatus,'Pump')+7)=='f'
1886        PumpSwitch=0;
1887    elseif BlowerStatus(strfind(BlowerStatus,'Pump')+7)=='n'
1888        PumpSwitch=1;
1889    else PumpSwitch=-1;
1890    end
1891    if BlowerStatus(strfind(BlowerStatus,'Inverter')+11)=='f'
1892        InverterSwitch=0;
1893    elseif BlowerStatus(strfind(BlowerStatus,'Inverter')+11)=='n'
1894        InverterSwitch=1;
1895    else InverterSwitch=-1;
1896    end
1897    if BlowerStatus(strfind(BlowerStatus,'Ramp')+7)=='f'
1898        RampSwitch=0;
1899    elseif BlowerStatus(strfind(BlowerStatus,'Ramp')+7)=='n'
1900        RampSwitch=1;
1901    else RampSwitch=-1;
1902    end
1903end
1904
1905if get(hObject,'Value') % switch on
1906    if ~isequal(get(horustxtBlower,'BackgroundColor'),[0 1 1]) % Blower connected via tcp (ground configuration)
1907            fprintf(tcpBlower,'pump on'); % switch pump on
1908            pause(0.5);
1909            tcpBlower.UserData=[];
1910    else % Blower connected directly to armaxis (air configuration)
1911        if statusData(lastrow,col.ValidSlaveDataFlag) % only if armaxis is active
1912            if isequal(get(hObject,'BackgroundColor'),[0 1 1])
1913                Valveword=bitset(statusData(lastrow,col.Valve2armAxis),10);  % switch Leybold pump on
1914                Valveword=bitset(Valveword,7);  % switch Scroll pump on
1915                system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to switch
1916                system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1917                set(hObject,'BackgroundColor','g','String','Pump ON');
1918            end
1919        end
1920    end
1921else % switch off
1922    if ~isequal(get(horustxtBlower,'BackgroundColor'),[0 1 1]) % Blower connected via tcp (ground configuration)
1923            if InverterSwitch==0 % make sure blower is ramped down
1924                fprintf(tcpBlower,'pump off'); % switch pump off
1925                pause(0.5);
1926                tcpBlower.UserData=[];
1927% Butterfly with stepper motor                
1928                system(['/lift/bin/eCmd @armAxis s butterflyposition ',num2str(42)]); % close Butterfly 
1929% end Butterfly with stepper motor
1930% Butterfly with relay
1931                Valveword=bitset(statusData(lastrow,col.Valve2armAxis),2,1); % close Butterfly
1932                system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1933% end Butterfly with relay
1934
1935                set(handles.togButterfly,'BackgroundColor','r','String','MOVING');
1936            end
1937    else % Blower connected directly to armaxis (air configuration)
1938        if statusData(lastrow,col.ValidSlaveDataFlag) % only if armaxis is active
1939            if isequal(get(hObject,'BackgroundColor'),[0 1 0]) | isequal(get(hObject,'BackgroundColor'),[1 0 0])
1940   %             set(handles.tglVent,'BackgroundColor','r');
1941                if bitget(statusData(lastrow,col.Valve2armAxis),1)==0 % make sure blower is ramped down
1942                    Valveword=bitset(statusData(lastrow,col.Valve2armAxis),9,0); % switch off blower
1943                    Valveword=bitset(Valveword,10,0);  % switch off Leybold Pump
1944                    Valveword=bitset(Valveword,7,0);  % switch off Scroll Pump
1945    %                Valveword=bitset(Valveword,13);  % ventilate Pump
1946% Butterfly with stepper motor                
1947                    system(['/lift/bin/eCmd @armAxis s butterflyposition ',num2str(42)]); % close Butterfly 
1948% end Butterfly with stepper motor
1949% Butterfly with relay
1950                    Valveword=bitset(statusData(lastrow,col.Valve2armAxis),2,1); % close Butterfly
1951                    system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1952% end Butterfly with relay
1953                    set(handles.togButterfly,'BackgroundColor','r','String','MOVING');
1954                    system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
1955                    system(['/lift/bin/eCmd @armAxis w 0xa40a ', num2str(Valveword)]);
1956                    system(['/lift/bin/eCmd @armAxis w 0xa462 ', num2str(uint16(18*140))]); % 18V needed to other valves working
1957                    set(hObject,'BackgroundColor','c','String','Pump OFF');
1958    %                set(handles.tglVent,'BackgroundColor','r');
1959                end
1960            end
1961        end
1962    end
1963end
1964
1965%for ground configuration, recheck pump status 
1966if ~isequal(get(horustxtBlower,'BackgroundColor'),[0 1 1])
1967    fprintf(tcpBlower,'status'); 
1968    pause(0.5);
1969    BlowerStatus=tcpBlower.UserData;
1970    tcpBlower.UserData=[];
1971    if BlowerStatus(strfind(BlowerStatus,'Pump')+7)=='f'
1972        PumpSwitch=0;
1973    elseif BlowerStatus(strfind(BlowerStatus,'Pump')+7)=='n'
1974        PumpSwitch=1;
1975    else PumpSwitch=-1;
1976    end
1977    if BlowerStatus(strfind(BlowerStatus,'Inverter')+11)=='f'
1978        InverterSwitch=0;
1979    elseif BlowerStatus(strfind(BlowerStatus,'Inverter')+11)=='n'
1980        InverterSwitch=1;
1981    else InverterSwitch=-1;
1982    end
1983    if BlowerStatus(strfind(BlowerStatus,'Ramp')+7)=='f'
1984        RampSwitch=0;
1985    elseif BlowerStatus(strfind(BlowerStatus,'Ramp')+7)=='n'
1986        RampSwitch=1;
1987    else RampSwitch=-1;
1988    end
1989   
1990    if PumpSwitch==0
1991        set(hObject,'BackgroundColor','c','String','Pump OFF');
1992        set(horustxtBlower,'String','Pump OFF'); 
1993    elseif (RampSwitch==0 | InverterSwitch==0)
1994        set(hObject,'BackgroundColor','g','String','Pump ON');
1995        set(horustxtBlower,'String','Pump ON'); 
1996    else
1997        set(horustxtBlower,'String','Blower ON','BackgroundColor','g');
1998    end
1999    if (PumpSwitch==-1 | RampSwitch==-1 | InverterSwitch==-1)
2000        set(hObject,'BackgroundColor','r','String','Pump ERR');
2001        set(horustxtBlower,'String','Blower ERROR','BackgroundColor','r');
2002    end
2003end
2004
2005
2006
2007function editMFCShower_Callback(hObject, eventdata, handles)
2008% hObject    handle to editMFCShower (see GCBO)
2009% eventdata  reserved - to be defined in a future version of MATLAB
2010% handles    structure with handles and user data (see GUIDATA)
2011
2012% Hints: get(hObject,'String') returns contents of editMFCShower as text
2013%        str2double(get(hObject,'String')) returns contents of editMFCShower as a double
2014MaxFlow=5000;
2015setMFC=str2double(get(hObject,'String'));
2016if setMFC<0 | isnan(setMFC) setMFC=0; end
2017if setMFC>MaxFlow setMFC=MaxFlow; end
2018set(hObject,'String',num2str(setMFC));
2019
2020Value=setMFC/MaxFlow*255;
2021%system(['/lift/bin/eCmd @armAxis w 0xa404 0xFF']); % initialise
2022system(['/lift/bin/eCmd @armAxis w 0xa446 ', num2str(uint16(Value))]);
2023
2024
2025% --- Executes during object creation, after setting all properties.
2026function editMFCShower_CreateFcn(hObject, eventdata, handles)
2027% hObject    handle to editMFCShower (see GCBO)
2028% eventdata  reserved - to be defined in a future version of MATLAB
2029% handles    empty - handles not created until after all CreateFcns called
2030
2031% Hint: edit controls usually have a white background on Windows.
2032%       See ISPC and COMPUTER.
2033if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2034    set(hObject,'BackgroundColor','white');
2035end
2036
2037
2038
2039function editMFCProp_Callback(hObject, eventdata, handles)
2040% hObject    handle to editMFCProp (see GCBO)
2041% eventdata  reserved - to be defined in a future version of MATLAB
2042% handles    structure with handles and user data (see GUIDATA)
2043
2044% Hints: get(hObject,'String') returns contents of editMFCProp as text
2045%        str2double(get(hObject,'String')) returns contents of editMFCProp as a double
2046MaxFlow=200;
2047setMFC=str2double(get(hObject,'String'));
2048if setMFC<0 | isnan(setMFC) setMFC=0; end
2049if setMFC>MaxFlow setMFC=MaxFlow; end
2050set(hObject,'String',num2str(setMFC));
2051
2052Value=setMFC/MaxFlow*255;
2053%system(['/lift/bin/eCmd @armAxis w 0xa404 0xFF']); % initialise
2054system(['/lift/bin/eCmd @armAxis w 0xa442 ', num2str(uint16(Value))]);
2055
2056
2057% --- Executes during object creation, after setting all properties.
2058function editMFCProp_CreateFcn(hObject, eventdata, handles)
2059% hObject    handle to editMFCProp (see GCBO)
2060% eventdata  reserved - to be defined in a future version of MATLAB
2061% handles    empty - handles not created until after all CreateFcns called
2062
2063% Hint: edit controls usually have a white background on Windows.
2064%       See ISPC and COMPUTER.
2065if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2066    set(hObject,'BackgroundColor','white');
2067end
2068
2069
2070
2071function editMFCC3F6_Callback(hObject, eventdata, handles)
2072% hObject    handle to editMFCC3F6 (see GCBO)
2073% eventdata  reserved - to be defined in a future version of MATLAB
2074% handles    structure with handles and user data (see GUIDATA)
2075
2076% Hints: get(hObject,'String') returns contents of editMFCC3F6 as text
2077%        str2double(get(hObject,'String')) returns contents of editMFCC3F6 as a double
2078MaxFlow=500;
2079setMFC=str2double(get(hObject,'String'));
2080if setMFC<0 | isnan(setMFC) setMFC=0; end
2081if setMFC>MaxFlow setMFC=MaxFlow; end
2082set(hObject,'String',num2str(setMFC));
2083
2084Value=setMFC/MaxFlow*255;
2085%system(['/lift/bin/eCmd @armAxis w 0xa404 0xFF']); % initialise
2086system(['/lift/bin/eCmd @armAxis w 0xa444 ', num2str(uint16(Value))]);
2087
2088
2089% --- Executes during object creation, after setting all properties.
2090function editMFCC3F6_CreateFcn(hObject, eventdata, handles)
2091% hObject    handle to editMFCC3F6 (see GCBO)
2092% eventdata  reserved - to be defined in a future version of MATLAB
2093% handles    empty - handles not created until after all CreateFcns called
2094
2095% Hint: edit controls usually have a white background on Windows.
2096%       See ISPC and COMPUTER.
2097if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2098    set(hObject,'BackgroundColor','white');
2099end