PageRenderTime 77ms CodeModel.GetById 16ms app.highlight 55ms RepoModel.GetById 1ms app.codeStats 1ms

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