source: MML/trunk/machine/SOLEIL/common/database/tango_staticdb_config.m @ 4

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

Initial import--MML version from SOLEIL@2013

File size: 34.9 KB
Line 
1function varargout = tango_staticdb_config(varargin)
2% TANGO_STATICDB_EDITOR M-file for tango_staticdb_config.fig
3%      TANGO_STATICDB_EDITOR, by itself, creates a new TANGO_STATICDB_EDITOR or raises the existing
4%      singleton*.
5%
6%      H = TANGO_STATICDB_EDITOR returns the handle to a new TANGO_STATICDB_EDITOR or the handle to
7%      the existing singleton*.
8%
9%      TANGO_STATICDB_EDITOR('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in TANGO_STATICDB_EDITOR.M with the given input arguments.
11%
12%      TANGO_STATICDB_EDITOR('Property','Value',...) creates a new TANGO_STATICDB_EDITOR or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before tango_staticdb_config_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to tango_staticdb_config_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 tango_staticdb_config
26
27% Last Modified by GUIDE v2.5 24-Mar-2006 11:54:22
28
29% Laurent S. Nadolski, SOLEIL
30
31% Begin initialization code - DO NOT EDIT
32gui_Singleton = 1;
33gui_State = struct('gui_Name',       mfilename, ...
34    'gui_Singleton',  gui_Singleton, ...
35    'gui_OpeningFcn', @tango_staticdb_config_OpeningFcn, ...
36    'gui_OutputFcn',  @tango_staticdb_config_OutputFcn, ...
37    'gui_LayoutFcn',  [] , ...
38    'gui_Callback',   []);
39if nargin && ischar(varargin{1})
40    gui_State.gui_Callback = str2func(varargin{1});
41end
42
43if nargout
44    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
45else
46    gui_mainfcn(gui_State, varargin{:});
47end
48% End initialization code - DO NOT EDIT
49
50
51% --- Executes just before tango_staticdb_config is made visible.
52function tango_staticdb_config_OpeningFcn(hObject, eventdata, handles, varargin)
53% This function has no output args, see OutputFcn.
54% hObject    handle to figure
55% eventdata  reserved - to be defined in a future version of MATLAB
56% handles    structure with handles and user data (see GUIDATA)
57% varargin   command line arguments to tango_staticdb_config (see VARARGIN)
58
59% Choose default command line output for tango_staticdb_config
60handles.output = hObject;
61
62% Update handles structure
63guidata(hObject, handles);
64
65% UIWAIT makes tango_staticdb_config wait for user response (see UIRESUME)
66% uiwait(handles.figure1);
67
68disp('TANGO Static DataBase Configurator');
69
70set(handles.figure1,'HandleVisibility','Callback');
71set(handles.listbox_log, 'String',{[datestr(now) ': application started'], ' '});
72
73% uimenu_anneau_Callback(handles.uimenu_LT1, eventdata, handles);
74%uimenu_LT1_Callback(handles.uimenu_LT1, eventdata, handles);
75% Update handles structure
76guidata(hObject, handles);
77
78% --- Outputs from this function are returned to the command line.
79function varargout = tango_staticdb_config_OutputFcn(hObject, eventdata, handles)
80% varargout  cell array for returning output args (see VARARGOUT);
81% hObject    handle to figure
82% eventdata  reserved - to be defined in a future version of MATLAB
83% handles    structure with handles and user data (see GUIDATA)
84
85% Get default command line output from handles structure
86varargout{1} = handles.output;
87
88
89% --- Executes on selection change in popupmenu_group.
90function popupmenu_group_Callback(hObject, eventdata, handles)
91% hObject    handle to popupmenu_group (see GCBO)
92% eventdata  reserved - to be defined in a future version of MATLAB
93% handles    structure with handles and user data (see GUIDATA)
94
95% Hints: contents = get(hObject,'String') returns popupmenu_group contents as cell array
96%        contents{get(hObject,'Value')} returns selected item from popupmenu_group
97
98contents = get(hObject,'String');
99num      = get(hObject,'Value');
100family   = contents{num};
101
102AO = getfamilydata(family);
103setappdata(handles.figure1,'AO',AO);
104setappdata(handles.figure1, 'Family', family);
105
106%% Status one devices
107valid  = find(AO.Status);
108%% Builds up attribut list for selected family
109if ~iscell(AO.DeviceName)
110    AO.DeviceName = {AO.DeviceName};
111end
112
113attributeList = tango_get_attribute_list(AO.DeviceName{valid(1)});
114
115if isnumeric(attributeList) &&  attributeList == -1
116    error('Cannot communicate with device %s',AO.DeviceName{valid(1)})
117end
118
119num = get(handles.popupmenu_attribute,'Value');
120if num > length(attributeList)
121    num = 1;
122    set(handles.popupmenu_attribute,'Value',num);
123end
124set(handles.popupmenu_attribute,'String',attributeList);
125
126%setback selected elements and property to first one
127set(handles.listbox_property,'Value',1);
128set(handles.listbox_group,'Value',1);
129set(handles.listbox_dev_property,'Value',1);
130
131popupmenu_attribute_Callback(handles.popupmenu_attribute, eventdata, handles);
132
133%% Build up command list
134% popupmenu_group_Callback(handles.popupmenu_attribute, eventdata, handles);
135
136commandList = tango_command_list_query(AO.DeviceName{valid(1)});
137
138num = get(handles.popupmenu_command,'Value');
139if num > length(attributeList)
140    num = 1;
141    set(handles.popupmenu_command,'Value',num);
142end
143
144% trick for getting a field array from a cell array
145commandOutputType = eval(['{commandList.', 'out_type}']);
146commandInputType  = eval(['{commandList.', 'in_type}']);
147setappdata(handles.figure1,'cmd_output_type',commandOutputType);
148setappdata(handles.figure1,'cmd_input_type',commandInputType);
149commandList = eval(['{commandList.', 'cmd_name}']);
150
151set(handles.popupmenu_command,'String',commandList);
152
153%% Build up a NaN attribute value pannel
154set(handles.listbox_attribute,'String', repmat('NaN',size(AO.DeviceName)));
155set(handles.listbox_dev_property,'String', repmat('NaN',size(AO.DeviceName)));
156
157%% Build up device property device list
158devPropList = tango_command_list_query(AO.DeviceName{valid(1)});
159
160% Update handles structure
161guidata(hObject, handles);
162
163% --- Executes during object creation, after setting all properties.
164function popupmenu_group_CreateFcn(hObject, eventdata, handles)
165% hObject    handle to popupmenu_group (see GCBO)
166% eventdata  reserved - to be defined in a future version of MATLAB
167% handles    empty - handles not created until after all CreateFcns called
168
169% Hint: popupmenu controls usually have a white background on Windows.
170%       See ISPC and COMPUTER.
171if ispc
172    set(hObject,'BackgroundColor','white');
173else
174    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
175end
176
177
178% --- Executes on selection change in popupmenu_attribute.
179function popupmenu_attribute_Callback(hObject, eventdata, handles)
180% hObject    handle to popupmenu_attribute (see GCBO)
181% eventdata  reserved - to be defined in a future version of MATLAB
182% handles    structure with handles and user data (see GUIDATA)
183
184% Hints: contents = get(hObject,'String') returns popupmenu_attribute contents as cell array
185%        contents{get(hObject,'Value')} returns selected item from popupmenu_attribute
186
187contents  = get(hObject,'String');
188num       = get(hObject,'Value');
189attribute = contents{num};
190
191family     = getappdata(handles.figure1,'Family');
192AO         = getappdata(handles.figure1,'AO');
193
194%% Selects valid devices
195valid  = find(AO.Status);
196%% Builds up property list for selected family
197
198if ~iscell(AO.DeviceName)
199    AO.DeviceName = cellstr(AO.DeviceName);
200end
201   
202propertyList = fieldnames(tango_attribute_query(AO.DeviceName{valid(1)}, attribute));
203
204num = get(hObject,'Value');
205if num > length(propertyList)
206    num = 1;
207    set(handles.popupmenu_property,'Value',num);
208end
209set(handles.popupmenu_property,'String',propertyList);
210
211% Reset to first item in selection list
212set(handles.listbox_property,'Value',1);
213set(handles.listbox_group,'Value',1);
214set(handles.listbox_attribute,'Value',1);
215
216popupmenu_property_Callback(handles.popupmenu_property, eventdata, handles);
217
218%set(handles.radiobutton_property,'Value',1);
219
220% Update handles structure
221guidata(hObject, handles);
222
223% --- Executes during object creation, after setting all properties.
224function popupmenu_attribute_CreateFcn(hObject, eventdata, handles)
225% hObject    handle to popupmenu_attribute (see GCBO)
226% eventdata  reserved - to be defined in a future version of MATLAB
227% handles    empty - handles not created until after all CreateFcns called
228
229% Hint: popupmenu controls usually have a white background on Windows.
230%       See ISPC and COMPUTER.
231if ispc
232    set(hObject,'BackgroundColor','white');
233else
234    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
235end
236
237
238% --- Executes on selection change in popupmenu_property.
239function popupmenu_property_Callback(hObject, eventdata, handles)
240% hObject    handle to popupmenu_property (see GCBO)
241% eventdata  reserved - to be defined in a future version of MATLAB
242% handles    structure with handles and user data (see GUIDATA)
243
244% Hints: contents = get(hObject,'String') returns popupmenu_property contents as cell array
245%        contents{get(hObject,'Value')} returns selected item from popupmenu_property
246
247contents  = get(hObject,'String');
248num       = get(hObject,'Value');
249property  = contents{num};
250
251attribute  = get(handles.popupmenu_attribute,'String');
252iattribute = get(handles.popupmenu_attribute,'Value');
253AO         = getappdata(handles.figure1,'AO');
254
255
256% Status one devices
257valid  = find(AO.Status);
258
259% Update Group list
260
261if ~iscell(AO.DeviceName)
262    AO.DeviceName = {AO.DeviceName};
263end
264
265set(handles.listbox_group,'String',AO.DeviceName(valid));
266
267% Contruct DeviceName/AttributName list
268fullTangoNames = strcat(AO.DeviceName(valid), '/', attribute{iattribute});
269
270% Builds up property list
271list = tango_get_attribute_property(fullTangoNames, property);
272set(handles.listbox_property,'String',list);
273% Reset to first item in selection list
274set(handles.listbox_property,'Value',1);
275set(handles.listbox_group,'Value',1);
276set(handles.listbox_attribute,'Value',1);
277set(handles.checkbox_all,'Value',0);
278
279writelog(['Values for property ''' char(property) ''' refreshed'],handles);
280
281%popupmenu_command_Callback(handles.popupmenu_property, eventdata, handles);
282
283% Update handles structure
284guidata(hObject, handles);
285
286% --- Executes during object creation, after setting all properties.
287function popupmenu_property_CreateFcn(hObject, eventdata, handles)
288% hObject    handle to popupmenu_property (see GCBO)
289% eventdata  reserved - to be defined in a future version of MATLAB
290% handles    empty - handles not created until after all CreateFcns called
291
292% Hint: popupmenu controls usually have a white background on Windows.
293%       See ISPC and COMPUTER.
294if ispc
295    set(hObject,'BackgroundColor','white');
296else
297    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
298end
299
300% --- Executes on selection change in listbox_group.
301function listbox_group_Callback(hObject, eventdata, handles)
302% hObject    handle to listbox_group (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% Hints: contents = get(hObject,'String') returns listbox_group contents as cell array
307%        contents{get(hObject,'Value')} returns selected item from listbox_group
308
309idx = get(hObject,'Value');
310
311set(handles.listbox_attribute,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
312set(handles.listbox_property,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
313set(handles.listbox_dev_property,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
314set(handles.checkbox_all,'Value',0);
315
316% --- Executes during object creation, after setting all properties.
317function listbox_group_CreateFcn(hObject, eventdata, handles)
318% hObject    handle to listbox_group (see GCBO)
319% eventdata  reserved - to be defined in a future version of MATLAB
320% handles    empty - handles not created until after all CreateFcns called
321
322% Hint: listbox controls usually have a white background on Windows.
323%       See ISPC and COMPUTER.
324if ispc
325    set(hObject,'BackgroundColor','white');
326else
327    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
328end
329
330
331% --- Executes on selection change in listbox_property.
332function listbox_property_Callback(hObject, eventdata, handles)
333% hObject    handle to listbox_property (see GCBO)
334% eventdata  reserved - to be defined in a future version of MATLAB
335% handles    structure with handles and user data (see GUIDATA)
336
337% Hints: contents = get(hObject,'String') returns listbox_property contents as cell array
338%        contents{get(hObject,'Value')} returns selected item from listbox_property
339
340contents = get(hObject,'String');
341idx = get(hObject,'Value');
342
343set(handles.listbox_group,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
344set(handles.listbox_attribute,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
345set(handles.listbox_dev_property,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
346set(handles.checkbox_all,'Value',0);
347
348set(handles.edit_value,'String',contents{idx(1)});
349
350%select radiobutton
351set(handles.radiobutton_property,'Value',1);
352
353% --- Executes during object creation, after setting all properties.
354function listbox_property_CreateFcn(hObject, eventdata, handles)
355% hObject    handle to listbox_property (see GCBO)
356% eventdata  reserved - to be defined in a future version of MATLAB
357% handles    empty - handles not created until after all CreateFcns called
358
359% Hint: listbox controls usually have a white background on Windows.
360%       See ISPC and COMPUTER.
361if ispc
362    set(hObject,'BackgroundColor','white');
363else
364    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
365end
366
367
368% --- Executes on button press in checkbox_all.
369function checkbox_all_Callback(hObject, eventdata, handles)
370% hObject    handle to checkbox_all (see GCBO)
371% eventdata  reserved - to be defined in a future version of MATLAB
372% handles    structure with handles and user data (see GUIDATA)
373
374% Hint: get(hObject,'Value') returns toggle state of checkbox_all
375val = get(handles.listbox_group,'String');
376
377if get(hObject,'Value') == 1
378    set(handles.listbox_group,'Value',1:length(val));
379    set(handles.listbox_attribute,'Value',1:length(val));
380    set(handles.listbox_property,'Value',1:length(val));
381    set(handles.listbox_dev_property,'Value',1:length(val));
382    set(handles.listbox_group,'listboxtop',1);
383    set(handles.listbox_attribute,'listboxtop',1);
384    set(handles.listbox_property,'listboxtop',1);
385    set(handles.listbox_dev_property,'listboxtop',1);
386end
387
388function edit_value_Callback(hObject, eventdata, handles)
389% hObject    handle to edit_value (see GCBO)
390% eventdata  reserved - to be defined in a future version of MATLAB
391% handles    structure with handles and user data (see GUIDATA)
392
393% Hints: get(hObject,'String') returns contents of edit_value as text
394%        str2double(get(hObject,'String')) returns contents of edit_value as a double
395
396% First of all, ask for confirmation
397answer = questdlg('Do you want to apply change ?','Confirmation dialog box');
398
399switch answer
400    case 'Yes'
401
402        % Get the new value
403        % Need to force char array
404        value = char(get(hObject,'String'));       
405
406        attribute  = get(handles.popupmenu_attribute,'String');
407        iattribute = get(handles.popupmenu_attribute,'Value');
408        property   = get(handles.popupmenu_property,'String');
409        iproperty  = get(handles.popupmenu_property,'Value');       
410        iSelected  = get(handles.listbox_group,'Value');
411        Family     = getappdata(handles.figure1, 'Family');
412        DeviceName = family2tangodev(Family);
413
414        switch get(handles.radiobutton_property,'Value')
415
416            case 1 % property change
417
418                %% Get selected element               
419                writelog(['Please wait: writting property ' property{iproperty}  '...'], handles);
420               
421                tango_set_attribute_property(strcat(DeviceName(iSelected), ...
422                    '/',attribute{iattribute}),property{iproperty}, value)
423               
424                writelog('Properties written', handles);
425               
426                % refresh display
427                popupmenu_property_Callback(handles.popupmenu_property,eventdata, handles);
428
429            case 0 %attribute change
430                                               
431               writelog(['Please wait: writting attributes ', attribute{iattribute}, '  ...'], handles);
432 
433               value = repmat(value,size(DeviceName(iSelected),1),1);
434               writeattribute(strcat(DeviceName(iSelected), ...
435                   '/',attribute{iattribute}), value, 'QueryDB');
436
437               writelog('Attributes written', handles);
438
439                % refresh display
440                pushbutton_refresh_Callback(handles.pushbutton_refresh,eventdata, handles);
441        end
442    case {'No','Cancel'}
443        return;
444    otherwise
445        warning('Wrong answer')
446end
447
448
449
450
451% --- Executes during object creation, after setting all properties.
452function edit_value_CreateFcn(hObject, eventdata, handles)
453% hObject    handle to edit_value (see GCBO)
454% eventdata  reserved - to be defined in a future version of MATLAB
455% handles    empty - handles not created until after all CreateFcns called
456
457% Hint: edit controls usually have a white background on Windows.
458%       See ISPC and COMPUTER.
459if ispc
460    set(hObject,'BackgroundColor','white');
461else
462    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
463end
464
465
466% --------------------------------------------------------------------
467function uimenu_linac_Callback(hObject, eventdata, handles)
468% hObject    handle to uimenu_linac (see GCBO)
469% eventdata  reserved - to be defined in a future version of MATLAB
470% handles    structure with handles and user data (see GUIDATA)
471
472init_uimenu(hObject, eventdata, handles);
473
474% -------------------------------------------------------------------------
475function uimenu_LT1_Callback(hObject, eventdata, handles)
476% hObject    handle to uimenu_LT1 (see GCBO)
477% eventdata  reserved - to be defined in a future version of MATLAB
478% handles    structure with handles and user data (see GUIDATA)
479
480AD = getad;
481
482if isempty(AD)
483    LT1init;
484elseif ~strcmpi(AD.Machine,'LT1')
485    LT1init;
486end
487
488writelog('LT1 loaded',handles);
489handles = init_uimenu(hObject, eventdata, handles);
490% Update handles structure
491guidata(hObject, handles);
492
493% -------------------------------------------------------------------------
494function handles = init_uimenu(hObject, eventdata, handles)
495
496%% Checked box
497all = findobj(get(hObject,'Parent'),'Type','UImenu');
498set(all, 'Checked', 'Off');
499set(hObject, 'Checked', 'On');
500
501%% Initialize popupmenu w/ first element, first attribute, first property
502listfamily = fieldnames(getfamilydata);
503set(handles.popupmenu_group,'String',listfamily);
504
505popupmenu_group_Callback(handles.popupmenu_group, eventdata, handles);
506
507% --------------------------------------------------------------------
508function uimenu_booster_Callback(hObject, eventdata, handles)
509% hObject    handle to uimenu_booster (see GCBO)
510% eventdata  reserved - to be defined in a future version of MATLAB
511% handles    structure with handles and user data (see GUIDATA)
512
513AD = getad;
514
515if isempty(AD)
516    boosterinit;
517elseif ~strcmpi(AD.Machine,'Booster')
518    boosterinit
519end
520
521writelog('Booster loaded',handles);
522init_uimenu(hObject, eventdata, handles);
523
524% --------------------------------------------------------------------
525function uimenu_LT2_Callback(hObject, eventdata, handles)
526% hObject    handle to uimenu_LT2 (see GCBO)
527% eventdata  reserved - to be defined in a future version of MATLAB
528% handles    structure with handles and user data (see GUIDATA)
529
530AD = getad;
531
532if isempty(AD)
533    LT2init
534elseif ~strcmpi(AD.Machine,'LT2')
535    LT2init;
536end
537
538writelog('LT2 loaded',handles);
539
540init_uimenu(hObject, eventdata, handles);
541
542% --------------------------------------------------------------------
543function uimenu_anneau_Callback(hObject, eventdata, handles)
544% hObject    handle to uimenu_anneau (see GCBO)
545% eventdata  reserved - to be defined in a future version of MATLAB
546% handles    structure with handles and user data (see GUIDATA)
547
548machineName = getsubmachinename;
549
550if isempty(machineName)
551    soleilinit;
552elseif ~strcmpi(machineName,'StorageRing')
553    soleilinit
554end
555
556writelog('Ring loaded',handles);
557
558init_uimenu(hObject, eventdata, handles);
559
560% --- Executes on selection change in listbox_attribute.
561function listbox_attribute_Callback(hObject, eventdata, handles)
562% hObject    handle to listbox_attribute (see GCBO)
563% eventdata  reserved - to be defined in a future version of MATLAB
564% handles    structure with handles and user data (see GUIDATA)
565
566% Hints: contents = get(hObject,'String') returns listbox_attribute contents as cell array
567%        contents{get(hObject,'Value')} returns selected item from listbox_attribute
568
569contents = get(hObject,'String');
570idx = get(hObject,'Value');
571set(handles.listbox_group,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
572set(handles.listbox_property,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
573set(handles.listbox_dev_property,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
574set(handles.checkbox_all,'Value',0);
575
576% Selected only first element
577% If all elements are numeric, return a char array and not a cell!
578if ischar(contents)
579    contents = cellstr(contents);
580end
581set(handles.edit_value,'String',contents{idx(1)});
582
583%select radiobutton
584set(handles.radiobutton_attribute,'Value',1);
585
586% --- Executes during object creation, after setting all properties.
587function listbox_attribute_CreateFcn(hObject, eventdata, handles)
588% hObject    handle to listbox_attribute (see GCBO)
589% eventdata  reserved - to be defined in a future version of MATLAB
590% handles    empty - handles not created until after all CreateFcns called
591
592% Hint: listbox controls usually have a white background on Windows.
593%       See ISPC and COMPUTER.
594if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
595    set(hObject,'BackgroundColor','white');
596end
597
598
599% --- Executes on selection change in popupmenu_command.
600function popupmenu_command_Callback(hObject, eventdata, handles)
601% hObject    handle to popupmenu_command (see GCBO)
602% eventdata  reserved - to be defined in a future version of MATLAB
603% handles    structure with handles and user data (see GUIDATA)
604
605% Hints: contents = get(hObject,'String') returns popupmenu_command contents as cell array
606%        contents{get(hObject,'Value')} returns selected item from popupmenu_command
607
608contents  = get(hObject,'String');
609num       = get(hObject,'Value');
610command  = contents{num};
611
612setappdata(handles.figure1,'command', command);
613
614% --- Executes during object creation, after setting all properties.
615function popupmenu_command_CreateFcn(hObject, eventdata, handles)
616% hObject    handle to popupmenu_command (see GCBO)
617% eventdata  reserved - to be defined in a future version of MATLAB
618% handles    empty - handles not created until after all CreateFcns called
619
620% Hint: popupmenu controls usually have a white background on Windows.
621%       See ISPC and COMPUTER.
622if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
623    set(hObject,'BackgroundColor','white');
624end
625
626
627% --- Executes on button press in pushbutton_apply.
628function pushbutton_apply_Callback(hObject, eventdata, handles)
629% hObject    handle to pushbutton_apply (see GCBO)
630% eventdata  reserved - to be defined in a future version of MATLAB
631% handles    structure with handles and user data (see GUIDATA)
632
633% Apply command
634
635answer = questdlg('Do you want to apply change ?','Confirmation dialog box');
636
637switch answer
638    case 'Yes'
639        % get selected device
640        iSelected = get(handles.listbox_group,'Value');
641
642        Family = getappdata(handles.figure1, 'Family');
643        DeviceName = family2tangodev(Family);
644
645        if isempty(iSelected)
646            writelog('Non device names selected or status 0',handles);
647            return;
648        end
649
650        valS = repmat('NaN',size(DeviceName));
651        val = cellstr(valS);
652        %get selected command
653        icmd    = get(handles.popupmenu_command,'Value');
654        cmdlist = get(handles.popupmenu_command,'String');
655        command = cmdlist{icmd};
656       
657        writelog(['Applying command: ' command], handles);
658        set(handles.listbox_attribute,'String',val);
659       
660        commandOutputType = getappdata(handles.figure1,'cmd_output_type');
661        commandOutputType = commandOutputType{icmd};
662        commandInputType  = getappdata(handles.figure1,'cmd_input_type');
663        commandInputType  = commandInputType{icmd};
664
665        switch commandOutputType
666            case {'1-by-n char'}       
667                for k = 1:length(iSelected),
668                    val0 = tango_command_inout2(DeviceName{iSelected(k)},command);
669                    val{iSelected(k)} = val0;
670                end
671                set(handles.listbox_attribute,'String',val);
672            otherwise % not output command
673                for k=1:length(iSelected),
674                    tango_command_inout2(DeviceName{iSelected(k)},command);
675                end
676        end
677        writelog('Command applied', handles);
678    case {'No','Cancel'}
679        return;
680    otherwise
681        warning('Wrong answer')
682end
683
684
685% --- Executes on button press in pushbutton_refresh.
686function pushbutton_refresh_Callback(hObject, eventdata, handles)
687% hObject    handle to pushbutton_refresh (see GCBO)
688% eventdata  reserved - to be defined in a future version of MATLAB
689% handles    structure with handles and user data (see GUIDATA)
690
691% attributes
692% refresh ALL
693ifamily = get(handles.popupmenu_group,'Value');
694family = get(handles.popupmenu_group,'String');
695
696Family = family{ifamily};
697DeviceName = family2tangodev(Family);
698
699if isempty(Family)
700    writelog('No machine loaded!',handles);
701    return
702end
703
704iattribute = get(handles.popupmenu_attribute,'Value');
705attribute  = get(handles.popupmenu_attribute,'String');
706iSelected  = get(handles.listbox_group,'Value');
707
708val  = ones(size(DeviceName))*NaN';
709valS = repmat('NaN',size(DeviceName));
710%val0 = readattribute(strcat(DeviceName,'/',char(attribute(iattribute))));
711val0 = readattribute(strcat(DeviceName(iSelected),'/',char(attribute(iattribute))));
712
713if iscellstr(val0) % See timestamp for MON as an example
714    val = cellstr(valS);
715    val(iSelected,:) = val0;
716else
717    val(iSelected) = val0;
718end
719
720% % update listbox
721 set(handles.listbox_attribute,'String',val);
722% % update editbox     
723% set(handles.edit_value,'String',val(1));
724% set(handles.listbox_attribute,'Value',1);
725% set(handles.listbox_group,'Value',1);
726% set(handles.listbox_dev_property,'Value',1);
727% set(handles.listbox_property,'Value',1);
728% % uncheck buttons
729% set(handles.checkbox_all,'Value', 0);
730
731writelog(['Values for attribute ''' char(attribute(iattribute)) ''' refreshed'],handles);
732
733% --- Executes on selection change in listbox_log.
734function listbox_log_Callback(hObject, eventdata, handles)
735% hObject    handle to listbox_log (see GCBO)
736% eventdata  reserved - to be defined in a future version of MATLAB
737% handles    structure with handles and user data (see GUIDATA)
738
739% Hints: contents = get(hObject,'String') returns listbox_log contents as cell array
740%        contents{get(hObject,'Value')} returns selected item from listbox_log
741
742
743% --- Executes during object creation, after setting all properties.
744function listbox_log_CreateFcn(hObject, eventdata, handles)
745% hObject    handle to listbox_log (see GCBO)
746% eventdata  reserved - to be defined in a future version of MATLAB
747% handles    empty - handles not created until after all CreateFcns called
748
749% Hint: listbox controls usually have a white background on Windows.
750%       See ISPC and COMPUTER.
751if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
752    set(hObject,'BackgroundColor','white');
753end
754
755
756function writelog(strvalue, handles)
757% Add stuff in the logging window
758
759str = get(handles.listbox_log, 'String');
760str = {str{:} [datestr(now) ': ' strvalue]};
761% update logging window
762set(handles.listbox_log, 'String',str,'ListBoxTop',length(str));
763
764
765% --- Executes on selection change in listbox_dev_property.
766function listbox_dev_property_Callback(hObject, eventdata, handles)
767% hObject    handle to listbox_dev_property (see GCBO)
768% eventdata  reserved - to be defined in a future version of MATLAB
769% handles    structure with handles and user data (see GUIDATA)
770
771% Hints: contents = get(hObject,'String') returns listbox_dev_property contents as cell array
772%        contents{get(hObject,'Value')} returns selected item from listbox_dev_property
773contents = get(hObject,'String');
774idx = get(hObject,'Value');
775
776set(handles.listbox_group,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
777set(handles.listbox_attribute,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
778set(handles.listbox_property,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
779set(handles.listbox_dev_property,'Value',idx,'ListBoxTop',get(hObject,'ListboxTop'));
780set(handles.checkbox_all,'Value',0);
781
782set(handles.edit_value,'String',contents{idx(1)});
783
784
785% --- Executes during object creation, after setting all properties.
786function listbox_dev_property_CreateFcn(hObject, eventdata, handles)
787% hObject    handle to listbox_dev_property (see GCBO)
788% eventdata  reserved - to be defined in a future version of MATLAB
789% handles    empty - handles not created until after all CreateFcns called
790
791% Hint: listbox controls usually have a white background on Windows.
792%       See ISPC and COMPUTER.
793if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
794    set(hObject,'BackgroundColor','white');
795end
796
797
798% --- Executes on selection change in popupmenu_dev_prop.
799function popupmenu_dev_prop_Callback(hObject, eventdata, handles)
800% hObject    handle to popupmenu_dev_prop (see GCBO)
801% eventdata  reserved - to be defined in a future version of MATLAB
802% handles    structure with handles and user data (see GUIDATA)
803
804% Hints: contents = get(hObject,'String') returns popupmenu_dev_prop contents as cell array
805%        contents{get(hObject,'Value')} returns selected item from popupmenu_dev_prop
806contents  = get(hObject,'String');
807num       = get(hObject,'Value');
808devproperty  = contents{num};
809
810setappdata(handles.figure1,'devproperty', devproperty);
811
812
813% --- Executes during object creation, after setting all properties.
814function popupmenu_dev_prop_CreateFcn(hObject, eventdata, handles)
815% hObject    handle to popupmenu_dev_prop (see GCBO)
816% eventdata  reserved - to be defined in a future version of MATLAB
817% handles    empty - handles not created until after all CreateFcns called
818
819% Hint: popupmenu controls usually have a white background on Windows.
820%       See ISPC and COMPUTER.
821if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
822    set(hObject,'BackgroundColor','white');
823end
824
825
826
827function edit_dev_propvalue_Callback(hObject, eventdata, handles)
828% hObject    handle to edit_dev_propvalue (see GCBO)
829% eventdata  reserved - to be defined in a future version of MATLAB
830% handles    structure with handles and user data (see GUIDATA)
831
832% Hints: get(hObject,'String') returns contents of edit_dev_propvalue as text
833%        str2double(get(hObject,'String')) returns contents of edit_dev_propvalue as a double
834% First of all, ask for confirmation
835answer = questdlg('Do you want to apply change ?','Confirmation dialog box');
836
837switch answer
838    case 'Yes'
839
840        % Get the new value
841        % Need to force char array
842        value = char(get(hObject,'String'));
843
844        propertyname  = get(handles.edit_dev_propname,'String');
845        propertyvalue = get(handles.edit_dev_propvalue,'String');
846        Family        = getappdata(handles.figure1, 'Family');
847        DeviceName    = family2tangodev(Family);
848
849        iSelected = get(handles.listbox_group,'Value');
850
851        val = tango_get_device_property(DeviceName(iSelected), ...
852            propertyname);
853
854        %% Get selected element
855        if isempty(val)
856            writelog(['Cancelled: property ' str2mat(propertyvalue)  'not defined'], handles);
857            set(handles.listbox_dev_property,'String', repmat('NaN',size(DeviceName)));
858        else
859            writelog(['Please wait: writting DEVICE property ' str2mat(propertyvalue)  '...'], handles);
860
861            tango_set_device_property(DeviceName(iSelected), ...
862                propertyname, propertyvalue);
863
864            writelog('Device properties written', handles);
865
866            % refresh display
867            pushbutton_dev_prop_Callback(handles.edit_dev_propvalue,eventdata, handles);
868        end
869    case {'No','Cancel'}
870        return;
871    otherwise
872        warning('Wrong answer')
873end
874
875
876% --- Executes during object creation, after setting all properties.
877function edit_dev_propvalue_CreateFcn(hObject, eventdata, handles)
878% hObject    handle to edit_dev_propvalue (see GCBO)
879% eventdata  reserved - to be defined in a future version of MATLAB
880% handles    empty - handles not created until after all CreateFcns called
881
882% Hint: edit controls usually have a white background on Windows.
883%       See ISPC and COMPUTER.
884if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
885    set(hObject,'BackgroundColor','white');
886end
887
888
889
890function edit_dev_propname_Callback(hObject, eventdata, handles)
891% hObject    handle to edit_dev_propname (see GCBO)
892% eventdata  reserved - to be defined in a future version of MATLAB
893% handles    structure with handles and user data (see GUIDATA)
894
895% Hints: get(hObject,'String') returns contents of edit_dev_propname as text
896%        str2double(get(hObject,'String')) returns contents of edit_dev_propname as a double
897
898
899% --- Executes during object creation, after setting all properties.
900function edit_dev_propname_CreateFcn(hObject, eventdata, handles)
901% hObject    handle to edit_dev_propname (see GCBO)
902% eventdata  reserved - to be defined in a future version of MATLAB
903% handles    empty - handles not created until after all CreateFcns called
904
905% Hint: edit controls usually have a white background on Windows.
906%       See ISPC and COMPUTER.
907if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
908    set(hObject,'BackgroundColor','white');
909end
910
911
912% --- Executes on button press in pushbutton_dev_prop.
913function pushbutton_dev_prop_Callback(hObject, eventdata, handles)
914% hObject    handle to pushbutton_dev_prop (see GCBO)
915% eventdata  reserved - to be defined in a future version of MATLAB
916% handles    structure with handles and user data (see GUIDATA)
917
918ifamily = get(handles.popupmenu_group,'Value');
919family  = get(handles.popupmenu_group,'String');
920
921Family        = family{ifamily};
922DeviceName    = family2tangodev(Family);
923
924if isempty(Family)
925    writelog('No machine loaded!',handles);
926    return
927end
928
929val = ones(size(DeviceName))*NaN';
930valS = repmat('NaN',size(DeviceName));
931
932property  = get(handles.edit_dev_propname,'String');
933
934val0 = tango_get_device_property(DeviceName,property);
935
936if isempty(val0)
937    writelog(['Property ''' property ''' not defined'],handles);
938    return;
939end
940
941if iscellstr(val0)
942    val = cellstr(val0);
943else
944    val = val0;
945end
946
947% unpdate listbox
948set(handles.listbox_dev_property,'String',val);
949% update editbox     
950set(handles.edit_value,'String',val(1));
951set(handles.listbox_attribute,'Value',1);
952set(handles.listbox_group,'Value',1);
953set(handles.listbox_dev_property,'Value',1);
954set(handles.listbox_property,'Value',1);
955% uncheckk buttons
956set(handles.checkbox_all,'Value', 0);
957
958writelog(['Values for property ''' property ''' refreshed'],handles);
959
Note: See TracBrowser for help on using the repository browser.