source: MML/trunk/machine/SOLEIL/common/archiving/tango_archiving_config.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: 32.3 KB
Line 
1function varargout = tango_archiving_config(varargin)
2% TANGO_ARCHIVING_CONFIG M-file for tango_archiving_config.fig
3%      TANGO_ARCHIVING_CONFIG, by itself, creates a new TANGO_ARCHIVING_CONFIG or raises the existing
4%      singleton*.
5%
6%      H = TANGO_ARCHIVING_CONFIG returns the handle to a new TANGO_ARCHIVING_CONFIG or the handle to
7%      the existing singleton*.
8%
9%      TANGO_ARCHIVING_CONFIG('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in TANGO_ARCHIVING_CONFIG.M with the given input arguments.
11%
12%      TANGO_ARCHIVING_CONFIG('Property','Value',...) creates a new TANGO_ARCHIVING_CONFIG or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before tango_archiving_config_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to tango_archiving_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_archiving_config
26
27% Last Modified by GUIDE v2.5 07-Apr-2005 09:47: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', @tango_archiving_config_OpeningFcn, ...
34    'gui_OutputFcn',  @tango_archiving_config_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% Written by Laurent S. Nadolski
50
51
52% --- Executes just before tango_archiving_config is made visible.
53function tango_archiving_config_OpeningFcn(hObject, eventdata, handles, varargin)
54% This function has no output args, see OutputFcn.
55% hObject    handle to figure
56% eventdata  reserved - to be defined in a future version of MATLAB
57% handles    structure with handles and user data (see GUIDATA)
58% varargin   command line arguments to tango_archiving_config (see VARARGIN)
59
60% Choose default command line output for tango_archiving_config
61handles.output = hObject;
62
63% Update handles structure
64guidata(hObject, handles);
65
66% UIWAIT makes tango_archiving_config wait for user response (see UIRESUME)
67% uiwait(handles.figure1);
68
69disp('TANGO Archiving Configurator');
70
71%% Look for archiving manager TANGO name in static Database
72archivingmanager = cell2mat(tango_get_db_property('archivage','archivingmanager'));
73tango_set_timeout(archivingmanager,30000);
74
75setappdata(handles.figure1,'archivingmanager', archivingmanager);
76
77%% Initialize database {HDB} and machine {LT1}
78handles.database='HDB';
79guidata(hObject, handles);
80
81hdbmenu_Callback(hObject, eventdata, handles);
82uimenu_anneau_Callback(handles.uimenu_LT1, eventdata, handles);
83
84% Update handles structure
85guidata(hObject, handles);
86
87% --- Outputs from this function are returned to the command line.
88function varargout = tango_archiving_config_OutputFcn(hObject, eventdata, handles)
89% varargout  cell array for returning output args (see VARARGOUT);
90% hObject    handle to figure
91% eventdata  reserved - to be defined in a future version of MATLAB
92% handles    structure with handles and user data (see GUIDATA)
93
94% Get default command line output from handles structure
95varargout{1} = handles.output;
96
97% --- Executes on selection change in popupmenu_group.
98function popupmenu_group_Callback(hObject, eventdata, handles)
99% hObject    handle to popupmenu_group (see GCBO)
100% eventdata  reserved - to be defined in a future version of MATLAB
101% handles    structure with handles and user data (see GUIDATA)
102
103% Hints: contents = get(hObject,'String') returns popupmenu_group contents as cell array
104%        contents{get(hObject,'Value')} returns selected item from popupmenu_group
105
106contents = get(hObject,'String');
107num      = get(hObject,'Value');
108group    = contents{num};
109
110setappdata(handles.figure1,'group', group);
111
112AO       = getappdata(handles.figure1,'AO');
113
114% Status one devices
115valid  = find(AO.(group).Status);
116
117% Update Group list
118set(handles.listbox_group,'String',AO.(group).DeviceName(valid));
119
120set(handles.popupmenu_command,'BackgroundColor','red');
121
122% Builds up attribut list for selected group
123attributeList = tango_get_attribute_list(AO.(group).DeviceName{valid(1)});
124
125num = get(handles.popupmenu_attribute,'Value');
126if num > length(attributeList)
127    num = 1;
128    set(handles.popupmenu_attribute,'Value',num);
129end
130set(handles.popupmenu_attribute,'String',attributeList);
131
132popupmenu_attribute_Callback(handles.popupmenu_attribute, eventdata, handles);
133
134%setback selected element and property to first one
135set(handles.listbox_property,'Value',1);
136set(handles.listbox_group,'Value',1);
137
138
139% Update handles structure
140guidata(hObject, handles);
141
142% --- Executes during object creation, after setting all properties.
143function popupmenu_group_CreateFcn(hObject, eventdata, handles)
144% hObject    handle to popupmenu_group (see GCBO)
145% eventdata  reserved - to be defined in a future version of MATLAB
146% handles    empty - handles not created until after all CreateFcns called
147
148% Hint: popupmenu controls usually have a white background on Windows.
149%       See ISPC and COMPUTER.
150if ispc
151    set(hObject,'BackgroundColor','white');
152else
153    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
154end
155
156
157% --- Executes on selection change in popupmenu_attribute.
158function popupmenu_attribute_Callback(hObject, eventdata, handles)
159% hObject    handle to popupmenu_attribute (see GCBO)
160% eventdata  reserved - to be defined in a future version of MATLAB
161% handles    structure with handles and user data (see GUIDATA)
162
163% Hints: contents = get(hObject,'String') returns popupmenu_attribute contents as cell array
164%        contents{get(hObject,'Value')} returns selected item from popupmenu_attribute
165
166contents  = get(hObject,'String');
167num       = get(hObject,'Value');
168attribute = contents{num};
169
170setappdata(handles.figure1,'attribute', attribute);
171
172% --- Executes during object creation, after setting all properties.
173function popupmenu_attribute_CreateFcn(hObject, eventdata, handles)
174% hObject    handle to popupmenu_attribute (see GCBO)
175% eventdata  reserved - to be defined in a future version of MATLAB
176% handles    empty - handles not created until after all CreateFcns called
177
178% Hint: popupmenu controls usually have a white background on Windows.
179%       See ISPC and COMPUTER.
180if ispc
181    set(hObject,'BackgroundColor','white');
182else
183    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
184end
185
186
187% --- Executes on selection change in popupmenu_command.
188function popupmenu_command_Callback(hObject, eventdata, handles)
189% hObject    handle to popupmenu_command (see GCBO)
190% eventdata  reserved - to be defined in a future version of MATLAB
191% handles    structure with handles and user data (see GUIDATA)
192
193% Hints: contents = get(hObject,'String') returns popupmenu_command contents as cell array
194%        contents{get(hObject,'Value')} returns selected item from popupmenu_command
195
196%% Set color to Green
197set(handles.popupmenu_command,'BackgroundColor','green');
198
199contents  = get(hObject,'String');
200num       = get(hObject,'Value');
201command  = contents{num};
202
203setappdata(handles.figure1,'command', command);
204
205group     = getappdata(handles.figure1,'group');
206attribute = getappdata(handles.figure1,'attribute');
207AO        = getappdata(handles.figure1,'AO');
208
209% Status one devices
210valid  = find(AO.(group).Status);
211
212% Construct DeviceName/AttributName list
213%host = getenv('TANGO_HOST'); %% TODO PAS PROPRE mais pour rester conforme avec archiving
214%fullTangoNames = strcat('//',host,'/',AO.(group).DeviceName(valid), '/', attribute);
215fullTangoNames = strcat(AO.(group).DeviceName(valid), '/', attribute);
216archivingmanager = getappdata(handles.figure1,'archivingmanager');
217
218if (get(handles.checkbox_all,'Value') == 0)
219    %% Get selected element
220    idx = get(handles.listbox_property,'Value');
221    fullTangoNamesV = fullTangoNames(idx);
222else % All the same
223    fullTangoNamesV = fullTangoNames';
224end
225
226% Select database
227switch handles.database
228    case 'HDB'
229        command = [command 'Hdb'];
230    case 'TDB'
231        command = [command 'Tdb'];
232end
233
234% switchyard on commands
235switch command(1:end-3)
236    case {'IsArchived'} % check archiving state
237        argin = fullTangoNames';
238        list = tango_command_inout2(archivingmanager,command,argin)';
239        set(handles.listbox_property,'String',list);
240
241    case {'GetArchivingMode'} % Get archiving mode
242        list = [];
243        for k = 1:length(fullTangoNames)
244            argin = fullTangoNames{k};
245            answer = tango_command_inout2(archivingmanager,command,argin);
246            list = [list ; format_output_list(answer)];
247        end
248
249        %% Format data for fast print out
250        Name = strcat(AO.(group).DeviceName(valid), '/', attribute);
251        [n1 n2] = size(list);
252        Strcell = cell(n2+1,n1);
253        Strcell(end,:) = Name;
254        Strcell(1:end-1,:) = num2cell(list');
255
256        %% TODO: location for file, check fopen is OK
257        directory = getfamilydata('Directory','Archiving');
258        filename = [directory 'summarymodedata.txt'];
259        %filename = tempname;
260        [fid message] = fopen(filename,'w');
261        if fid == -1
262            message
263            return;
264        end
265
266        fprintf(fid,['# ',handles.database ' DATABASE: File generated on' ...
267            ' %s\n'],datestr(now));
268        fprintf(fid,['# Periodic Mode      Absolute Mode       ' ...
269            '  Relative Mode       TANGO attribute Name   \n']);
270        fprintf(fid,['#      T(s)    T(s)     min      max     ' ...
271            'T(s)     min      max    \n']);
272        fprintf(fid,'    %7.1f %7.1f %8.2f %8.2f %7.1f %8.2f %8.2f  %s\n',Strcell{:});
273        fclose(fid);
274
275        % edit 'modedata.txt'
276        if isunix
277            system(['nedit ', filename, ' &']);  % much faster
278%             eval(['edit ' filename])
279        else
280            eval(['edit ' filename])
281        end
282
283    case {'ArchivingStart'}% Start archiving
284
285        %% Selects archiving mode
286        mode = archiving_panel_mode(handles.database);
287               
288        if isstruct(mode) % means not canceled
289            %% Build up the argument for sIntermediatetarting archiving
290            %% Check for different modes selected by user
291            argin = BuildArgin(fullTangoNamesV, mode,handles);
292           
293            if isnumeric(argin) && argin == -1
294                disp('No Archiving mode selected, does nothing');
295                return;
296            end
297           
298            start_archiving(archivingmanager,command,argin,handles);
299
300            %% Force a IsArchived call to check if everything as
301            %% expected
302            set(handles.popupmenu_command,'Value',1);
303            popupmenu_command_Callback(hObject, eventdata, handles);
304        end
305
306    case {'ArchivingStop'}% Stop archiving
307        argin = fullTangoNamesV';
308        error = tango_command_inout2(archivingmanager,command,argin);
309        display_archiving_error(error,handles);
310
311        set(handles.popupmenu_command,'Value',1);
312        popupmenu_command_Callback(hObject, eventdata, handles);
313
314    case {'ArchivingModif'}% Get archiving mode
315        list = []; % clear list
316        % build list
317        for k = 1:length(fullTangoNamesV) % length(fullTangoNames) % Get the first one if a list
318            argin = fullTangoNamesV{k};
319            answer = tango_command_inout2(archivingmanager,['GetArchivingMode' command(end-2:end)],argin);
320            list = [list ; format_output_list(answer)];
321        end
322
323        % Selects archiving mode
324        % List contains existing archiving modes to be modified
325        mode = archiving_panel_mode(handles.database,list);
326
327        if isstruct(mode) % means not canceled
328
329            %% Build up the argument for starting archiving
330            %% Check for different modes selected by user
331            argin = BuildArgin(fullTangoNamesV, mode,handles);
332
333            start_archiving(archivingmanager,command,argin,handles);
334
335            %% Force a IsArchived call to check if everything as
336            %% expected
337            set(handles.popupmenu_command,'Value',1);
338            popupmenu_command_Callback(hObject, eventdata, handles);
339        end
340
341    otherwise
342        disp('Command not implemented')
343end
344
345% Update handles structure
346guidata(handles.figure1, handles);
347
348
349function argin = BuildArgin(fullTangoNames, mode, handles)
350% Build up the argument for starting archiving
351% Check for different modes selected by user
352
353[temp ismodeselected] = findkeyword(mode.selection,'1');
354if ismodeselected == 0 % no mode selected
355    argin = -1;
356    return;
357   
358elseif ismodeselected == 1 % at least an archiving mode selected
359   
360    %Load balancing
361   
362    %% standard header
363    % 1. archiver name for load balancing feature
364    % 2. group feature true or false (not implemented to the end)
365    switch mode.grouped
366        case '0'
367            header = {'toto', 'false'};
368        case '1'
369            % Force to flase since not yet implemented in matlab gui
370            header = {'toto', 'false'};
371            % header = {'toto', 'true'};
372    end
373   
374    %% Not required fields set to default values
375    % 1. data type
376    % 2. data format
377    % 3. writable
378    % 4. device in charge
379    % 5. Trigger time
380   
381    header_attribute = { '0', '0', '0', '','NULL'};
382
383    % header length for each attribut
384    % depends on the mode selection
385    len = 6;
386    len_mode = 0;
387   
388    % number of attributes to archive
389    nb = length(fullTangoNames);
390   
391    % mode parametrization
392    mode_P ={};
393    mode_A ={};
394    mode_R ={};
395    mode_string = {};
396
397    if str2double(mode.selection{1}) == 1 %% Periodic mode
398        len = len + 3;
399        len_mode = len_mode + 2;
400        if strcmpi(handles.database,'HDB')
401            mode.periodic.period = [mode.periodic.period '000']; % ms
402        end
403        mode_P = {'MODE_P', mode.periodic.period};
404    end
405
406    if str2double(mode.selection{2}) == 1 % Absolute mode
407        len = len + 4;
408        len_mode = len_mode + 4;
409        if strcmpi(handles.database,'HDB')
410            mode.absolute.period = [mode.absolute.period '000']; % ms
411        end
412        mode_A = {'MODE_A', mode.absolute.period,...
413            mode.absolute.lowerlimit, mode.absolute.upperlimit};
414    end
415
416    if str2double(mode.selection{3}) == 1 %Relative mode
417        len = len + 4;
418        len_mode = len_mode + 4;
419        if strcmpi(handles.database,'HDB')
420            mode.relative.period = [mode.relative.period '000']; % ms
421        end
422        mode_R = {'MODE_R', mode.relative.period,...
423            mode.relative.lowerlimit,mode.relative.upperlimit};
424    end
425
426    mode_string = {mode_P{:}, mode_R{:}, mode_A{:}};
427   
428    switch handles.database %% Select database
429        case 'TDB' %% Intermediate DATABASE
430            len = len +3;
431            len_mode = len_mode + 3;
432            mode_string = {mode_string{:}, 'TDB_SPEC', ...
433                mode.exportwindow, mode.keepingwindow};
434        case 'HDB' %% Historical DATABASE
435            % No extra arguments
436    end
437   
438    argin = header;
439   
440    % loop over list of attributed to be archived
441    for k = 1:nb       
442        argin = {argin{:}, num2str(len), fullTangoNames{k}, ...
443            header_attribute{:}, num2str(len_mode), mode_string{:}};
444    end
445     
446end
447
448function start_archiving(archivingmanager,command,argin,handles)
449% START_ARCHIVING - Start or modify an archiving
450%
451% INPUTS
452% archivingmanager - TANGO name of the archiving manager
453% command - start or modify archiving, could be
454%         - ArchivingStart
455%         - ArchivingModif
456%         - ArchivingStartIntermediate
457%         - ArchivingModifIntermediate
458% argin - inputs arguments related to command (see archivingmanager doc )
459%
460error = tango_command_inout2(archivingmanager,command,argin);
461
462display_archiving_error(error,handles);
463
464function display_archiving_error(error,handles)
465%DISPLAY_ARCHIVING_ERROR - Display error reason
466% Errorhandler
467% See archivingmanager documentation for details
468
469switch error
470    case 0
471        %% start succeeded
472        return;
473    case 1
474        disp('All the given attribute already archiving process')
475    case 2
476        disp('start failed')
477    case 3
478        % stop succeeded
479        return;
480    case 4
481        disp('All giving attributs are not in archiving process');
482    case 5
483        disp('Stop failed');
484    case 6
485        %% Modif succeeded
486        return;
487    case 7
488        disp('All given attributes are not in historic archiving');
489    case 8
490        disp('modif failed');
491    case 9
492        disp('No running [H/T]dbArchiver')
493    case 10
494        disp('All the attribute do not exist in static DB')
495    case 11
496        disp('database not connected')
497    case 12
498        disp('device cannot talk to the database')
499    otherwise
500        disp('Unknown error')
501end
502
503warning(['Error with ', handles.database,' database']);
504
505
506% --- Executes during object creation, after setting all properties.
507function popupmenu_command_CreateFcn(hObject, eventdata, handles)
508% hObject    handle to popupmenu_command (see GCBO)
509% eventdata  reserved - to be defined in a future version of MATLAB
510% handles    empty - handles not created until after all CreateFcns called
511
512% Hint: popupmenu controls usually have a white background on Windows.
513%       See ISPC and COMPUTER.
514if ispc
515    set(hObject,'BackgroundColor','white');
516else
517    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
518end
519
520% --- Executes on selection change in listbox_group.
521function listbox_group_Callback(hObject, eventdata, handles)
522% hObject    handle to listbox_group (see GCBO)
523% eventdata  reserved - to be defined in a future version of MATLAB
524% handles    structure with handles and user data (see GUIDATA)
525
526% Hints: contents = get(hObject,'String') returns listbox_group contents as cell array
527%        contents{get(hObject,'Value')} returns selected item from listbox_group
528
529set(handles.listbox_property,'Value',get(hObject,'Value'));
530set(handles.listbox_property,'ListboxTop',get(hObject,'ListboxTop'));
531
532
533% --- Executes during object creation, after setting all properties.
534function listbox_group_CreateFcn(hObject, eventdata, handles)
535% hObject    handle to listbox_group (see GCBO)
536% eventdata  reserved - to be defined in a future version of MATLAB
537% handles    empty - handles not created until after all CreateFcns called
538
539% Hint: listbox controls usually have a white background on Windows.
540%       See ISPC and COMPUTER.
541if ispc
542    set(hObject,'BackgroundColor','white');
543else
544    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
545end
546
547
548% --- Executes on selection change in listbox_property.
549function listbox_property_Callback(hObject, eventdata, handles)
550% hObject    handle to listbox_property (see GCBO)
551% eventdata  reserved - to be defined in a future version of MATLAB
552% handles    structure with handles and user data (see GUIDATA)
553
554% Hints: contents = get(hObject,'String') returns listbox_property contents as cell array
555%        contents{get(hObject,'Value')} returns selected item from listbox_property
556
557set(handles.listbox_group,'Value', get(hObject,'Value'));
558set(handles.listbox_group,'ListboxTop', get(hObject,'ListboxTop'));
559
560%set(handles.edit_value,'String',contents{get(hObject,'Value')});
561
562% --- Executes during object creation, after setting all properties.
563function listbox_property_CreateFcn(hObject, eventdata, handles)
564% hObject    handle to listbox_property (see GCBO)
565% eventdata  reserved - to be defined in a future version of MATLAB
566% handles    empty - handles not created until after all CreateFcns called
567
568% Hint: listbox controls usually have a white background on Windows.
569%       See ISPC and COMPUTER.
570if ispc
571    set(hObject,'BackgroundColor','white');
572else
573    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
574end
575
576
577% --- Executes on button press in checkbox_all.
578function checkbox_all_Callback(hObject, eventdata, handles)
579% hObject    handle to checkbox_all (see GCBO)
580% eventdata  reserved - to be defined in a future version of MATLAB
581% handles    structure with handles and user data (see GUIDATA)
582
583% Hint: get(hObject,'Value') returns toggle state of checkbox_all
584
585function edit_value_Callback(hObject, eventdata, handles)
586% hObject    handle to edit_value (see GCBO)
587% eventdata  reserved - to be defined in a future version of MATLAB
588% handles    structure with handles and user data (see GUIDATA)
589
590% Hints: get(hObject,'String') returns contents of edit_value as text
591%        str2double(get(hObject,'String')) returns contents of edit_value as a double
592
593value = get(hObject,'String');
594
595group     = getappdata(handles.figure1,'group');
596attribute = getappdata(handles.figure1,'attribute');
597property  = getappdata(handles.figure1,'property');
598AO        = getappdata(handles.figure1,'AO');
599
600%% Status one devices
601valid  = find(AO.(group).Status);
602
603if (get(handles.checkbox_all,'Value') == 0)
604    %% Get selectedd element
605    idx = get(handles.listbox_property,'Value');
606    tango_set_attribute_property(strcat(AO.(group).DeviceName{valid(idx)}, ...
607        '/',attribute),property, value)
608else % All the same
609    tango_set_attribute_property(strcat(AO.(group).DeviceName(valid), ...
610        '/',attribute),property, value)
611end
612%% Status one devices
613valid  = find(AO.(group).Status);
614
615%% refresh display
616popupmenu_property_Callback(handles.popupmenu_command,eventdata, handles);
617
618
619% --- Executes during object creation, after setting all properties.
620function edit_value_CreateFcn(hObject, eventdata, handles)
621% hObject    handle to edit_value (see GCBO)
622% eventdata  reserved - to be defined in a future version of MATLAB
623% handles    empty - handles not created until after all CreateFcns called
624
625% Hint: edit controls usually have a white background on Windows.
626%       See ISPC and COMPUTER.
627if ispc
628    set(hObject,'BackgroundColor','white');
629else
630    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
631end
632
633
634% --------------------------------------------------------------------
635function uimenu_linac_Callback(hObject, eventdata, handles)
636% hObject    handle to uimenu_linac (see GCBO)
637% eventdata  reserved - to be defined in a future version of MATLAB
638% handles    structure with handles and user data (see GUIDATA)
639
640init_uimenu(hObject, eventdata, handles);
641
642% --------------------------------------------------------------------
643function uimenu_LT1_Callback(hObject, eventdata, handles)
644% hObject    handle to uimenu_LT1 (see GCBO)
645% eventdata  reserved - to be defined in a future version of MATLAB
646% handles    structure with handles and user data (see GUIDATA)
647
648if ~strcmpi(getsubmachinename, 'LT1')
649    LT1init;
650end
651handles = init_uimenu(hObject, eventdata, handles);
652% Update handles structure
653guidata(hObject, handles);
654
655%%%--------------------------------------------------------------------
656function handles = init_uimenu(hObject, eventdata, handles)
657
658setappdata(handles.figure1,'AO', getao);
659
660%% Checked box
661all = findobj(get(hObject,'Parent'),'Type','UImenu');
662set(all, 'Checked', 'Off');
663set(hObject, 'Checked', 'On');
664
665%% Initializes popupmenu w/ first element, first attribute, first property
666listgroup = findmemberof('Archivable');
667
668set(handles.popupmenu_group,'String',listgroup);
669setappdata(handles.figure1,'group', listgroup{1});
670
671popupmenu_group_Callback(handles.popupmenu_group, eventdata, handles);
672
673%% Initializes command popup menu w/ list of archivingmanager available
674%% commands
675% res = tango_command_list_query(archivingmanager);
676% listcmd = {res.cmd_name};
677listcmd = {'IsArchived','GetArchivingMode', 'ArchivingStart', ...
678    'ArchivingStop','ArchivingModif'};
679set(handles.popupmenu_command,'String',listcmd);
680value = find(strcmp(listcmd,'IsArchived'));
681set(handles.popupmenu_command,'Value',value);
682setappdata(handles.figure1,'command', value);
683
684% --------------------------------------------------------------------
685function uimenu_booster_Callback(hObject, eventdata, handles)
686% hObject    handle to uimenu_booster (see GCBO)
687% eventdata  reserved - to be defined in a future version of MATLAB
688% handles    structure with handles and user data (see GUIDATA)
689
690if ~strcmpi(getsubmachinename, 'Booster')
691    boosterinit
692end
693init_uimenu(hObject, eventdata, handles);
694
695% --------------------------------------------------------------------
696function uimenu_LT2_Callback(hObject, eventdata, handles)
697% hObject    handle to uimenu_LT2 (see GCBO)
698% eventdata  reserved - to be defined in a future version of MATLAB
699% handles    structure with handles and user data (see GUIDATA)
700
701if ~strcmpi(getsubmachinename, 'LT2')
702   LT2init;
703end
704init_uimenu(hObject, eventdata, handles);
705
706% --------------------------------------------------------------------
707function uimenu_anneau_Callback(hObject, eventdata, handles)
708% hObject    handle to uimenu_anneau (see GCBO)
709% eventdata  reserved - to be defined in a future version of MATLAB
710% handles    structure with handles and user data (see GUIDATA)
711
712if ~strcmpi(getsubmachinename, 'StorageRing')
713    soleilinit;
714end
715init_uimenu(hObject, eventdata, handles);
716
717% --------------------------------------------------------------------
718function Untitled_1_Callback(hObject, eventdata, handles)
719% hObject    handle to Untitled_1 (see GCBO)
720% eventdata  reserved - to be defined in a future version of MATLAB
721% handles    structure with handles and user data (see GUIDATA)
722
723
724% --------------------------------------------------------------------
725function hdbmenu_Callback(hObject, eventdata, handles)
726% hObject    handle to menuhdb (see GCBO)
727% eventdata  reserved - to be defined in a future version of MATLAB
728% handles    structure with handles and user data (see GUIDATA)
729set(handles.hdbmenu,'checked','On');
730set(handles.tdbmenu,'checked','Off');
731handles.database='HDB';
732set(handles.mainuipanel,'Title','TANGO HDB Configurator', ...
733    'ForegroundColor',[0, 0.5, 0]);
734% Update handles structure
735guidata(hObject, handles);
736
737% --------------------------------------------------------------------
738function tdbmenu_Callback(hObject, eventdata, handles)
739% hObject    handle to tdbmenu (see GCBO)
740% eventdata  reserved - to be defined in a future version of MATLAB
741% handles    structure with handles and user data (see GUIDATA)
742set(handles.tdbmenu,'checked','On');
743set(handles.hdbmenu,'checked','Off');
744handles.database='TDB';
745set(handles.mainuipanel,'Title','TANGO TDB Configurator','ForegroundColor','b');
746% Update handles structure
747guidata(hObject, handles);
748
749% --------------------------------------------------------------------
750function Untitled_2_Callback(hObject, eventdata, handles)
751% hObject    handle to Untitled_2 (see GCBO)
752% eventdata  reserved - to be defined in a future version of MATLAB
753% handles    structure with handles and user data (see GUIDATA)
754
755
756% --- Executes on button press in checkbox_loadbalancing.
757function checkbox_loadbalancing_Callback(hObject, eventdata, handles)
758% hObject    handle to checkbox_loadbalancing (see GCBO)
759% eventdata  reserved - to be defined in a future version of MATLAB
760% handles    structure with handles and user data (see GUIDATA)
761
762% Hint: get(hObject,'Value') returns toggle state of checkbox_loadbalancing
763
764function list = format_output_list(varargin)
765
766cellarray = varargin{:};
767
768list = zeros(1,7);
769
770% Periodical mode: just get archiving period
771[cellarray index] = findkeyword2(cellarray,'MODE_P');
772if index ~= 0
773    list(1) = str2double(cellarray(index))/1e3; % seconds
774end
775
776% Absolute mode: just get archiving period and variation limits
777[cellarray index] = findkeyword2(cellarray,'MODE_A');
778if index ~= 0
779    list(2) = str2double(cellarray(index))/1e3; % seconds
780    list(3) = str2double(cellarray(index+1)); % decreasing variation (%)
781    list(4) = str2double(cellarray(index+2)); % increasing variation (%)
782end
783
784% Relative mode: just get archiving period and variation limits
785[cellarray index] = findkeyword2(cellarray,'MODE_R');
786if index ~= 0
787    list(5) = str2double(cellarray(index))/1e3; % seconds
788    list(6) = str2double(cellarray(index+1)); % decreasing variation (%)
789    list(7) = str2double(cellarray(index+2)); % increasing variation (%)
790end
791
792
793% --- If Enable == 'on', executes on mouse press in 5 pixel border.
794% --- Otherwise, executes on mouse press in 5 pixel border or over listbox_group.
795function listbox_group_ButtonDownFcn(hObject, eventdata, handles)
796% hObject    handle to listbox_group (see GCBO)
797% eventdata  reserved - to be defined in a future version of MATLAB
798% handles    structure with handles and user data (see GUIDATA)
799
800%% TODO: works only if right button pressed
801%       do not know how to do for left button
802val = get(handles.listbox_group,'Value');
803set(handles.listbox_property,'Value',val);
804
805
806% --------------------------------------------------------------------
807function menu_file_Callback(hObject, eventdata, handles)
808% hObject    handle to menu_file (see GCBO)
809% eventdata  reserved - to be defined in a future version of MATLAB
810% handles    structure with handles and user data (see GUIDATA)
811
812
813% --------------------------------------------------------------------
814function savemenu_Callback(hObject, eventdata, handles)
815% hObject    handle to savemenu (see GCBO)
816% eventdata  reserved - to be defined in a future version of MATLAB
817% handles    structure with handles and user data (see GUIDATA)
818
819summarymenu_Callback(hObject, eventdata, handles);
820directory = getfamilydata('Directory','Archiving');
821filename1 = [directory appendtimestamp('config')];
822filename0 = [directory 'config.dat'];
823copyfile(filename0,filename1);
824
825% --------------------------------------------------------------------
826function summarymenu_Callback(hObject, eventdata, handles)
827% hObject    handle to summarymenu (see GCBO)
828% eventdata  reserved - to be defined in a future version of MATLAB
829% handles    structure with handles and user data (see GUIDATA)
830
831AO        = getappdata(handles.figure1,'AO');
832archivingmanager = getappdata(handles.figure1,'archivingmanager');
833
834%grouplist = intersect(findmemberof('Magnet'),findmemberof('Archivable'));
835grouplist = findmemberof('Archivable');
836
837% get database name
838switch handles.database
839    case 'HDB'
840        dbName = 'Hdb';
841    case 'TDB'
842        dbName = 'Tdb';
843end
844
845directory = getfamilydata('Directory','Archiving');
846%filename = [directory appendtimestamp('config')];
847filename = [directory 'config.dat'];
848fid = fopen(filename,'w');
849
850fprintf(fid,['# ',handles.database ' DATABASE: File generated on' ...
851    ' %s\n'],datestr(now));
852fprintf(fid,['# Periodic Mode      Absolute Mode       ' ...
853    '  Relative Mode       TANGO attribute Name   \n']);
854fprintf(fid,['#      T(s)    T(s)     min      max     ' ...
855    'T(s)     min      max    \n']);
856
857for k1 = 1:length(grouplist),
858    % loop of group of devices
859    %get attribut list
860    % Status one devices
861    valid  = find(AO.(grouplist{k1}).Status);
862
863    for k2 = 1:length(valid)
864        % loop over devices
865        % Builds up attribut list for selected groups
866        attributeList = tango_get_attribute_list(AO.(grouplist{k1}).DeviceName{valid(k2)});
867        for k3 = 1:length(attributeList),
868            % loop over attributes
869            %check if archived
870            try
871                argin = strcat(AO.(grouplist{k1}).DeviceName(valid(k2)), '/', attributeList{k3});
872                arstatus = tango_command_inout2(archivingmanager,['IsArchived' dbName], argin);
873            catch
874                fprintf('Erreur with attribute %s\n Action aborted \n', attributeList{k3});
875                return;
876            end
877            if arstatus
878                %get Archiving modes
879                answer = tango_command_inout2(archivingmanager,['GetArchivingMode' dbName], argin{:});
880                list = format_output_list(answer);
881
882                %% Format data for fast print out
883%                 Name = strcat(AO.(groupLIST(k1)).DeviceName(valid(k2)), '/', attributelist{k3});
884                Name = argin;
885                [n1 n2] = size(list);
886                Strcell = cell(n2+1,n1);
887                Strcell(end,:) = Name;
888                Strcell(1:end-1,:) = num2cell(list');
889                fprintf(fid,'    %7.1f %7.1f %8.2f %8.2f %7.1f %8.2f %8.2f  %s\n',Strcell{:});
890            end
891        end
892    end
893end
894
895fclose(fid);
896
897% show file
898if isunix
899    system(['nedit ', filename, ' &']);  % much faster
900else
901    eval(['edit ' filename])
902end
903
904
905% --------------------------------------------------------------------
906function loadmenu_Callback(hObject, eventdata, handles)
907% hObject    handle to loadmenu (see GCBO)
908% eventdata  reserved - to be defined in a future version of MATLAB
909% handles    structure with handles and user data (see GUIDATA)
910
911disp('Not implemented yet')
Note: See TracBrowser for help on using the repository browser.