/matlab/FlyDetectionMM.m~

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

Large files are truncated click here to view the full file

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