/matlab/Laser.asv

http://github.com/Yniold/liftsrc · Unknown · 646 lines · 559 code · 87 blank · 0 comment · 0 complexity · 788a0d2dc4c66b640f73c14a046b306c MD5 · raw file

  1. function varargout = Laser(varargin)
  2. % GUI for pump laser control
  3. % diode current should be 35.4 for PSSN 120865, HEADSN 2363/710
  4. % diode temperature should be 26.1?C for PSSN 120865, HEADSN 2363/710
  5. % crystal temperature should be 151 for PSSN 120865, HEADSN 2363/710
  6. % LASER M-file for Laser.fig
  7. % LASER, by itself, creates a new LASER or raises the existing
  8. % singleton*.
  9. %
  10. % H = LASER returns the handle to a new LASER or the handle to
  11. % the existing singleton*.
  12. %
  13. % LASER('CALLBACK',hObject,eventData,handles,...) calls the local
  14. % function named CALLBACK in LASER.M with the given input arguments.
  15. %
  16. % LASER('Property','Value',...) creates a new LASER or raises the
  17. % existing singleton*. Starting from the left, property value pairs are
  18. % applied to the GUI before Laser_OpeningFunction gets called. An
  19. % unrecognized property name or invalid value makes property application
  20. % stop. All inputs are passed to Laser_OpeningFcn via varargin.
  21. %
  22. % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
  23. % instance to run (singleton)".
  24. %
  25. % See also: GUIDE, GUIDATA, GUIHANDLES
  26. % Copyright 2002-2003 The MathWorks, Inc.
  27. % Edit the above text to modify the response to help Laser
  28. % Last Modified by GUIDE v2.5 09-Feb-2005 14:06:24
  29. % Begin initialization code - DO NOT EDIT
  30. gui_Singleton = 1;
  31. gui_State = struct('gui_Name', mfilename, ...
  32. 'gui_Singleton', gui_Singleton, ...
  33. 'gui_OpeningFcn', @Laser_OpeningFcn, ...
  34. 'gui_OutputFcn', @Laser_OutputFcn, ...
  35. 'gui_LayoutFcn', [] , ...
  36. 'gui_Callback', []);
  37. if nargin && ischar(varargin{1})
  38. gui_State.gui_Callback = str2func(varargin{1});
  39. end
  40. if nargout
  41. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  42. else
  43. gui_mainfcn(gui_State, varargin{:});
  44. end
  45. % End initialization code - DO NOT EDIT
  46. % --- Executes just before Laser is made visible.
  47. function Laser_OpeningFcn(hObject, eventdata, handles, varargin)
  48. % This function has no output args, see OutputFcn.
  49. % hObject handle to figure
  50. % eventdata reserved - to be defined in a future version of MATLAB
  51. % handles structure with handles and user data (see GUIDATA)
  52. % varargin command line arguments to Laser (see VARARGIN)
  53. % Choose default command line output for Laser
  54. handles.output = hObject;
  55. % get horus handle
  56. if length(varargin)==2 & varargin{1}=='handle'
  57. handles.parenthandle=str2double(varargin{2});
  58. end
  59. % open tcpip port for communication with Laser
  60. echotcpip('on',10001);
  61. tcpdata.tport=tcpip('10.111.111.20',10001);
  62. set(tcpdata.tport,'ReadAsyncMode','continuous');
  63. set(tcpdata.tport,'BytesAvailableFcn',{'tcpipdatacallback'});
  64. fopen(tcpdata.tport);
  65. tport=tcpdata.tport;
  66. % check which laser head and power supply is being used and display what
  67. % the settings should be
  68. fprintf(tport,'?PSSN');
  69. pause(0.5);
  70. PSSN=tport.UserData;
  71. fprintf(tport,'?HEADSN');
  72. pause(0.5);
  73. HEADSN=tport.UserData;
  74. % diode current should be 35.4 for PSSN 120865, HEADSN 2363/710
  75. % diode temperature should be 26.1?C for PSSN 120865, HEADSN 2363/710
  76. % crystal temperature should be 151 for PSSN 120865, HEADSN 2363/710
  77. % diode current should be 36.0 for PSSN 120881, HEADSN 2366/712
  78. % diode temperature should be 28.6?C for PSSN 120881, HEADSN 2366/712
  79. % crystal temperature should be 130 for PSSN 120881, HEADSN 2366/712
  80. set(handles.txtsetReprate,'String','3000 kHz'); % pulses/s
  81. if PSSN(1:6)=='120865'
  82. set(handles.txtsetDiodeCurrent,'String','35.4 A');
  83. set(handles.txtsetDiodeTemp,'String','26.1 C');
  84. set(handles.txtsetIRPower,'String','4.5 W'); % IR intern
  85. elseif PSSN(1:6)=='120881'
  86. set(handles.txtsetDiodeCurrent,'String','36.0 A');
  87. set(handles.txtsetDiodeTemp,'String','28.6 C');
  88. set(handles.txtsetIRPower,'String','4.45 W'); % IR intern
  89. end
  90. if HEADSN(1:8)=='2363/710'
  91. set(handles.txtsetCrtemp,'String','151'); % ADC Counts
  92. set(handles.txtsetTowerTemp,'String','??? C');
  93. elseif HEADSN(1:8)=='2366/712'
  94. set(handles.txtsetCrtemp,'String','130'); % ADC Counts
  95. set(handles.txtsetTowerTemp,'String','28.6 C');
  96. end
  97. % Update handles structure
  98. guidata(hObject, handles);
  99. setappdata(handles.output, 'tcpdata', tcpdata);
  100. % --- Outputs from this function are returned to the command line.
  101. function varargout = Laser_OutputFcn(hObject, eventdata, handles)
  102. % varargout cell array for returning output args (see VARARGOUT);
  103. % hObject handle to figure
  104. % eventdata reserved - to be defined in a future version of MATLAB
  105. % handles structure with handles and user data (see GUIDATA)
  106. % Get default command line output from handles structure
  107. varargout{1} = handles.output;
  108. % --- Executes on button press in toggleLaser.
  109. function toggleLaser_Callback(hObject, eventdata, handles)
  110. % hObject handle to toggleLaser (see GCBO)
  111. % eventdata reserved - to be defined in a future version of MATLAB
  112. % handles structure with handles and user data (see GUIDATA)
  113. set(handles.txtStatus,'String','Query Status','ForegroundColor','r');
  114. Zeit=clock;
  115. set(handles.txtZeit,'String',datestr(Zeit,13));
  116. %mark strings to be updated
  117. set(handles.txtDiodeCurrent,'ForegroundColor','r');
  118. set(handles.txtIRPower,'ForegroundColor','r');
  119. set(handles.txtDiodeTemp,'ForegroundColor','r');
  120. set(handles.txtTowerTemp,'ForegroundColor','r');
  121. % switch laser on or off
  122. tcpdata = getappdata(handles.output, 'tcpdata');
  123. tport=tcpdata.tport;
  124. if get(hObject,'Value')
  125. fprintf(tport,'D1');
  126. set(hObject,'BackgroundColor','r');
  127. set(hObject,'String','Laser switched ON')
  128. pause(0.5);
  129. else
  130. fprintf(tport,'D0');
  131. set(hObject,'BackgroundColor','y');
  132. set(hObject,'String','Laser switched OFF')
  133. pause(0.5);
  134. end
  135. pause(3)
  136. fprintf(tport,'?D');
  137. pause(0.5);
  138. DiodeStatus=tport.UserData;
  139. % check if switching was successfull and update laser toggle
  140. if strcmp(DiodeStatus(1:2),'ON')
  141. set(hObject,'Value',1)
  142. set(hObject,'BackgroundColor','r');
  143. set(hObject,'String','Laser is ON')
  144. elseif strcmp(DiodeStatus(1:3),'OFF')
  145. set(hObject,'Value',0)
  146. set(hObject,'BackgroundColor','g');
  147. set(hObject,'String','Laser is OFF')
  148. end
  149. % check diode parameters
  150. % diode current
  151. fprintf(tport,'?C1');
  152. pause(0.5);
  153. DiodeCurrent=tport.UserData;
  154. set(handles.txtDiodeCurrent,'String',DiodeCurrent,'ForegroundColor','k');
  155. % check diode current setting and update power toggle
  156. fprintf(tport,'?CS1');
  157. pause(0.5);
  158. DiodeCurrentSet=tport.UserData;
  159. % current depends on power supply
  160. fprintf(tport,'?PSSN');
  161. pause(0.5);
  162. PSSN=tport.UserData;
  163. if PSSN(1:6)=='120865'
  164. if str2double(DiodeCurrentSet)==35.4
  165. set(handles.togglePower,'Value',1,'String','FULL Power','BackgroundColor','g');
  166. elseif str2double(DiodeCurrentSet)==14
  167. set(handles.togglePower,'Value',0,'String','LOW Power','BackgroundColor','c');
  168. else
  169. set(handles.togglePower,'Value',0,'String','medium Power','BackgroundColor','c');
  170. end
  171. elseif PSSN(1:6)=='120881'
  172. if str2double(DiodeCurrentSet)==36.0
  173. set(handles.togglePower,'Value',1,'String','FULL Power','BackgroundColor','g');
  174. elseif str2double(DiodeCurrentSet)==14
  175. set(handles.togglePower,'Value',0,'String','LOW Power','BackgroundColor','c');
  176. else
  177. set(handles.togglePower,'Value',0,'String','medium Power','BackgroundColor','c');
  178. end
  179. end
  180. % IR power
  181. fprintf(tport,'?P');
  182. pause(0.5);
  183. IRPower=tport.UserData;
  184. set(handles.txtIRPower,'String',IRPower,'ForegroundColor','k');
  185. % diode temperature
  186. fprintf(tport,'?T1');
  187. pause(0.5);
  188. DiodeTemp=tport.UserData;
  189. set(handles.txtDiodeTemp,'String',DiodeTemp,'ForegroundColor','k');
  190. % tower temperature
  191. fprintf(tport,'?TT');
  192. pause(0.5);
  193. TowerTemp=tport.UserData;
  194. set(handles.txtTowerTemp,'String',TowerTemp,'ForegroundColor','k');
  195. set(handles.txtStatus,'String','Idle','ForegroundColor','k');
  196. % --- Executes on button press in toggleShutter.
  197. function toggleShutter_Callback(hObject, eventdata, handles)
  198. % hObject handle to toggleShutter (see GCBO)
  199. % eventdata reserved - to be defined in a future version of MATLAB
  200. % handles structure with handles and user data (see GUIDATA)
  201. set(handles.txtStatus,'String','Query Status','ForegroundColor','r');
  202. tcpdata = getappdata(handles.output, 'tcpdata');
  203. tport=tcpdata.tport;
  204. % switch shutter on or off
  205. if get(hObject,'Value')
  206. fprintf(tport,'SHT:1');
  207. set(hObject,'BackgroundColor','r')
  208. set(hObject,'String','Shutter opened')
  209. pause(0.5);
  210. else
  211. fprintf(tport,'SHT:0');
  212. set(hObject,'BackgroundColor','y')
  213. set(hObject,'String','Shutter closed')
  214. pause(0.5);
  215. end
  216. %check if switching was successfull
  217. fprintf(tport,'?SHT');
  218. pause(3);
  219. ShutterStatus=tport.UserData;
  220. if strcmp(ShutterStatus(1:4),'OPEN') %shutter is open
  221. set(hObject,'Value',1)
  222. set(hObject,'BackgroundColor','r')
  223. set(hObject,'String','Shutter is OPEN')
  224. elseif strcmp(ShutterStatus(1:6),'CLOSED')
  225. set(hObject,'Value',0)
  226. set(hObject,'BackgroundColor','g')
  227. set(hObject,'String','Shutter is CLOSED')
  228. end
  229. set(handles.txtStatus,'String','Idle','ForegroundColor','k');
  230. function edtCommand_Callback(hObject, eventdata, handles)
  231. % hObject handle to edtCommand (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. % Hints: get(hObject,'String') returns contents of edtCommand as text
  235. % str2double(get(hObject,'String')) returns contents of edtCommand as a double
  236. set(handles.txtStatus,'String','Query Status','ForegroundColor','r');
  237. %mark strings to be updated
  238. set(handles.txtReprate,'ForegroundColor','r');
  239. set(handles.txtCrtemp,'ForegroundColor','r');
  240. set(handles.txtDiodeCurrent,'ForegroundColor','r');
  241. set(handles.txtDiodeMaxCurrent,'ForegroundColor','r');
  242. set(handles.txtIRPower,'ForegroundColor','r');
  243. set(handles.txtDiodeTemp,'ForegroundColor','r');
  244. set(handles.txtTowerTemp,'ForegroundColor','r');
  245. tcpdata = getappdata(handles.output, 'tcpdata');
  246. tport=tcpdata.tport;
  247. LaserCmd=get(hObject,'String');
  248. % if the command is laser switching, update Laser toggle button
  249. if LaserCmd(1)=='d'
  250. if LaserCmd(2)=='1'
  251. set(handles.toggleLaser,'BackgroundColor','r');
  252. set(handles.toggleLaser,'String','Laser switched ON')
  253. elseif LaserCmd(2)=='0'
  254. set(handles.toggleLaser,'BackgroundColor','y');
  255. set(handles.toggleLaser,'String','Laser switched OFF')
  256. end
  257. end
  258. % send command and read answer, if any
  259. fprintf(tport,LaserCmd);
  260. pause(4);
  261. LaserAns=tport.UserData;
  262. % if command is a query, display answer
  263. if LaserCmd(1)=='?'
  264. set(handles.txtCommandAnswer,'String',LaserAns);
  265. else %if command is not a query, send query to check effect and display answer
  266. fprintf(tport,['?',LaserCmd(isletter(LaserCmd))]);
  267. pause(0.5);
  268. LaserAns=tport.UserData;
  269. if isempty(deblank(LaserAns)) % some queries require specifying #
  270. fprintf(tport,['?',LaserCmd(isletter(LaserCmd)),'1']); % # is always 1 for our system
  271. pause(0.5);
  272. LaserAns=tport.UserData;
  273. end
  274. set(handles.txtCommandAnswer,'String',LaserAns);
  275. end
  276. % update laser status info
  277. Zeit=clock;
  278. set(handles.txtZeit,'String',datestr(Zeit,13));
  279. % check diode switch status and update laser toggle
  280. fprintf(tport,'?D');
  281. pause(0.5);
  282. DiodeStatus=tport.UserData;
  283. if strcmp(DiodeStatus(1:2),'ON')
  284. set(handles.toggleLaser,'Value',1)
  285. set(handles.toggleLaser,'BackgroundColor','r');
  286. set(handles.toggleLaser,'String','Laser is ON')
  287. elseif strcmp(DiodeStatus(1:3),'OFF')
  288. set(handles.toggleLaser,'Value',0)
  289. set(handles.toggleLaser,'BackgroundColor','g');
  290. set(handles.toggleLaser,'String','Laser is OFF')
  291. end
  292. %check shutter and update shutter toggle
  293. fprintf(tport,'?SHT');
  294. pause(0.5);
  295. ShutterStatus=tport.UserData;
  296. if strcmp(ShutterStatus(1:6),'CLOSED')
  297. set(handles.toggleShutter,'Value',0)
  298. set(handles.toggleShutter,'BackgroundColor','g')
  299. set(handles.toggleShutter,'String','Shutter is CLOSED')
  300. elseif strcmp(ShutterStatus(1:4),'OPEN')
  301. set(handles.toggleShutter,'Value',1)
  302. set(handles.toggleShutter,'BackgroundColor','r')
  303. set(handles.toggleShutter,'String','Shutter is OPEN')
  304. end
  305. %check diode current
  306. fprintf(tport,'?C1');
  307. pause(0.5);
  308. DiodeCurrent=tport.UserData;
  309. set(handles.txtDiodeCurrent,'String',DiodeCurrent,'ForegroundColor','k');
  310. %check diode current setting and update power toggle
  311. fprintf(tport,'?CS1');
  312. pause(0.5);
  313. DiodeCurrentSet=tport.UserData;
  314. % current depends on power supply
  315. fprintf(tport,'?PSSN');
  316. pause(0.5);
  317. PSSN=tport.UserData;
  318. if PSSN(1:6)=='120865'
  319. if str2double(DiodeCurrentSet)==35.4
  320. set(handles.togglePower,'Value',1,'String','FULL Power','BackgroundColor','g');
  321. elseif str2double(DiodeCurrentSet)==14
  322. set(handles.togglePower,'Value',0,'String','LOW Power','BackgroundColor','c');
  323. else
  324. set(handles.togglePower,'Value',0,'String','medium Power','BackgroundColor','c');
  325. end
  326. elseif PSSN(1:6)=='120881'
  327. if str2double(DiodeCurrentSet)==36.0
  328. set(handles.togglePower,'Value',1,'String','FULL Power','BackgroundColor','g');
  329. elseif str2double(DiodeCurrentSet)==14
  330. set(handles.togglePower,'Value',0,'String','LOW Power','BackgroundColor','c');
  331. else
  332. set(handles.togglePower,'Value',0,'String','medium Power','BackgroundColor','c');
  333. end
  334. end
  335. % check repetition rate
  336. fprintf(tport,'?Q');
  337. pause(0.5);
  338. RepRate=tport.UserData;
  339. set(handles.txtReprate,'String',RepRate,'ForegroundColor','k');
  340. % check crystal temp.
  341. fprintf(tport,'?SHG');
  342. pause(0.5);
  343. CrystalTmp=tport.UserData;
  344. set(handles.txtCrtemp,'String',CrystalTmp,'ForegroundColor','k');
  345. % check tower temperature
  346. fprintf(tport,'?TT');
  347. pause(0.5);
  348. TowerTemp=tport.UserData;
  349. set(handles.txtTowerTemp,'String',TowerTemp,'ForegroundColor','k');
  350. % check max. allowed diode current
  351. fprintf(tport,'?DCL1');
  352. pause(0.5);
  353. DiodeMaxCurrent=tport.UserData;
  354. set(handles.txtDiodeMaxCurrent,'String',DiodeMaxCurrent,'ForegroundColor','k');
  355. % check diode temp.
  356. fprintf(tport,'?T1');
  357. pause(0.5);
  358. DiodeTemp=tport.UserData;
  359. set(handles.txtDiodeTemp,'String',DiodeTemp,'ForegroundColor','k');
  360. % check IR power
  361. fprintf(tport,'?P');
  362. pause(0.5);
  363. IRPower=tport.UserData;
  364. set(handles.txtIRPower,'String',IRPower,'ForegroundColor','k');
  365. set(handles.txtStatus,'String','Idle','ForegroundColor','k');
  366. % --- Executes on button press in pubExit.
  367. function pubExit_Callback(hObject, eventdata, handles)
  368. % hObject handle to pubExit (see GCBO)
  369. % eventdata reserved - to be defined in a future version of MATLAB
  370. % handles structure with handles and user data (see GUIDATA)
  371. % shut down tcpip connection
  372. tcpdata = getappdata(handles.output, 'tcpdata');
  373. tport=tcpdata.tport;
  374. fclose(tcpdata.tport);
  375. delete(tcpdata.tport);
  376. echotcpip('off');
  377. close(handles.figure1);
  378. % --- Executes on button press in Update.
  379. function Update_Callback(hObject, eventdata, handles)
  380. % hObject handle to Update (see GCBO)
  381. % eventdata reserved - to be defined in a future version of MATLAB
  382. % handles structure with handles and user data (see GUIDATA)
  383. set(handles.txtStatus,'String','Query Status','ForegroundColor','r');
  384. tcpdata = getappdata(handles.output, 'tcpdata');
  385. tport=tcpdata.tport;
  386. Zeit=clock;
  387. set(handles.txtZeit,'String',datestr(Zeit,13));
  388. %mark strings to be updated
  389. set(handles.txtReprate,'ForegroundColor','r');
  390. set(handles.txtCrtemp,'ForegroundColor','r');
  391. set(handles.txtDiodeCurrent,'ForegroundColor','r');
  392. set(handles.txtDiodeMaxCurrent,'ForegroundColor','r');
  393. set(handles.txtIRPower,'ForegroundColor','r');
  394. set(handles.txtDiodeTemp,'ForegroundColor','r');
  395. set(handles.txtTowerTemp,'ForegroundColor','r');
  396. % check diode switch status and update laser toggle
  397. fprintf(tport,'?D');
  398. pause(0.5);
  399. DiodeStatus=tport.UserData;
  400. if strcmp(DiodeStatus(1:2),'ON')
  401. set(handles.toggleLaser,'Value',1)
  402. set(handles.toggleLaser,'BackgroundColor','r');
  403. set(handles.toggleLaser,'String','Laser is ON')
  404. elseif strcmp(DiodeStatus(1:3),'OFF')
  405. set(handles.toggleLaser,'Value',0)
  406. set(handles.toggleLaser,'BackgroundColor','g');
  407. set(handles.toggleLaser,'String','Laser is OFF')
  408. end
  409. % check shutter and update shutter toggle
  410. fprintf(tport,'?SHT');
  411. pause(0.5);
  412. ShutterStatus=tport.UserData;
  413. if strcmp(ShutterStatus(1:6),'CLOSED')
  414. set(handles.toggleShutter,'Value',0)
  415. set(handles.toggleShutter,'BackgroundColor','g')
  416. set(handles.toggleShutter,'String','Shutter is CLOSED')
  417. elseif strcmp(ShutterStatus(1:4),'OPEN')
  418. set(handles.toggleShutter,'Value',1)
  419. set(handles.toggleShutter,'BackgroundColor','r')
  420. set(handles.toggleShutter,'String','Shutter is OPEN')
  421. end
  422. % check diode current
  423. fprintf(tport,'?C1');
  424. pause(0.5);
  425. DiodeCurrent=tport.UserData;
  426. set(handles.txtDiodeCurrent,'String',DiodeCurrent,'ForegroundColor','k');
  427. %check diode current setting and update power toggle
  428. fprintf(tport,'?CS1');
  429. pause(0.5);
  430. DiodeCurrentSet=tport.UserData;
  431. % current depends on power supply
  432. fprintf(tport,'?PSSN');
  433. pause(0.5);
  434. PSSN=tport.UserData;
  435. if PSSN(1:6)=='120865'
  436. if str2double(DiodeCurrentSet)==35.4
  437. set(handles.togglePower,'Value',1,'String','FULL Power','BackgroundColor','g');
  438. elseif str2double(DiodeCurrentSet)==14
  439. set(handles.togglePower,'Value',0,'String','LOW Power','BackgroundColor','c');
  440. else
  441. set(handles.togglePower,'Value',0,'String','medium Power','BackgroundColor','c');
  442. end
  443. elseif PSSN(1:6)=='120881'
  444. if str2double(DiodeCurrentSet)==36.0
  445. set(handles.togglePower,'Value',1,'String','FULL Power','BackgroundColor','g');
  446. elseif str2double(DiodeCurrentSet)==14
  447. set(handles.togglePower,'Value',0,'String','LOW Power','BackgroundColor','c');
  448. else
  449. set(handles.togglePower,'Value',0,'String','medium Power','BackgroundColor','c');
  450. end
  451. end
  452. % check repetition rate
  453. fprintf(tport,'?Q');
  454. pause(0.5);
  455. RepRate=tport.UserData;
  456. set(handles.txtReprate,'String',RepRate,'ForegroundColor','k');
  457. % check crystal temperature
  458. fprintf(tport,'?SHG');
  459. pause(0.5);
  460. CrystalTmp=tport.UserData;
  461. set(handles.txtCrtemp,'String',CrystalTmp,'ForegroundColor','k');
  462. % check tower temperature
  463. fprintf(tport,'?TT');
  464. pause(0.5);
  465. TowerTemp=tport.UserData;
  466. set(handles.txtTowerTemp,'String',TowerTemp,'ForegroundColor','k');
  467. % check max. allowed diode current
  468. fprintf(tport,'?DCL1');
  469. pause(0.5);
  470. DiodeMaxCurrent=tport.UserData;
  471. set(handles.txtDiodeMaxCurrent,'String',DiodeMaxCurrent,'ForegroundColor','k');
  472. % check diode temperature
  473. fprintf(tport,'?T1');
  474. pause(0.5);
  475. DiodeTemp=tport.UserData;
  476. set(handles.txtDiodeTemp,'String',DiodeTemp,'ForegroundColor','k');
  477. % check IR power
  478. fprintf(tport,'?P');
  479. pause(0.5);
  480. IRPower=tport.UserData;
  481. set(handles.txtIRPower,'String',IRPower,'ForegroundColor','k');
  482. set(handles.txtStatus,'String','Idle','ForegroundColor','k');
  483. % --- Executes on button press in togglePower.
  484. function togglePower_Callback(hObject, eventdata, handles)
  485. % hObject handle to togglePower (see GCBO)
  486. % eventdata reserved - to be defined in a future version of MATLAB
  487. % handles structure with handles and user data (see GUIDATA)
  488. % Hint: get(hObject,'Value') returns toggle state of togglePower
  489. set(handles.txtStatus,'String','Query Status','ForegroundColor','r');
  490. tcpdata = getappdata(handles.output, 'tcpdata');
  491. tport=tcpdata.tport;
  492. % mark strings to be updated
  493. set(handles.txtDiodeCurrent,'ForegroundColor','r');
  494. set(handles.txtIRPower,'ForegroundColor','r');
  495. set(handles.txtCrtemp,'ForegroundColor','r');
  496. set(handles.txtDiodeTemp,'ForegroundColor','r');
  497. set(handles.txtTowerTemp,'ForegroundColor','r');
  498. % current depends on power supply
  499. fprintf(tport,'?PSSN');
  500. pause(0.5);
  501. PSSN=tport.UserData;
  502. if PSSN(1:6)=='120865'
  503. if get(hObject,'Value')
  504. fprintf(tport,'C1:35.4'); % full power
  505. else
  506. fprintf(tport,'C1:14'); % lowest green power
  507. end
  508. elseif PSSN(1:6)=='120881'
  509. if get(hObject,'Value')
  510. fprintf(tport,'C1:36.0'); % full power
  511. else
  512. fprintf(tport,'C1:14'); % lowest green power
  513. end
  514. end
  515. % check effect
  516. pause(0.5)
  517. fprintf(tport,'?CS1');
  518. pause(0.5);
  519. DiodeCurrentSet=tport.UserData;
  520. % current depends on power supply
  521. if (PSSN(1:6)=='120865' & str2double(DiodeCurrentSet)==35.4)...
  522. | (PSSN(1:6)=='120881' & str2double(DiodeCurrentSet)==36.0)
  523. set(handles.togglePower,'Value',1)
  524. set(handles.togglePower,'BackgroundColor','c');
  525. set(handles.togglePower,'String','FULL Power')
  526. else
  527. set(handles.togglePower,'Value',0)
  528. set(handles.togglePower,'BackgroundColor','b');
  529. set(handles.togglePower,'String','LOW Power')
  530. if str2double(DiodeCurrentSet)~=14
  531. set(handles.togglePower,'String','medium Power')
  532. end
  533. end
  534. % check crystal temp.
  535. fprintf(tport,'?SHG');
  536. pause(0.5);
  537. CrystalTmp=tport.UserData;
  538. set(handles.txtCrtemp,'String',CrystalTmp,'ForegroundColor','k');
  539. % check tower temperature
  540. fprintf(tport,'?TT');
  541. pause(0.5);
  542. TowerTemp=tport.UserData;
  543. set(handles.txtTowerTemp,'String',TowerTemp,'ForegroundColor','k');
  544. % check diode temp.
  545. fprintf(tport,'?T1');
  546. pause(0.5);
  547. DiodeTemp=tport.UserData;
  548. set(handles.txtDiodeTemp,'String',DiodeTemp,'ForegroundColor','k');
  549. % check diode current
  550. fprintf(tport,'?C1');
  551. pause(0.5);
  552. DiodeCurrent=tport.UserData;
  553. set(handles.txtDiodeCurrent,'String',DiodeCurrent,'ForegroundColor','k');
  554. % check IR power
  555. fprintf(tport,'?P');
  556. pause(0.5);
  557. IRPower=tport.UserData;
  558. set(handles.txtIRPower,'String',IRPower,'ForegroundColor','k');
  559. set(handles.txtStatus,'String','Idle','ForegroundColor','k');