diff --git a/@MyCollector/MyCollector.m b/@MyCollector/MyCollector.m index 21d8d28..7569934 100644 --- a/@MyCollector/MyCollector.m +++ b/@MyCollector/MyCollector.m @@ -1,125 +1,125 @@ classdef MyCollector < handle properties (Access=public, SetObservable=true) InstrProps=struct(); InstrList=struct(); MeasHeaders=struct(); collect_flag; end properties (Access=private) Listeners=struct(); end properties (Dependent=true) open_instruments; end events NewMeasHeaders; end methods (Access=public) function this=MyCollector(varargin) p=inputParser; addParameter(p,'InstrHandles',{}); parse(p,varargin{:}); this.collect_flag=true; if ~isempty(p.Results.InstrHandles) cellfun(@(x) addInstrument(this,x),p.Results.InstrHandles); end end function delete(this) cellfun(@(x) deleteListeners(this,x), this.open_instruments); end - function addInstrument(this,instr_handle) + function addInstrument(this,prog_handle) %Input check - assert(ischar(instr_handle.name),... + assert(ischar(prog_handle.name),... 'The instrument name must be a char') - name=instr_handle.name; + name=prog_handle.name; %We add only MyInstrument classes for now - if contains('MyInstrument',superclasses(instr_handle)) + if contains('MyInstrument',superclasses(prog_handle)) %Defaults to read header this.InstrProps.(name).header_flag=true; - this.InstrList.(name)=instr_handle; + this.InstrList.(name)=prog_handle; else error(['%s is not a subclass of MyInstrument,',... ' cannot be added to instrument list'],name) end %If the added instrument has a newdata event, we add a listener for it. - if contains('NewData',events(instr_handle)) + if contains('NewData',events(prog_handle)) this.Listeners.(name).NewData=... addlistener(this.InstrList.(name),'NewData',... @(src,~) collectHeaders(this,src)); end %Cleans up if the instrument is closed this.Listeners.(name).Deletion=... addlistener(this.InstrList.(name),'ObjectBeingDestroyed',... @(~,~) deleteInstrument(this,name)); end function collectHeaders(this,src) %If the collect flag is not active, do nothing if ~this.collect_flag; return; end if isprop(src,'Trace') && isprop(src.Trace,'uid') this.MeasHeaders=MyMetadata('uid',src.Trace.uid); else this.MeasHeaders=MyMetadata(); end acquireHeaders(this); end %Collects headers for open instruments with the header flag on function acquireHeaders(this) for i=1:length(this.open_instruments) name=this.open_instruments{i}; if this.InstrProps.(name).header_flag tmp_struct=readHeader(this.InstrList.(name)); addField(this.MeasHeaders,name); addStructToField(this.MeasHeaders,name,tmp_struct); end end %Triggers the event showing measurement headers are ready triggerMeasHeaders(this); end function clearHeaders(this) this.MeasHeaders=MyMetadata(); end end methods (Access=private) function triggerMeasHeaders(this) notify(this,'NewMeasHeaders'); end %deleteListeners is in a separate file deleteListeners(this, obj_name); function deleteInstrument(this,name) %We remove the instrument this.InstrList=rmfield(this.InstrList,name); this.InstrProps=rmfield(this.InstrProps,name); deleteListeners(this,name); end end methods function open_instruments=get.open_instruments(this) open_instruments=fieldnames(this.InstrList); end end end diff --git a/Utility functions/DataAcquisitionMenu.mlapp b/Utility functions/DataAcquisitionMenu.mlapp index df8eed9..1ab7a6b 100644 Binary files a/Utility functions/DataAcquisitionMenu.mlapp and b/Utility functions/DataAcquisitionMenu.mlapp differ diff --git a/Utility functions/generateRunFile.m b/Utility functions/generateRunFile.m index 9f03f32..5ce60a2 100644 --- a/Utility functions/generateRunFile.m +++ b/Utility functions/generateRunFile.m @@ -1,74 +1,74 @@ % Automatically generates a run file for an entry from the InstrumentsList function generateRunFile(inst_entry, varargin) p=inputParser(); % Ignore unmatched parameters p.KeepUnmatched = true; addParameter(p,'out_dir','',@ischar); addParameter(p,'menu_title','',@ischar); addParameter(p,'show_in_daq',false,@islogical); parse(p,varargin{:}); if ~isempty(p.Results.out_dir) dir = p.Results.out_dir; else %By default, create files in the same directory with InstrumentList %or in the base directory if it does not exist dir=getLocalBaseDir(); end % Create run file if there is a default_gui indicated for the % instrument and no such file already exists file_name = fullfile(dir, ['run',inst_entry.name,'.m']); if ~logical(exist(inst_entry.default_gui,'file')) warning(['No valid Gui specified for %s, a run file cannot ',... 'be created'],inst_entry.name) return end if ~logical(exist(inst_entry.control_class,'class')) warning(['No valid control class specified for %s, a run ',... 'file cannot be created'], inst_entry.name) return end if exist(file_name,'file') warning(['The run file %s already exists, a new file has not ',... 'been created'], file_name) return end header_str=''; if ~isempty(p.Results.menu_title) header_str = [header_str, sprintf('%% menu_title=%s\n',... p.Results.menu_title)]; end if p.Results.show_in_daq header_str = [header_str, sprintf('%% show_in_daq=true\n')]; end % Code, defining the run function code_str = [... 'function instance_name = run%s()\n',... ' instance_name = ''%s%s'';\n',... ' if ~isValidBaseVar(instance_name)\n',... ' gui = %s(''instr_list'', ''%s'', ''instance_name'', instance_name);\n',... ' assignin(''base'', instance_name, gui);\n',... ' if ~isValidBaseVar(''DaqMenu''); runDaqMenu; end \n',... ' evalin(''base'', ... \n',... - ' sprintf(''addInstrument(DaqMenu.Collector,findMyInstrument(%%s))'',... \n',... - ' instance_name)); \n',... + ' sprintf(''addInstrument(DaqMenu.Collector,findMyInstrument(%%s))'',... \n',... + ' instance_name)); \n',... ' else\n',... ' warning(''%%s is already running'', instance_name);\n',... ' end\n',... 'end\n']; try fid = fopen(file_name,'w'); fprintf(fid, '%s', header_str); fprintf(fid, code_str,... inst_entry.name, inst_entry.default_gui, inst_entry.name,... inst_entry.default_gui, inst_entry.name); fclose(fid); catch warning('Failed to create the run file') end end