diff --git a/+Base/pref.m b/+Base/pref.m index 071878cc3..2d5419f46 100644 --- a/+Base/pref.m +++ b/+Base/pref.m @@ -14,6 +14,7 @@ % help_text - provide longer text to describe what this pref does (think tooltip) % readonly - boolean specifying if GUI control should be editable (e.g. "enabled") % display_only - boolean specifying if saved as pref when module unloaded + % tag - any data type available for user to choose (similar to gobject UserData) % set* % custom_validate* % custom_clean* @@ -74,6 +75,8 @@ custom_clean = {[], @(a)true}; % First things called before any validation set = {[], @(a)true}; + % Tag available to the user + tag = {[], @(a)true}; end methods % May be overloaded by subclass pref diff --git a/+Modules/Source.m b/+Modules/Source.m index c50e6d5b9..e0eff8876 100644 --- a/+Modules/Source.m +++ b/+Modules/Source.m @@ -33,7 +33,7 @@ function arm(obj) end function blackout(obj) %this method should do whatever is necessary to completely - %block emissions from the source; for example, this may include + %block emissions from the source; for example, this may include %powering off a source warning('SOURCE:notimplemented','blackout method not implemented for %s',class(obj)) end diff --git a/.matlabprefs.mat.backup b/.matlabprefs.mat.backup new file mode 100644 index 000000000..d12ec89ac Binary files /dev/null and b/.matlabprefs.mat.backup differ diff --git a/HelperFunctions/hwserver.m b/HelperFunctions/hwserver.m index 40aa46f0c..3018f323e 100644 --- a/HelperFunctions/hwserver.m +++ b/HelperFunctions/hwserver.m @@ -21,6 +21,7 @@ obj.connection.Terminator = 'LF'; obj.connection.OutputBufferSize = 4096; obj.connection.InputBufferSize = 4096; + obj.ping; end function delete(obj) if strcmp(obj.connection.status,'open') diff --git a/Modules/+Sources/SuperK.m b/Modules/+Sources/SuperK.m index c08d4ca27..6bacc0c44 100644 --- a/Modules/+Sources/SuperK.m +++ b/Modules/+Sources/SuperK.m @@ -1,31 +1,42 @@ classdef SuperK < Modules.Source - %superK used to control all aspects of the superK laser. + % SuperK used to control all aspects of the superK laser. % - % The on/off state of laser is controlled by the PulseBlaster (loaded - % in set.ip). Note this state can switch to unknown if another - % module takes over the PulseBlaster program. - % - % Power to the laser can be controlled through the serial object - % - obj.serial.on()/off() - however, time consuming calls! + % The emission state of the laser is controlled by serial connection + % + - properties - ip = 'Deprecated Use'; % IP of computer with and server - prefs = {'ip'}; + properties(SetObservable,GetObservable) + prefs = {'Power','Pulse_Picker','Rep_Rate','Center_Wavelength',... + 'Bandwidth','Attenuation','Host'}; + show_prefs = {'Power','Pulse_Picker','Rep_Rate','Center_Wavelength',... + 'Bandwidth','Attenuation','Host'}; + Power = Prefs.Double('max',100,'min',0,'units','%','allow_nan',false,... + 'tag','setPower'); + Pulse_Picker = Prefs.Integer('max',40,'min',0,'help_text','Divider of max rep rate',... + 'tag','setPulsePicker'); + Rep_Rate = Prefs.Double('units','MHz','readonly',true,... + 'tag','setRepRate'); + Center_Wavelength = Prefs.Double('min',0,'units','nm',... + 'tag','setWavelength'); + Bandwidth = Prefs.Double('min',0,'units','nm',... + 'tag','setBandwidth'); + Attenuation = Prefs.Double('max',100,'min',0,'units','%',... + 'tag','setND'); + Host = Prefs.String('No Server','set','setHost'); + end properties(SetObservable,SetAccess=private) source_on = false; running % Boolean specifying if StaticLines program running end properties(SetAccess=private,Hidden) - listeners status % Text object reflecting running path_button - serial + comm = hwserver.empty end methods(Access=protected) function obj = SuperK() obj.loadPrefs; - obj.serial = Drivers.SuperK.instance(obj.ip); end end methods(Static) @@ -40,89 +51,59 @@ end methods function delete(obj) - delete(obj.listeners) - delete(obj.serial) + if obj.comm_isvalid + delete(obj.comm); + end + end + function setNum(obj,val,pref) + obj.serial.(pref.tag.set)(val); end - function set.ip(obj,val) + function host = setHost(obj,val,pref) err = []; + if obj.comm_isvalid + delete(obj.comm); + end + if isempty(val) || strcmp(val,'No Server') + obj.comm = hwserver.empty; + obj.Host = 'No Server'; + host = obj.Host; + return + end try - delete(obj.serial) - obj.serial = Drivers.SuperK.instance(val); - obj.ip = val; + obj.comm = Drivers.SuperK.instance(val); + obj.Host = val; + host = val; catch err - delete(obj.listeners) - obj.ip = 'No Server'; + obj.Host = 'No Server'; + host = obj.Host; end if ~isempty(err) rethrow(err) end end function on(obj) - obj.serial.on(); + obj.comm.on(); obj.source_on = true; end function off(obj) - obj.serial.off(); + obj.comm.off(); obj.source_on = false; end - - % Settings and Callbacks - function settings(obj,panelH,~,~) - spacing = 1.5; - num_lines = 6; - line = 1; - uicontrol(panelH,'style','text','string','Power (%):','horizontalalignment','right',... - 'units','characters','position',[0 spacing*(num_lines-line) 18 1.25]); - uicontrol(panelH,'style','edit','string',num2str(obj.serial.getPower),'tag','setPower',... - 'units','characters','callback',@obj.setNum,... - 'horizontalalignment','left','position',[19 spacing*(num_lines-line) 10 1.5]); - line = 2; - uicontrol(panelH,'style','text','string','Pulse Picker (int):','horizontalalignment','right',... - 'units','characters','position',[0 spacing*(num_lines-line) 18 1.25]); - uicontrol(panelH,'style','edit','string',num2str(obj.serial.getPulsePicker),'tag','setPulsePicker',... - 'units','characters','callback',@obj.setNum,... - 'horizontalalignment','left','position',[19 spacing*(num_lines-line) 10 1.5]); - line = 3; - uicontrol(panelH,'style','text','string',strcat('Rep Rate (MHz): ',num2str(obj.serial.getRepRate())),'horizontalalignment','right',... - 'units','characters','position',[0,spacing*(num_lines-line) 25 1.25]); - line = 4; - uicontrol(panelH,'style','text','string','Center Wavelength (nm):','horizontalalignment','right',... - 'units','characters','position',[0 spacing*(num_lines-line) 18 1.25]); - uicontrol(panelH,'style','edit','string',num2str(obj.serial.getWavelength()),'tag','setWavelength',... - 'units','characters','callback',@obj.setNum,... - 'horizontalalignment','left','position',[19 spacing*(num_lines-line) 10 1.5]); - line = 5; - uicontrol(panelH,'style','text','string','Bandwidth (nm):','horizontalalignment','right',... - 'units','characters','position',[0 spacing*(num_lines-line) 18 1.25]); - uicontrol(panelH,'style','edit','string',num2str(obj.serial.getBandwidth()),'tag','setBandwidth',... - 'units','characters','callback',@obj.setNum,... - 'horizontalalignment','left','position',[19 spacing*(num_lines-line) 10 1.5]); - line = 6; - uicontrol(panelH,'style','text','string','Attenuation (%)):','horizontalalignment','right',... - 'units','characters','position',[0 spacing*(num_lines-line) 18 1.25]); - uicontrol(panelH,'style','edit','string',num2str(obj.serial.getND()),'tag','setND',... - 'units','characters','callback',@obj.setNum,... - 'horizontalalignment','left','position',[19 spacing*(num_lines-line) 10 1.5]); - end - - function setNum(obj,hObj,~) - temp = get(hObj,'string'); - temp = str2double(temp); - assert(~isnan(temp),'Must be a number!'); - obj.serial.(get(hObj,'tag'))(temp); + + function arm(obj) + % nothing needs to be done since SuperK just needs on/off methods end - function ipCallback(obj,src,varargin) - err = []; - try - obj.ip = get(src,'string'); - catch err - end - set(src,'string',obj.ip) - if ~isempty(err) - rethrow(err) + function val = get.comm(obj) + d = dbstack(1); + if ~strcmp(d(1).name,'SuperK.comm_isvalid') % avoid recursive call + assert(obj.comm_isvalid,'Not connected (set.host)'); end + val = obj.comm; end + function val = comm_isvalid(obj) % get method allows direct access to comm + val = any(isvalid(obj.comm)); + end end end \ No newline at end of file