/matlab/old/Dyelaser.m

http://github.com/Yniold/liftsrc · Objective C · 836 lines · 671 code · 165 blank · 0 comment · 71 complexity · c56c437e504852c51d41884d5be05a9c MD5 · raw file

  1. function varargout = Dyelaser(varargin)
  2. % DYELASER M-file for Dyelaser.fig
  3. % DYELASER, by itself, creates a new DYELASER or raises the existing
  4. % singleton*.
  5. %
  6. % H = DYELASER returns the handle to a new DYELASER or the handle to
  7. % the existing singleton*.
  8. %
  9. % DYELASER('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in DYELASER.M with the given input arguments.
  11. %
  12. % DYELASER('Property','Value',...) creates a new DYELASER or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before Dyelaser_OpeningFunction gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to Dyelaser_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 Dyelaser
  24. % Last Modified by GUIDE v2.5 27-May-2005 13:19:11
  25. % Begin initialization code - DO NOT EDIT
  26. gui_Singleton = 1;
  27. gui_State = struct('gui_Name', mfilename, ...
  28. 'gui_Singleton', gui_Singleton, ...
  29. 'gui_OpeningFcn', @Dyelaser_OpeningFcn, ...
  30. 'gui_OutputFcn', @Dyelaser_OutputFcn, ...
  31. 'gui_LayoutFcn', [] , ...
  32. 'gui_Callback', []);
  33. if nargin && ischar(varargin{1})
  34. gui_State.gui_Callback = str2func(varargin{1});
  35. end
  36. if nargout
  37. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  38. else
  39. gui_mainfcn(gui_State, varargin{:});
  40. end
  41. % End initialization code - DO NOT EDIT
  42. % --- Executes just before Dyelaser is made visible.
  43. function Dyelaser_OpeningFcn(hObject, eventdata, handles, varargin)
  44. % This function has no output args, see OutputFcn.
  45. % hObject handle to figure
  46. % eventdata reserved - to be defined in a future version of MATLAB
  47. % handles structure with handles and user data (see GUIDATA)
  48. % varargin command line arguments to Dyelaser (see VARARGIN)
  49. % Choose default command line output for Dyelaser
  50. handles.output = hObject;
  51. % get horus handle
  52. if length(varargin)==2 & varargin{1}=='handle'
  53. handles.parenthandle=str2double(varargin{2});
  54. end
  55. % setup Timer function
  56. handles.ActTimer = timer('ExecutionMode','fixedDelay',...
  57. 'Period',0.7,...
  58. 'BusyMode','drop',...
  59. 'TimerFcn', {@DyelaserRefresh,handles});
  60. start(handles.ActTimer);
  61. data.ActTimer=handles.ActTimer;
  62. % open communication with picomotors
  63. handles.serport=serial('/dev/ttyS0','BaudRate',19200,'Terminator','CR');
  64. set(handles.serport,'BytesAvailableFcn',{'serialdatacallback'});
  65. try fopen(handles.serport);
  66. catch
  67. delete(handles.serport);
  68. rmfield(handles,'serport');
  69. end;
  70. % Update handles structure
  71. guidata(hObject, handles);
  72. % UIWAIT makes Dyelaser wait for user response (see UIRESUME)
  73. % uiwait(handles.figure1);
  74. setappdata(handles.output, 'Dyelaserdata', data);
  75. function DyelaserRefresh(arg1,arg2,handles)
  76. data = getappdata(handles.output, 'Dyelaserdata');
  77. horusdata = getappdata(handles.parenthandle, 'horusdata');
  78. statusData=horusdata.statusData;
  79. AvgData=horusdata.AvgData;
  80. col=horusdata.col;
  81. fcts2val=horusdata.fcts2val;
  82. statustime=double(statusData(:,1))+ ...
  83. double(statusData(:,2))./1.0+ ...
  84. double(statusData(:,3))./24.0+...
  85. double(statusData(:,4))./1440.0+...
  86. double(statusData(:,5))./86400.0;
  87. [SortZeit,indexZeit]=sort(statustime);
  88. maxLen=size(statustime,1);
  89. lastrow=indexZeit(maxLen);
  90. PlotWidth=maxLen;
  91. stopPlot=maxLen;
  92. startPlot=1;
  93. iZeit=indexZeit(startPlot:stopPlot);
  94. minTime=statustime(iZeit(1));
  95. maxTime=statustime(iZeit(size(iZeit,1)));
  96. % display ADC values
  97. x=double(statusData(:,col.DiodeUV)); eval(['DiodeUV=',fcts2val.DiodeUV,';']);
  98. set(handles.txtDiodeGr,'String',statusData(lastrow,col.DiodeGr));
  99. set(handles.txtDiodeUV,'String',statusData(lastrow,col.DiodeUV));
  100. set(handles.txtDiodeEt,'String',statusData(lastrow,col.DiodeEtalon));
  101. set(handles.txtPDyelaser,'String',statusData(lastrow,col.PDyelaser));
  102. set(handles.txtPVent,'String',statusData(lastrow,col.PVent));
  103. set(handles.txtIFilament,'String',statusData(lastrow,col.IFilament));
  104. set(handles.txtPRef,'String',statusData(lastrow,col.PRef));
  105. if statusData(lastrow,col.PRef)>10500
  106. set(handles.txtPRef,'BackgroundColor','r');
  107. else
  108. set(handles.txtPRef,'BackgroundColor',[0.7,0.7,0.7]);
  109. end
  110. Etalonhelp=int32(statusData(:,col.etaSetPosLow));
  111. EtalonSetPos=(Etalonhelp)+int32(statusData(:,col.etaSetPosHigh));
  112. EtalonSetPos(Etalonhelp>32767)=EtalonSetPos(Etalonhelp>32767)-65535;
  113. Etalonhelp=int32(statusData(:,col.etaCurPosLow));
  114. EtalonCurPos=(Etalonhelp)+int32(statusData(:,col.etaCurPosHigh));
  115. EtalonCurPos(Etalonhelp>32767)=EtalonCurPos(Etalonhelp>32767)-65535;
  116. Etalonhelp=int32(statusData(:,col.etaEncoderPosLow));
  117. EtalonEncPos=(Etalonhelp)+int32(statusData(:,col.etaEncoderPosHigh));
  118. EtalonEncPos(Etalonhelp>32767)=EtalonEncPos(Etalonhelp>32767)-65535;
  119. EtalonSpeed=statusData(:,col.etaSetSpd);
  120. EtalonStatus=statusData(:,col.etaStatus);
  121. set(handles.txtEtCurPos,'String',EtalonCurPos(lastrow));
  122. set(handles.txtEtSetPos,'String',EtalonSetPos(lastrow));
  123. set(handles.txtEtEncPos,'String',EtalonEncPos(lastrow));
  124. if bitget(EtalonStatus(lastrow),9)
  125. set(handles.txtLimitSwitch,'String','left','BackgroundColor','r');
  126. elseif bitget(EtalonStatus(lastrow),10)
  127. set(handles.txtLimitSwitch,'String','right','BackgroundColor','r');
  128. else
  129. set(handles.txtLimitSwitch,'String','none','BackgroundColor','c');
  130. end
  131. % plot parameters in graph 1
  132. hold(handles.axes1,'off');
  133. if get(handles.checkDiodeGr,'Value')
  134. plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.DiodeGr),'r');
  135. hold(handles.axes1,'on');
  136. end
  137. if get(handles.checkDiodeUV,'Value')
  138. plot(handles.axes1,statustime(iZeit),DiodeUV(iZeit));
  139. hold(handles.axes1,'on');
  140. end
  141. if get(handles.checkDiodeEt,'Value')
  142. plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.DiodeEtalon),'r');
  143. hold(handles.axes1,'on');
  144. end
  145. if get(handles.checkPDyelaser,'Value')
  146. plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.PDyelaser),'r');
  147. hold(handles.axes1,'on');
  148. end
  149. if get(handles.checkPVent,'Value')
  150. plot(handles.axes1,statustime(iZeit),statusData(iZeit,col.PVent),'r');
  151. hold(handles.axes1,'on');
  152. end
  153. if get(handles.chkEtCurPos,'Value')
  154. plot(handles.axes1,statustime(iZeit),EtalonCurPos(iZeit));
  155. hold(handles.axes1,'on');
  156. end
  157. if get(handles.chkEtSetPos,'Value')
  158. plot(handles.axes1,statustime(iZeit),EtalonSetPos(iZeit));
  159. hold(handles.axes1,'on');
  160. end
  161. if get(handles.chkEtEncPos,'Value')
  162. plot(handles.axes1,statustime(iZeit),EtalonEncPos(iZeit));
  163. hold(handles.axes1,'on');
  164. end
  165. xlim(handles.axes1,[minTime maxTime]);
  166. grid(handles.axes1);
  167. % plot ref. signal in graph 2
  168. [SortEtpos,indexEtpos]=sort(EtalonCurPos);
  169. iEtpos=indexEtpos(startPlot:stopPlot);
  170. minEtpos=EtalonCurPos(iEtpos(1));
  171. maxEtpos=EtalonCurPos(iEtpos(size(iEtpos,1)));
  172. maxEtpos=max(maxEtpos,minEtpos+1);
  173. if get(handles.radioTime,'Value');
  174. hold(handles.axes2,'off');
  175. plot(handles.axes2,statustime(iZeit),statusData(iZeit,col.ccCounts0));
  176. hold(handles.axes2,'on');
  177. xlim(handles.axes2,[minTime maxTime]);
  178. else
  179. hold(handles.axes2,'off');
  180. plot(handles.axes2,EtalonCurPos(iEtpos),statusData(iEtpos,col.ccCounts0));
  181. hold(handles.axes2,'on');
  182. xlim(handles.axes2,[minEtpos maxEtpos]);
  183. end
  184. grid(handles.axes2);
  185. % check filament status (e.g. if it was swiched off by horus)
  186. if bitget(statusData(lastrow,col.Valve),14)==0;
  187. set(handles.toggleFilament,'Value',0,'string','Filament is OFF');
  188. set(handles.toggleFilament,'BackgroundColor','c');
  189. else
  190. set(handles.toggleFilament,'Value',1,'string','Filament is ON');
  191. set(handles.toggleFilament,'BackgroundColor','g');
  192. end
  193. % check shutter status
  194. if bitget(statusData(lastrow,col.Valve),13)==0;
  195. set(handles.toggleShutter,'Value',0,'string','Shutter is OPEN');
  196. set(handles.toggleShutter,'BackgroundColor','g');
  197. else
  198. set(handles.toggleShutter,'Value',1,'string','Shutter is CLOSED');
  199. set(handles.toggleShutter,'BackgroundColor','c');
  200. end
  201. data.lastrow=lastrow;
  202. setappdata(handles.output, 'Dyelaserdata', data);
  203. % --- Outputs from this function are returned to the command line.
  204. function varargout = Dyelaser_OutputFcn(hObject, eventdata, handles)
  205. % varargout cell array for returning output args (see VARARGOUT);
  206. % hObject handle to figure
  207. % eventdata reserved - to be defined in a future version of MATLAB
  208. % handles structure with handles and user data (see GUIDATA)
  209. % Get default command line output from handles structure
  210. varargout{1} = handles.output;
  211. % --- Executes on button press in checkDiodeGr.
  212. function checkDiodeGr_Callback(hObject, eventdata, handles)
  213. % hObject handle to checkDiodeGr (see GCBO)
  214. % eventdata reserved - to be defined in a future version of MATLAB
  215. % handles structure with handles and user data (see GUIDATA)
  216. % Hint: get(hObject,'Value') returns toggle state of checkDiodeGr
  217. % --- Executes on button press in checkDiodeUV.
  218. function checkDiodeUV_Callback(hObject, eventdata, handles)
  219. % hObject handle to checkDiodeUV (see GCBO)
  220. % eventdata reserved - to be defined in a future version of MATLAB
  221. % handles structure with handles and user data (see GUIDATA)
  222. % Hint: get(hObject,'Value') returns toggle state of checkDiodeUV
  223. % --- Executes on button press in checkDiodeEt.
  224. function checkDiodeEt_Callback(hObject, eventdata, handles)
  225. % hObject handle to checkDiodeEt (see GCBO)
  226. % eventdata reserved - to be defined in a future version of MATLAB
  227. % handles structure with handles and user data (see GUIDATA)
  228. % Hint: get(hObject,'Value') returns toggle state of checkDiodeEt
  229. % --- Executes on button press in checkPDyelaser.
  230. function checkPDyelaser_Callback(hObject, eventdata, handles)
  231. % hObject handle to checkPDyelaser (see GCBO)
  232. % eventdata reserved - to be defined in a future version of MATLAB
  233. % handles structure with handles and user data (see GUIDATA)
  234. % Hint: get(hObject,'Value') returns toggle state of checkPDyelaser
  235. % --- Executes on button press in checkPVent.
  236. function checkPVent_Callback(hObject, eventdata, handles)
  237. % hObject handle to checkPVent (see GCBO)
  238. % eventdata reserved - to be defined in a future version of MATLAB
  239. % handles structure with handles and user data (see GUIDATA)
  240. % Hint: get(hObject,'Value') returns toggle state of checkPVent
  241. % --- Executes on button press in toggleDyelaser.
  242. function toggleDyelaser_Callback(hObject, eventdata, handles)
  243. % hObject handle to toggleDyelaser (see GCBO)
  244. % eventdata reserved - to be defined in a future version of MATLAB
  245. % handles structure with handles and user data (see GUIDATA)
  246. % Hint: get(hObject,'Value') returns toggle state of toggleDyelaser
  247. horusdata = getappdata(handles.parenthandle, 'horusdata');
  248. statusData=horusdata.statusData;
  249. col=horusdata.col;
  250. data = getappdata(handles.output, 'Dyelaserdata');
  251. lastrow=data.lastrow;
  252. if get(hObject,'Value')
  253. Valveword=bitset(statusData(lastrow,col.Valve),10+1);
  254. set(hObject,'BackgroundColor','g','String','Valve Dyelaser ON');
  255. else
  256. Valveword=bitset(statusData(lastrow,col.Valve),10+1,0);
  257. set(hObject,'BackgroundColor','c','String','Valve Dyelaser OFF');
  258. end
  259. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
  260. system(['/lift/bin/eCmd w 0xa408 ', num2str(Valveword)]);
  261. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(8*140))]); % 8V needed to keep solenoids open
  262. % --- Executes on button press in toggleVacuum.
  263. function toggleVacuum_Callback(hObject, eventdata, handles)
  264. % hObject handle to toggleVacuum (see GCBO)
  265. % eventdata reserved - to be defined in a future version of MATLAB
  266. % handles structure with handles and user data (see GUIDATA)
  267. % Hint: get(hObject,'Value') returns toggle state of toggleVacuum
  268. horusdata = getappdata(handles.parenthandle, 'horusdata');
  269. statusData=horusdata.statusData;
  270. col=horusdata.col;
  271. data = getappdata(handles.output, 'Dyelaserdata');
  272. lastrow=data.lastrow;
  273. if get(hObject,'Value')
  274. Valveword=bitset(statusData(lastrow,col.Valve),7+1);
  275. set(hObject,'BackgroundColor','g','String','Valve Vacuum ON');
  276. else
  277. Valveword=bitset(statusData(lastrow,col.Valve),7+1,0);
  278. set(hObject,'BackgroundColor','c','String','Valve Vacuum OFF');
  279. end
  280. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
  281. system(['/lift/bin/eCmd w 0xa408 ', num2str(Valveword)]);
  282. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(8*140))]); % 8V needed to keep solenoids open
  283. % --- Executes on button press in toggleN2.
  284. function toggleN2_Callback(hObject, eventdata, handles)
  285. % hObject handle to toggleN2 (see GCBO)
  286. % eventdata reserved - to be defined in a future version of MATLAB
  287. % handles structure with handles and user data (see GUIDATA)
  288. % Hint: get(hObject,'Value') returns toggle state of toggleN2
  289. horusdata = getappdata(handles.parenthandle, 'horusdata');
  290. statusData=horusdata.statusData;
  291. col=horusdata.col;
  292. data = getappdata(handles.output, 'Dyelaserdata');
  293. lastrow=data.lastrow;
  294. if get(hObject,'Value')
  295. Valveword=bitset(statusData(lastrow,col.Valve),9+1);
  296. set(hObject,'BackgroundColor','g','String','Valve N2 ON');
  297. else
  298. Valveword=bitset(statusData(lastrow,col.Valve),9+1,0);
  299. set(hObject,'BackgroundColor','c','String','Valve N2 OFF');
  300. end
  301. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
  302. system(['/lift/bin/eCmd w 0xa408 ', num2str(Valveword)]);
  303. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(8*140))]); % 8V needed to keep solenoids open
  304. % --- Executes on button press in toggleAmbient.
  305. function toggleAmbient_Callback(hObject, eventdata, handles)
  306. % hObject handle to toggleAmbient (see GCBO)
  307. % eventdata reserved - to be defined in a future version of MATLAB
  308. % handles structure with handles and user data (see GUIDATA)
  309. % Hint: get(hObject,'Value') returns toggle state of toggleAmbient
  310. horusdata = getappdata(handles.parenthandle, 'horusdata');
  311. statusData=horusdata.statusData;
  312. col=horusdata.col;
  313. data = getappdata(handles.output, 'Dyelaserdata');
  314. lastrow=data.lastrow;
  315. if get(hObject,'Value')
  316. Valveword=bitset(statusData(lastrow,col.Valve),8+1);
  317. set(hObject,'BackgroundColor','g','String','Valve Ambient ON');
  318. else
  319. Valveword=bitset(statusData(lastrow,col.Valve),8+1,0);
  320. set(hObject,'BackgroundColor','c','String','Valve Ambient OFF');
  321. end
  322. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(24*140))]); % 24V needed to switch solenoids on
  323. system(['/lift/bin/eCmd w 0xa408 ', num2str(Valveword)]);
  324. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(8*140))]); % 8V needed to keep solenoids open
  325. % --- Executes on button press in Exit.
  326. function Exit_Callback(hObject, eventdata, handles)
  327. % hObject handle to Exit (see GCBO)
  328. % eventdata reserved - to be defined in a future version of MATLAB
  329. % handles structure with handles and user data (see GUIDATA)
  330. stop(handles.ActTimer);
  331. delete(handles.ActTimer);
  332. if isvalid(handles.serport)
  333. fclose(handles.serport);
  334. delete(handles.serport);
  335. end;
  336. close(handles.figure1);
  337. function online_pos_Callback(hObject, eventdata, handles)
  338. % hObject handle to online_pos (see GCBO)
  339. % eventdata reserved - to be defined in a future version of MATLAB
  340. % handles structure with handles and user data (see GUIDATA)
  341. % Hints: get(hObject,'String') returns contents of online_pos as text
  342. % str2double(get(hObject,'String')) returns contents of online_pos as a double
  343. onlinepos=uint16(str2double(get(hObject,'String')));
  344. if isnan(onlinepos)
  345. set(hObject,'BackgroundColor','red');
  346. else
  347. set(hObject,'BackgroundColor','white');
  348. set(hObject,'string',num2str(onlinepos));
  349. end
  350. function scan_start_pos_Callback(hObject, eventdata, handles)
  351. % hObject handle to scan_start_pos (see GCBO)
  352. % eventdata reserved - to be defined in a future version of MATLAB
  353. % handles structure with handles and user data (see GUIDATA)
  354. % Hints: get(hObject,'String') returns contents of scan_start_pos as text
  355. % str2double(get(hObject,'String')) returns contents of scan_start_pos as a double
  356. scanstartpos=uint16(str2double(get(hObject,'String')));
  357. if isnan(scanstartpos)
  358. set(hObject,'BackgroundColor','red');
  359. else
  360. set(hObject,'BackgroundColor','white');
  361. set(hObject,'string',num2str(scanstartpos));
  362. end
  363. function scan_stop_pos_Callback(hObject, eventdata, handles)
  364. % hObject handle to scan_stop_pos (see GCBO)
  365. % eventdata reserved - to be defined in a future version of MATLAB
  366. % handles structure with handles and user data (see GUIDATA)
  367. % Hints: get(hObject,'String') returns contents of scan_stop_pos as text
  368. % str2double(get(hObject,'String')) returns contents of scan_stop_pos as a double
  369. scanstoppos=uint16(str2double(get(hObject,'String')));
  370. if isnan(scanstoppos)
  371. set(hObject,'BackgroundColor','red');
  372. else
  373. set(hObject,'BackgroundColor','white');
  374. set(hObject,'string',num2str(scanstoppos));
  375. end
  376. function scan_step_Callback(hObject, eventdata, handles)
  377. % hObject handle to scan_step (see GCBO)
  378. % eventdata reserved - to be defined in a future version of MATLAB
  379. % handles structure with handles and user data (see GUIDATA)
  380. % Hints: get(hObject,'String') returns contents of scan_step as text
  381. % str2double(get(hObject,'String')) returns contents of scan_step as a double
  382. scanstep=uint8(str2double(get(hObject,'String')));
  383. if isnan(scanstep)
  384. set(hObject,'BackgroundColor','red');
  385. else
  386. set(hObject,'BackgroundColor','white');
  387. scanstep=scanstep/16*16;
  388. if scanstep<=0, scanstep=16; end;
  389. set(hObject,'string',num2str(scanstep));
  390. end
  391. % --- Executes on button press in scan_pushbutton.
  392. function scan_pushbutton_Callback(hObject, eventdata, handles)
  393. % hObject handle to scan_pushbutton (see GCBO)
  394. % eventdata reserved - to be defined in a future version of MATLAB
  395. % handles structure with handles and user data (see GUIDATA)
  396. scanstartpos=uint16(str2double(get(handles.scan_start_pos,'String')));
  397. scanstoppos=uint16(str2double(get(handles.scan_stop_pos,'String')));
  398. scanstep=uint8(str2double(get(handles.scan_step,'String')));
  399. if (isnan(scanstartpos)| isnan(scanstoppos) | isnan(scanstep))
  400. error('invalid values');
  401. else
  402. system(['/lift/bin/eCmd s etalonnop']);
  403. system(['/lift/bin/eCmd s etalonscanstart ',num2str(scanstartpos)])
  404. system(['/lift/bin/eCmd s etalonscanstop ',num2str(scanstoppos)]);
  405. system(['/lift/bin/eCmd s etalonscanstep ',num2str(scanstep)]);
  406. system('/lift/bin/eCmd s etalonscan');
  407. end
  408. % --- Executes on button press in online_pushbutton.
  409. function online_pushbutton_Callback(hObject, eventdata, handles)
  410. % hObject handle to online_pushbutton (see GCBO)
  411. % eventdata reserved - to be defined in a future version of MATLAB
  412. % handles structure with handles and user data (see GUIDATA)
  413. onlinepos=uint16(str2double(get(handles.online_pos,'String')));
  414. if isnan(onlinepos)
  415. error('invalid values');
  416. else
  417. system(['/lift/bin/eCmd s etalonnop']);
  418. system(['/lift/bin/eCmd w 0xa510 ',num2str(onlinepos)]);
  419. system(['/lift/bin/eCmd s etalononline ',num2str(onlinepos)]);
  420. end
  421. % --- Executes on button press in offline_pushbutton.
  422. function offline_pushbutton_Callback(hObject, eventdata, handles)
  423. % hObject handle to offline_pushbutton (see GCBO)
  424. % eventdata reserved - to be defined in a future version of MATLAB
  425. % handles structure with handles and user data (see GUIDATA)
  426. onlinepos=uint16(str2double(get(handles.online_pos,'String')));
  427. offlinepos=onlinepos+1000;
  428. if isnan(onlinepos)
  429. error('invalid values');
  430. else
  431. system(['/lift/bin/eCmd s etalonnop']);
  432. system(['/lift/bin/eCmd w 0xa510 ',num2str(offlinepos)]);
  433. end
  434. % --- Executes on button press in toggle_pushbutton.
  435. function toggle_pushbutton_Callback(hObject, eventdata, handles)
  436. % hObject handle to toggle_pushbutton (see GCBO)
  437. % eventdata reserved - to be defined in a future version of MATLAB
  438. % handles structure with handles and user data (see GUIDATA)
  439. onlinepos=uint16(str2double(get(handles.online_pos,'String')));
  440. if isnan(onlinepos)
  441. error('invalid values');
  442. else
  443. system(['/lift/bin/eCmd s etalonnop']);
  444. system(['/lift/bin/eCmd s etalononline ',num2str(onlinepos)]);
  445. system(['/lift/bin/eCmd s etalonofflineleft 1000']);
  446. system(['/lift/bin/eCmd s etalonofflineright 1000']);
  447. system('/lift/bin/eCmd s etalondither 8');
  448. system('/lift/bin/eCmd s etalontoggle');
  449. end
  450. % --- Executes on button press in home_pushbutton.
  451. function home_pushbutton_Callback(hObject, eventdata, handles)
  452. % hObject handle to home_pushbutton (see GCBO)
  453. % eventdata reserved - to be defined in a future version of MATLAB
  454. % handles structure with handles and user data (see GUIDATA)
  455. system(['/lift/bin/eCmd s etalonnop']);
  456. system('/lift/bin/eCmd w 0xa510 0');
  457. % --- Executes on button press in toggleFilament.
  458. function toggleFilament_Callback(hObject, eventdata, handles)
  459. % hObject handle to toggleFilament (see GCBO)
  460. % eventdata reserved - to be defined in a future version of MATLAB
  461. % handles structure with handles and user data (see GUIDATA)
  462. % Hint: get(hObject,'Value') returns toggle state of toggleFilament
  463. horusdata = getappdata(handles.parenthandle, 'horusdata');
  464. statusData=horusdata.statusData;
  465. col=horusdata.col;
  466. data = getappdata(handles.output, 'Dyelaserdata');
  467. lastrow=data.lastrow;
  468. if get(hObject,'Value')
  469. if statusData(lastrow,col.PRef)<=10500 % check if pressure in reference cell is low enough
  470. Valveword=bitset(statusData(lastrow,col.Valve),14);
  471. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(15*140))]);% 15V needed to switch filament relay on
  472. system(['/lift/bin/eCmd w 0xa408 ', num2str(Valveword)]);
  473. system('sleep 1');
  474. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(8*140))]); % 8V needed to keep solenoids open
  475. set(hObject,'String','Filament is ON');
  476. set(hObject,'BackgroundColor','g');
  477. else
  478. set(hObject,'Value',0);
  479. end
  480. else
  481. Valveword=bitset(statusData(lastrow,col.Valve),14,0);
  482. system(['/lift/bin/eCmd w 0xa408 ', num2str(Valveword)]);
  483. set(hObject,'String','Filament is OFF');
  484. set(hObject,'BackgroundColor','c');
  485. end
  486. % --- Executes on button press in radioTime.
  487. function radioTime_Callback(hObject, eventdata, handles)
  488. % hObject handle to radioTime (see GCBO)
  489. % eventdata reserved - to be defined in a future version of MATLAB
  490. % handles structure with handles and user data (see GUIDATA)
  491. % Hint: get(hObject,'Value') returns toggle state of radioTime
  492. if get(hObject,'Value')
  493. set(handles.radioEtpos,'Value',0);
  494. end
  495. % --- Executes on button press in radioEtpos.
  496. function radioEtpos_Callback(hObject, eventdata, handles)
  497. % hObject handle to radioEtpos (see GCBO)
  498. % eventdata reserved - to be defined in a future version of MATLAB
  499. % handles structure with handles and user data (see GUIDATA)
  500. % Hint: get(hObject,'Value') returns toggle state of radioEtpos
  501. if get(hObject,'Value')
  502. set(handles.radioTime,'Value',0);
  503. end
  504. % --- Executes on button press in chkEtCurPos.
  505. function chkEtCurPos_Callback(hObject, eventdata, handles)
  506. % hObject handle to chkEtCurPos (see GCBO)
  507. % eventdata reserved - to be defined in a future version of MATLAB
  508. % handles structure with handles and user data (see GUIDATA)
  509. % Hint: get(hObject,'Value') returns toggle state of chkEtCurPos
  510. % --- Executes on button press in chkEtEncPos.
  511. function chkEtEncPos_Callback(hObject, eventdata, handles)
  512. % hObject handle to chkEtEncPos (see GCBO)
  513. % eventdata reserved - to be defined in a future version of MATLAB
  514. % handles structure with handles and user data (see GUIDATA)
  515. % Hint: get(hObject,'Value') returns toggle state of chkEtEncPos
  516. % --- Executes on button press in chkEtSetPos.
  517. function chkEtSetPos_Callback(hObject, eventdata, handles)
  518. % hObject handle to chkEtSetPos (see GCBO)
  519. % eventdata reserved - to be defined in a future version of MATLAB
  520. % handles structure with handles and user data (see GUIDATA)
  521. % Hint: get(hObject,'Value') returns toggle state of chkEtSetPos
  522. % --- Executes on button press in toggleShutter.
  523. function toggleShutter_Callback(hObject, eventdata, handles)
  524. % hObject handle to toggleShutter (see GCBO)
  525. % eventdata reserved - to be defined in a future version of MATLAB
  526. % handles structure with handles and user data (see GUIDATA)
  527. % Hint: get(hObject,'Value') returns toggle state of toggleShutter
  528. horusdata = getappdata(handles.parenthandle, 'horusdata');
  529. statusData=horusdata.statusData;
  530. col=horusdata.col;
  531. data = getappdata(handles.output, 'Dyelaserdata');
  532. lastrow=data.lastrow;
  533. if get(hObject,'Value')
  534. Valveword=bitset(statusData(lastrow,col.Valve),13);
  535. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(20*140))]);% 20V needed to close shutter
  536. system(['/lift/bin/eCmd w 0xa408 ', num2str(Valveword)]);
  537. set(hObject,'String','Shutter is CLOSED');
  538. set(hObject,'BackgroundColor','c');
  539. system('sleep 1');
  540. system(['/lift/bin/eCmd w 0xa468 ', num2str(uint16(8*140))]); % 8V needed to keep solenoids open
  541. else
  542. Valveword=bitset(statusData(lastrow,col.Valve),13,0);
  543. system(['/lift/bin/eCmd w 0xa408 ', num2str(Valveword)]);
  544. set(hObject,'String','Shutter is OPEN');
  545. set(hObject,'BackgroundColor','g');
  546. end
  547. % --- Executes on selection change in popupmirror.
  548. function popupmirror_Callback(hObject, eventdata, handles)
  549. % hObject handle to popupmirror (see GCBO)
  550. % eventdata reserved - to be defined in a future version of MATLAB
  551. % handles structure with handles and user data (see GUIDATA)
  552. % Hints: contents = get(hObject,'String') returns popupmirror contents as cell array
  553. % contents{get(hObject,'Value')} returns selected item from popupmirror
  554. set(handles.textPos,'String','0');
  555. % --- Executes during object creation, after setting all properties.
  556. function popupmirror_CreateFcn(hObject, eventdata, handles)
  557. % hObject handle to popupmirror (see GCBO)
  558. % eventdata reserved - to be defined in a future version of MATLAB
  559. % handles empty - handles not created until after all CreateFcns called
  560. % Hint: popupmenu controls usually have a white background on Windows.
  561. % See ISPC and COMPUTER.
  562. set(hObject,'Value',2);
  563. % --- Executes on button press in radiohor.
  564. function radiohor_Callback(hObject, eventdata, handles)
  565. % hObject handle to radiohor (see GCBO)
  566. % eventdata reserved - to be defined in a future version of MATLAB
  567. % handles structure with handles and user data (see GUIDATA)
  568. if get(hObject,'Value')
  569. set(handles.radiover,'Value',0);
  570. end
  571. set(handles.textPos,'String','0');
  572. % --- Executes on button press in radiover.
  573. function radiover_Callback(hObject, eventdata, handles)
  574. % hObject handle to radiover (see GCBO)
  575. % eventdata reserved - to be defined in a future version of MATLAB
  576. % handles structure with handles and user data (see GUIDATA)
  577. if get(hObject,'Value')
  578. set(handles.radiohor,'Value',0);
  579. end
  580. set(handles.textPos,'String','0');
  581. % --- Executes on button press in radiofor.
  582. function radiofor_Callback(hObject, eventdata, handles)
  583. % hObject handle to radiofor (see GCBO)
  584. % eventdata reserved - to be defined in a future version of MATLAB
  585. % handles structure with handles and user data (see GUIDATA)
  586. if get(hObject,'Value')
  587. set(handles.radiorev,'Value',0);
  588. end
  589. % --- Executes on button press in radiorev.
  590. function radiorev_Callback(hObject, eventdata, handles)
  591. % hObject handle to radiorev (see GCBO)
  592. % eventdata reserved - to be defined in a future version of MATLAB
  593. % handles structure with handles and user data (see GUIDATA)
  594. if get(hObject,'Value')
  595. set(handles.radiofor,'Value',0);
  596. end
  597. function editsteps_Callback(hObject, eventdata, handles)
  598. % hObject handle to editsteps (see GCBO)
  599. % eventdata reserved - to be defined in a future version of MATLAB
  600. % handles structure with handles and user data (see GUIDATA)
  601. % Hints: get(hObject,'String') returns contents of editsteps as text
  602. % str2double(get(hObject,'String')) returns contents of editsteps as a double
  603. steps=uint16(str2double(get(hObject,'String')));
  604. if isnan(steps)
  605. set(hObject,'BackgroundColor','red');
  606. else
  607. set(hObject,'BackgroundColor','white');
  608. set(hObject,'string',num2str(steps));
  609. end
  610. % --- Executes on button press in pushgo.
  611. function pushgo_Callback(hObject, eventdata, handles)
  612. % hObject handle to pushgo (see GCBO)
  613. % eventdata reserved - to be defined in a future version of MATLAB
  614. % handles structure with handles and user data (see GUIDATA)
  615. set(handles.textPos,'BackgroundColor','r');
  616. set(handles.pushgo,'BackgroundColor','r');
  617. serport=handles.serport;
  618. steps=get(handles.editsteps,'String');
  619. hor=get(handles.radiohor,'Value');
  620. forw=get(handles.radiofor,'Value');
  621. oldpos=str2double(get(handles.textPos,'String'));
  622. switch get(handles.popupmirror,'Value')
  623. case 1
  624. driver='a1';
  625. if hor==1 chl='0';
  626. else chl='1';
  627. end
  628. case 2
  629. if hor==1;
  630. driver='a1';
  631. chl='2';
  632. else
  633. driver='a2';
  634. chl='0';
  635. end
  636. case 3
  637. driver='a2';
  638. if hor==1 chl='1';
  639. else chl='2';
  640. end
  641. end
  642. fprintf(serport,['chl ',driver,'=',chl]);
  643. if forw==1
  644. fprintf(serport,['rel ',driver,' ',steps]);
  645. else
  646. fprintf(serport,['rel ',driver,' -',steps]);
  647. end
  648. fprintf(serport,['go ',driver]);
  649. % check if motor is still moving
  650. fprintf(serport,['pos ',driver]);
  651. x=find(serport.UserData=='=');
  652. pos2=str2double(serport.UserData(x+1:length(serport.UserData)-1));
  653. %serport.UserData
  654. pos1=pos2-1;
  655. while pos2~=pos1
  656. pos1=pos2;
  657. pause(1);
  658. fprintf(serport,['pos ',driver]);
  659. x=find(serport.UserData=='=');
  660. pos2=str2double(serport.UserData(x+1:length(serport.UserData)-1));
  661. end
  662. % display new motor position after motor has stopped
  663. newpos=oldpos+pos2;
  664. set(handles.textPos,'String',num2str(newpos),'BackgroundColor','w');
  665. set(handles.pushgo,'BackgroundColor','w');
  666. % --- Executes on button press in pushStop.
  667. function pushStop_Callback(hObject, eventdata, handles)
  668. % hObject handle to pushStop (see GCBO)
  669. % eventdata reserved - to be defined in a future version of MATLAB
  670. % handles structure with handles and user data (see GUIDATA)
  671. fprintf(handles.serport,'hal');