diff --git a/Utility functions/Local settings utilities/@MyInstrumentDescriptor/MyInstrumentDescriptor.m b/Utility functions/Local settings utilities/@MyInstrumentDescriptor/MyInstrumentDescriptor.m new file mode 100644 index 0000000..12e31e0 --- /dev/null +++ b/Utility functions/Local settings utilities/@MyInstrumentDescriptor/MyInstrumentDescriptor.m @@ -0,0 +1,37 @@ +% Class for storing information about local instruments + +classdef MyInstrumentDescriptor + properties (Access = public) + name = '' % Identifier that is a MATLAB variable name + title = '' % Title displayed in menus + control_class = '' % Instrument control class + gui = '' % Gui + enabled = true + StartupOpts = struct() % Options passed to the class constructor on startup + LoggerOpts = struct() % Options for starting a logger with this instrument + end + + methods (Access = public) + function this = MyInstrumentDescriptor(varargin) + P = MyClassParser(this); + processInputs(P, this, varargin{:}); + end + end + + methods + function this = set.name(this, val) + assert(isvarname(val), '''name'' must be valid variable name') + this.name = val; + end + + % If title is not specified, return name + function val = get.title(this) + if isempty(this.title) + val = this.name; + else + val = this.title; + end + end + end +end + diff --git a/Utility functions/Local settings utilities/convertInstrumentListToDescriptor.m b/Utility functions/Local settings utilities/convertInstrumentListToDescriptor.m new file mode 100644 index 0000000..b605475 --- /dev/null +++ b/Utility functions/Local settings utilities/convertInstrumentListToDescriptor.m @@ -0,0 +1,58 @@ +% Convert structure-based instrument list to a descriptor-based one + +function NewInstrList = convertInstrumentListToDescriptor(OldInstrList) + NewInstrList = MyInstrumentDescriptor.empty(); + + names = fieldnames(OldInstrList); + for i = 1:length(names) + EntrStruct = OldInstrList.(names{i}); + + NewInstrList(i).name = names{i}; + + try + NewInstrList(i).control_class = EntrStruct.control_class; + catch ME + warning(ME.message) + end + + try + NewInstrList(i).gui = EntrStruct.gui; + catch ME + warning(ME.message) + end + + try + NewInstrList(i).title = EntrStruct.menu_title; + catch ME + warning(ME.message) + end + + try + if ~isempty(EntrStruct.interface) + NewInstrList(i).StartupOpts.interface = EntrStruct.interface; + end + catch ME + warning(ME.message) + end + + try + if ~isempty(EntrStruct.address) + NewInstrList(i).StartupOpts.address = EntrStruct.address; + end + catch ME + warning(ME.message) + end + + try + if ~isempty(EntrStruct.StartupOpts) + opt_names = fieldnames(EntrStruct.StartupOpts); + for j=1:lengh(opt_names) + NewInstrList(i).StartupOpts.(opt_names{j}) = ... + EntrStruct.StartupOpts.(opt_names{j}); + end + end + catch + end + end +end +