source: MML/trunk/machine/SOLEIL/common/diag/DserverBPM/DserverBPM.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 18.8 KB
Line 
1function varargout = DserverBPM(varargin)
2% DSERVERBPM M-file for DserverBPM.fig
3%      DSERVERBPM, by itself, creates a new DSERVERBPM or raises the existing
4%      singleton*.
5%
6%      H = DSERVERBPM returns the handle to a new DSERVERBPM or the handle to
7%      the existing singleton*.
8%
9%      DSERVERBPM('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in DSERVERBPM.M with the given input arguments.
11%
12%      DSERVERBPM('Property','Value',...) creates a new DSERVERBPM or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before DserverBPM_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to DserverBPM_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 DserverBPM
26
27% Last Modified by GUIDE v2.5 05-Sep-2005 16:02:39
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', @DserverBPM_OpeningFcn, ...
34                   'gui_OutputFcn',  @DserverBPM_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 DserverBPM is made visible.
50function DserverBPM_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 DserverBPM (see VARARGIN)
56
57% Choose default command line output for DserverBPM
58handles.output = hObject;
59
60% Update handles structure
61guidata(hObject, handles);
62
63% UIWAIT makes DserverBPM wait for user response (see UIRESUME)
64% uiwait(handles.figure1);
65
66
67% --- Outputs from this function are returned to the command line.
68function varargout = DserverBPM_OutputFcn(hObject, eventdata, handles)
69% varargout  cell array for returning output args (see VARARGOUT);
70% hObject    handle to figure
71% eventdata  reserved - to be defined in a future version of MATLAB
72% handles    structure with handles and user data (see GUIDATA)
73
74% Get default command line output from handles structure
75varargout{1} = handles.output;
76
77
78
79function dev_name_Callback(hObject, eventdata, handles)
80% hObject    handle to dev_name (see GCBO)
81% eventdata  reserved - to be defined in a future version of MATLAB
82% handles    structure with handles and user data (see GUIDATA)
83
84% Hints: get(hObject,'String') returns contents of dev_name as text
85%        str2double(get(hObject,'String')) returns contents of dev_name as a double
86dev=get(handles.dev_name,'String')
87val_dev=get(handles.dev_name,'value')
88mode=tango_read_attribute(dev{val_dev},'Mode');
89set(handles.Current_mode,'String',mode.value);
90
91
92Nvalues=tango_read_attribute(dev{val_dev},'NumSamples');
93set(handles.Nsamples,'String',num2str(Nvalues.value(1)));
94
95% --- Executes during object creation, after setting all properties.
96function dev_name_CreateFcn(hObject, eventdata, handles)
97% hObject    handle to dev_name (see GCBO)
98% eventdata  reserved - to be defined in a future version of MATLAB
99% handles    empty - handles not created until after all CreateFcns called
100
101% Hint: edit controls usually have a white background on Windows.
102%       See ISPC and COMPUTER.
103if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
104    set(hObject,'BackgroundColor','white');
105end
106
107
108
109% --- Executes on button press in pushbutton3.
110function pushbutton3_Callback(hObject, eventdata, handles)
111% hObject    handle to pushbutton3 (see GCBO)
112% eventdata  reserved - to be defined in a future version of MATLAB
113% handles    structure with handles and user data (see GUIDATA)
114
115
116% --- Executes on button press in pushbutton4.
117function pushbutton4_Callback(hObject, eventdata, handles)
118% hObject    handle to pushbutton4 (see GCBO)
119% eventdata  reserved - to be defined in a future version of MATLAB
120% handles    structure with handles and user data (see GUIDATA)
121
122
123
124
125function Nsamples_Callback(hObject, eventdata, handles)
126% hObject    handle to Nsamples (see GCBO)
127% eventdata  reserved - to be defined in a future version of MATLAB
128% handles    structure with handles and user data (see GUIDATA)
129
130% Hints: get(hObject,'String') returns contents of Nsamples as text
131%        str2double(get(hObject,'String')) returns contents of Nsamples as a double
132Nvaleurs=int32(str2num(get(handles.Nsamples,'String')));
133dev=get(handles.dev_name,'String');
134val_dev=get(handles.dev_name,'value');
135tango_write_attribute(dev{val_dev},'NumSamples',Nvaleurs);
136if tango_error==-1
137    tango_print_error_stack;
138    error('Write attribute');
139    return
140end
141   
142%test_erreur_tango;
143argout=tango_read_attribute2(dev{val_dev},'NumSamples');
144%test_erreur_tango;
145if argout.value(1)~=Nvaleurs
146    disp('Le nombre de valeurs demandees n a pas ete mis a jour');
147end
148% --- Executes during object creation, after setting all properties.
149function Nsamples_CreateFcn(hObject, eventdata, handles)
150% hObject    handle to Nsamples (see GCBO)
151% eventdata  reserved - to be defined in a future version of MATLAB
152% handles    empty - handles not created until after all CreateFcns called
153
154% Hint: edit controls usually have a white background on Windows.
155%       See ISPC and COMPUTER.
156if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
157    set(hObject,'BackgroundColor','white');
158end
159
160
161
162% --- Executes on selection change in Change_mode.
163function Change_mode_Callback(hObject, eventdata, handles)
164% hObject    handle to Change_mode (see GCBO)
165% eventdata  reserved - to be defined in a future version of MATLAB
166% handles    structure with handles and user data (see GUIDATA)
167
168% Hints: contents = get(hObject,'String') returns Change_mode contents as cell array
169%        contents{get(hObject,'Value')} returns selected item from Change_mode
170val=get(handles.Change_mode,'Value')
171dev=get(handles.dev_name,'String')
172val_dev=get(handles.dev_name,'value')
173
174switch val
175    case 1
176        tango_write_attribute(dev{val_dev},'Mode','MODE_FT')
177        %test_erreur_tango;
178    case 2
179        tango_write_attribute(dev{val_dev},'Mode','MODE_TT')
180        %test_erreur_tango;
181    case 3
182         tango_write_attribute(dev{val_dev},'Mode','MODE_BN')
183         set(handles.Current_mode,'String','Boo Normal');
184         set(handles.Nsamples,'string',num2str(10169));
185end;
186mode=tango_read_attribute(dev{val_dev},'Mode')
187%test_erreur_tango;
188set(handles.Current_mode,'String',mode.value);
189
190% --- Executes during object creation, after setting all properties.
191function Change_mode_CreateFcn(hObject, eventdata, handles)
192% hObject    handle to Change_mode (see GCBO)
193% eventdata  reserved - to be defined in a future version of MATLAB
194% handles    empty - handles not created until after all CreateFcns called
195
196% Hint: listbox controls usually have a white background on Windows.
197%       See ISPC and COMPUTER.
198if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
199    set(hObject,'BackgroundColor','white');
200end
201
202
203
204function Current_mode_Callback(hObject, eventdata, handles)
205% hObject    handle to Current_mode (see GCBO)
206% eventdata  reserved - to be defined in a future version of MATLAB
207% handles    structure with handles and user data (see GUIDATA)
208
209% Hints: get(hObject,'String') returns contents of Current_mode as text
210%        str2double(get(hObject,'String')) returns contents of Current_mode as a double
211
212
213% --- Executes during object creation, after setting all properties.
214function Current_mode_CreateFcn(hObject, eventdata, handles)
215% hObject    handle to Current_mode (see GCBO)
216% eventdata  reserved - to be defined in a future version of MATLAB
217% handles    empty - handles not created until after all CreateFcns called
218
219% Hint: edit controls usually have a white background on Windows.
220%       See ISPC and COMPUTER.
221if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
222    set(hObject,'BackgroundColor','white');
223end
224
225
226% --- Executes on button press in Get_mode.
227function Get_mode_Callback(hObject, eventdata, handles)
228% hObject    handle to Get_mode (see GCBO)
229% eventdata  reserved - to be defined in a future version of MATLAB
230% handles    structure with handles and user data (see GUIDATA)
231
232dev=get(handles.dev_name,'String')
233val_dev=get(handles.dev_name,'value')
234mode=tango_read_attribute(dev{val_dev},'Mode');
235set(handles.Current_mode,'String',mode.value);
236
237% --- Executes on button press in pushbutton14.
238function Get_data_Callback(hObject, eventdata, handles)
239% hObject    handle to pushbutton14 (see GCBO)
240% eventdata  reserved - to be defined in a future version of MATLAB
241% handles    structure with handles and user data (see GUIDATA)
242global X Z Q Sum Va Vb Vc Vd Stop;
243
244dev=get(handles.dev_name,'String');
245val_dev=get(handles.dev_name,'value');
246
247Nsamples=int32(str2num(get(handles.Nsamples,'String')));
248%tango_write_attribute(dev{val_dev},'NumSamples',Nsamples);
249%test_erreur_tango;
250
251tango_set_timeout(dev{val_dev},30000);
252tango_get_timeout(dev{val_dev});
253Attr_name_list={'XPosVector','ZPosVector','QuadVector','SumVector','VaVector','VbVector','VcVector','VdVector'};
254Stop=0;
255while Stop==0,
256String=get(handles.Moyennage,'String');
257val=get(handles.Moyennage,'Value');
258Moyenne=str2num(String{val})
259val=get(handles.Aquisition_continue,'Value');
260switch val
261    case 0
262        Stop=1;
263    case 1
264        Stop=0;
265end
266argout=tango_read_attributes(dev{val_dev},Attr_name_list);
267%test_erreur_tango;
268X=argout(1).value;
269Z=argout(2).value;
270Q=argout(3).value;
271Sum=argout(4).value;
272Va=argout(5).value;
273Vb=argout(6).value;
274Vc=argout(7).value;
275Vd=argout(8).value;
276
277X_display=0;
278Z_display=0;
279Q_display=0;
280Sum_display=0;
281Va_display=0;
282Vb_display=0;
283Vc_display=0;
284Vd_display=0;
285
286if (Moyenne==1)
287    X_display=X;
288    Z_display=Z;
289    Q_display=Q;
290    Sum_display=Sum;
291    Va_display=Va;
292    Vb_display=Vb;
293    Vc_display=Vc;
294    Vd_display=Vd;
295   
296else
297    for i=1:Moyenne:Nsamples,   
298     X_display=[X_display,mean(X(i:i+Moyenne-1))];
299     Z_display=[Z_display,mean(Z(i:i+Moyenne-1))];
300     Q_display=[Q_display,mean(Q(i:i+Moyenne-1))];
301     Sum_display=[Sum_display,mean(Sum(i:i+Moyenne-1))];
302     Va_display=[Va_display,mean(Va(i:i+Moyenne-1))];
303     Vb_display=[Vb_display,mean(Vb(i:i+Moyenne-1))];
304     Vc_display=[Vc_display,mean(Vc(i:i+Moyenne-1))];
305     Vd_display=[Vd_display,mean(Vd(i:i+Moyenne-1))];
306     
307    end
308    X_display=X_display(2:size(X_display,2));
309    Z_display=Z_display(2:size(Z_display,2));
310    Q_display=Q_display(2:size(Q_display,2));
311    Sum_display=Sum_display(2:size(Sum_display,2));
312    Va_display=Va_display(2:size(Va_display,2));
313    Vb_display=Vb_display(2:size(Vb_display,2));
314    Vc_display=Vc_display(2:size(Vc_display,2));
315    Vd_display=Vd_display(2:size(Vd_display,2));
316   
317end
318
319axes(handles.Graph_X);
320plot(X_display);ylabel('mm');
321title('X');
322set(handles.Graph_X,'YLim',[-5 5]);
323%set(handles.Graph_X,'XLim',[0 200]);
324
325axes(handles.Graph_Z);
326plot(Z_display);
327title('Z');ylabel('mm');
328set(handles.Graph_Z,'YLim',[-5 5]);
329%set(handles.Graph_Z,'XLim',[0 200]);
330
331axes(handles.Graph_Q);
332plot(Q_display);title('Q');ylabel('mm');
333set(handles.Graph_Q,'YLim',[-5 5]);
334%set(handles.Graph_Q,'XLim',[0 200]);
335
336axes(handles.Graph_Somme);
337plot(Sum_display);title('Somme');
338%set(handles.Graph_Somme,'YLim',[0 1.2e9]);
339%set(handles.Graph_Somme,'XLim',[0 200]);
340
341val=get(handles.Display_channels,'Value');
342switch val
343    case 0
344    case 1
345        figure(1)
346        subplot(2,2,1);plot(Va); title('VA');
347        subplot(2,2,2);plot(Vb); title('VB');
348        subplot(2,2,3);plot(Vc); title('VC');
349        subplot(2,2,4);plot(Vd); title('VD');
350end
351       
352
353       
354val=get(handles.Detection,'Value');
355switch val
356    case 0
357    case 1
358        [Max_sum,I]=max(Sum_display)
359        seuil=0.9*Max_sum;
360        indices=find(Sum_display>seuil);
361        figure(2)
362        subplot(2,2,1);plot(indices,X_display(indices)); title('X');
363        valeur=num2str(X_display(indices));
364         legend(valeur);
365        subplot(2,2,2);plot(indices,Z_display(indices)); title('Z');
366        valeur=num2str(Z_display(indices));
367         legend(valeur);
368        subplot(2,2,3);plot(indices,Q_display(indices)); title('Q');
369        subplot(2,2,4);plot(indices,Sum_display(indices)); title('Sum');
370end
371       
372 pause(1);
373end
374         
375
376
377
378
379
380% --- Executes on button press in Display_channels.
381function Display_channels_Callback(hObject, eventdata, handles)
382% hObject    handle to Display_channels (see GCBO)
383% eventdata  reserved - to be defined in a future version of MATLAB
384% handles    structure with handles and user data (see GUIDATA)
385
386% Hint: get(hObject,'Value') returns toggle state of Display_channels
387global Va Vb Vc Vd;
388val=get(handles.Display_channels,'Value');
389switch val
390    case 0
391    case 1
392        figure(1)
393        subplot(2,2,1);plot(Va); title('VA');
394        subplot(2,2,2);plot(Vb); title('VB');
395        subplot(2,2,3);plot(Vc); title('VC');
396        subplot(2,2,4);plot(Vd); title('VD');
397end
398
399
400
401% --- Executes on selection change in Moyennage.
402function Moyennage_Callback(hObject, eventdata, handles)
403% hObject    handle to Moyennage (see GCBO)
404% eventdata  reserved - to be defined in a future version of MATLAB
405% handles    structure with handles and user data (see GUIDATA)
406
407% Hints: contents = get(hObject,'String') returns Moyennage contents as cell array
408%        contents{get(hObject,'Value')} returns selected item from Moyennage
409global X Z Q Sum Va Vb Vc Vd;
410Nsamples=str2num(get(handles.Nsamples,'String'));
411String=get(handles.Moyennage,'String');
412val=get(handles.Moyennage,'Value');
413Moyenne=str2num(String{val})
414
415hX=get(handles.Graph_X,'children');
416hZ=get(handles.Graph_Z,'children');
417hQ=get(handles.Graph_Q,'children');
418hSum=get(handles.Graph_Somme,'children');
419
420   
421X_display=0;
422Z_display=0;
423Q_display=0;
424Sum_display=0;
425Va_display=0;
426Vb_display=0;
427Vc_display=0;
428Vd_display=0;
429
430if (Moyenne==1)
431    X_display=X;
432    Z_display=Z;
433    Q_display=Q;
434    Sum_display=Sum;
435    Va_display=Va;
436    Vb_display=Vb;
437    Vc_display=Vc;
438    Vd_display=Vd;
439else
440    for i=1:Moyenne:Nsamples,   
441        X_display=[X_display,mean(X(i:i+Moyenne-1))];
442        Z_display=[Z_display,mean(Z(i:i+Moyenne-1))];
443        Q_display=[Q_display,mean(Q(i:i+Moyenne-1))];
444        Sum_display=[Sum_display,mean(Sum(i:i+Moyenne-1))];
445        Va_display=[Va_display,mean(Va(i:i+Moyenne-1))];
446        Vb_display=[Vb_display,mean(Vb(i:i+Moyenne-1))];
447        Vc_display=[Vc_display,mean(Vc(i:i+Moyenne-1))];
448        Vd_display=[Vd_display,mean(Vd(i:i+Moyenne-1))];
449    end
450    X_display=X_display(2:size(X_display,2));
451    Z_display=Z_display(2:size(Z_display,2));
452    Q_display=Q_display(2:size(Q_display,2));
453    Sum_display=Sum_display(2:size(Sum_display,2));
454    Va_display=Va_display(2:size(Va_display,2));
455    Vb_display=Vb_display(2:size(Vb_display,2));
456    Vc_display=Vc_display(2:size(Vc_display,2));
457    Vd_display=Vd_display(2:size(Vd_display,2));
458
459end
460
461set(hX,'YData',X_display);
462set(hZ,'YData',Z_display);
463set(hQ,'YData',Q_display);
464set(hSum,'YData',Sum_display);
465val=get(handles.Display_channels,'Value');
466switch val
467    case 0
468    case 1
469        figure(1)
470        subplot(2,2,1);plot(Va_display); title('VA');
471        subplot(2,2,2);plot(Vb_display); title('VB');
472        subplot(2,2,3);plot(Vc_display); title('VC');
473        subplot(2,2,4);plot(Vd_display); title('VD');
474end
475
476% --- Executes during object creation, after setting all properties.
477function Moyennage_CreateFcn(hObject, eventdata, handles)
478% hObject    handle to Moyennage (see GCBO)
479% eventdata  reserved - to be defined in a future version of MATLAB
480% handles    empty - handles not created until after all CreateFcns called
481
482% Hint: popupmenu controls usually have a white background on Windows.
483%       See ISPC and COMPUTER.
484if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
485    set(hObject,'BackgroundColor','white');
486end
487
488
489
490
491% --- Executes on button press in Stop.
492function Stop_Callback(hObject, eventdata, handles)
493% hObject    handle to Stop (see GCBO)
494% eventdata  reserved - to be defined in a future version of MATLAB
495% handles    structure with handles and user data (see GUIDATA)
496global Stop;
497Stop=1;
498
499
500
501% --- Executes on button press in Aquisition_continue.
502function Aquisition_continue_Callback(hObject, eventdata, handles)
503% hObject    handle to Aquisition_continue (see GCBO)
504% eventdata  reserved - to be defined in a future version of MATLAB
505% handles    structure with handles and user data (see GUIDATA)
506
507% Hint: get(hObject,'Value') returns toggle state of Aquisition_continue
508
509
510
511
512
513function Filename_Callback(hObject, eventdata, handles)
514% hObject    handle to Filename (see GCBO)
515% eventdata  reserved - to be defined in a future version of MATLAB
516% handles    structure with handles and user data (see GUIDATA)
517
518% Hints: get(hObject,'String') returns contents of Filename as text
519%        str2double(get(hObject,'String')) returns contents of Filename as a double
520
521
522% --- Executes during object creation, after setting all properties.
523function Filename_CreateFcn(hObject, eventdata, handles)
524% hObject    handle to Filename (see GCBO)
525% eventdata  reserved - to be defined in a future version of MATLAB
526% handles    empty - handles not created until after all CreateFcns called
527
528% Hint: edit controls usually have a white background on Windows.
529%       See ISPC and COMPUTER.
530if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
531    set(hObject,'BackgroundColor','white');
532end
533
534
535% --- Executes on button press in Save.
536function Save_Callback(hObject, eventdata, handles)
537% hObject    handle to Save (see GCBO)
538% eventdata  reserved - to be defined in a future version of MATLAB
539% handles    structure with handles and user data (see GUIDATA)
540global X Z Q Sum Va Vb Vc Vd;
541Nsamples=str2num(get(handles.Nsamples,'String'));
542dev=get(handles.dev_name,'String');
543val_dev=get(handles.dev_name,'value');
544mode=tango_read_attribute(dev{val_dev},'Mode');
545filename=get(handles.Filename,'String')
546%filepath=['c:\testni\ESRF\',filename]
547save(filename,'Nsamples','mode','X','Z','Q','Sum','Va','Vb','Vc','Vd');
548
549
550% --- Executes on button press in Detection.
551function Detection_Callback(hObject, eventdata, handles)
552% hObject    handle to Detection (see GCBO)
553% eventdata  reserved - to be defined in a future version of MATLAB
554% handles    structure with handles and user data (see GUIDATA)
555
556% Hint: get(hObject,'Value') returns toggle state of Detection
557
558
Note: See TracBrowser for help on using the repository browser.