diff --git a/src/+mic/+camera/@IMGSourceCamera/IMGSourceCamera.m b/src/+mic/+camera/@IMGSourceCamera/IMGSourceCamera.m index 122e8b49..b196187f 100644 --- a/src/+mic/+camera/@IMGSourceCamera/IMGSourceCamera.m +++ b/src/+mic/+camera/@IMGSourceCamera/IMGSourceCamera.m @@ -273,6 +273,7 @@ TriggerMode; % trigger mode for Hamamatsu sCMOS camera DefectCorrection; % defect correction for Hamamatsu sCMOS camera GuiDialog; + AquisitionType = 'capture'; end methods @@ -585,6 +586,10 @@ function setCamProperties(obj,Infield) obj.ReadyForAcq=0; obj.SequenceLength=in; end + + function fireTrigger(obj) + trigger(obj.CameraHandle); + end end diff --git a/src/+mic/+camera/@IMGSourceCamera/getcamera.m b/src/+mic/+camera/@IMGSourceCamera/getcamera.m index 753090e5..e138835d 100644 --- a/src/+mic/+camera/@IMGSourceCamera/getcamera.m +++ b/src/+mic/+camera/@IMGSourceCamera/getcamera.m @@ -1,5 +1,8 @@ function getcamera(obj) H=imaqhwinfo; +if isempty(H.InstalledAdaptors) + error('No image acquisition adaptors found. Please install hardware support packages.'); +end ADname=H.InstalledAdaptors{1}; info=imaqhwinfo(ADname); diff --git a/src/+mic/+camera/@abstract/abstract.m b/src/+mic/+camera/@abstract/abstract.m index 9533a737..1bbf7514 100644 --- a/src/+mic/+camera/@abstract/abstract.m +++ b/src/+mic/+camera/@abstract/abstract.m @@ -319,7 +319,7 @@ function delete(obj) end %scaling - mx=double(max(max(im))); + mx=double(max(max(im)))+1; mn=double(min(min(im))); if obj.AutoScale %im = single(im-mn)/(mx-mn); diff --git a/src/+mic/@KuriosFilter/KuriosFilter.m b/src/+mic/@KuriosFilter/KuriosFilter.m new file mode 100644 index 00000000..63753106 --- /dev/null +++ b/src/+mic/@KuriosFilter/KuriosFilter.m @@ -0,0 +1,183 @@ +classdef KuriosFilter < mic.abstract + + properties (SetAccess=protected) + InstrumentName = 'KuriosFilter'; + Serial; + FilterType; + BWModes; + end + + properties + Wavelength; + BandwidthMode; + OutputMode; + MaxWavelength; + MinWavelength; + StartGUI; + end + + methods + + function obj = KuriosFilter(SerialPort) + s = serialportfind(Tag=SerialPort); + if isempty(s) + s = serialport(SerialPort,115200,Tag=SerialPort); + else + delete(s); + s = serialport(SerialPort,115200,Tag=SerialPort); + end + + configureTerminator(s,"CR") + obj.Serial=s; + + obj.send("*IDN?") + response = readline(s); + disp("Opening: " + response); + + obj.send("ST?") + eval(readline(s)+';') + disp("Initializing...") + while ST == 0 + obj.send("ST?") + pause(1) + eval(readline(s)+';'); + end + disp("Warm up to 40 degree.") + while ST == 1 + obj.send("ST?") + pause(1) + eval(readline(s)+';') + end + if ST == 2 + disp("Ready") + end + + + obj.send("OH?") + + response = readline(s); + eval(response+';'); + OH_bit = bitget(OH,16:-1:1,'int16'); + if OH_bit(8)==1 + obj.FilterType = 'Visible'; + elseif OH_bit(7)==1 + obj.FilterType = 'NIR'; + end + + BWModes = {}; + if OH_bit(16) == 1 + BWModes = [BWModes,'BLACK']; + end + if OH_bit(15) == 1 + BWModes = cat(BWModes,'WIDE'); + end + if OH_bit(14) == 1 + BWModes = cat(BWModes,'MEDIUM'); + end + if OH_bit(13) == 1 + BWModes = [BWModes,'NARROW']; + end + obj.BWModes = BWModes; + + %set output mode to manual + obj.send("OM=1") + obj.OutputMode = "Manual"; + + %set Bandwidth mode to narrow + obj.send("BW=8") + obj.BandwidthMode = "NARROW"; + + %get wavelength range + obj.send("SP?") + %pause(1) + eval(readline(s)+';'); + %pause(2) + eval(readline(s)+';'); + obj.MaxWavelength=WLmax; + obj.MinWavelength=WLmin; + + %get current wavelength + obj.send("WL?") + %pause(0.1) + eval(readline(s)+';') + obj.Wavelength = WL; + + end + + + function send(obj,Message) + flush(obj.Serial) + writeline(obj.Serial,Message) + pause(0.1) + end + + function setWavelength(obj,Wavelength) + Wavelength = round(Wavelength); + if Wavelengthobj.MaxWavelength + warning("Wavelength is too large, set to %d nm", obj.MaxWavelength) + Wavelength = obj.MaxWavelength; + end + + obj.send("WL="+num2str(Wavelength)) + obj.Wavelength = Wavelength; + end + + function setBWmode(obj,BWmode) + if ~ismember(BWmode,obj.BWModes) + error('mic.KuriosFilter: setBWmode: available bandwidth modes are %s',strjoin(obj.BWModes,',')) + end + switch BWmode + case "BLACK" + obj.send("BW=1") + case "WIDE" + obj.send("BW=2") + case "MEDIUM" + obj.send("BW=4") + case "NARROW" + obj.send("BW=8") + end + obj.BandwidthMode = BWmode; + end + + function delete(obj) + flush(obj.Serial) + delete(obj.Serial) + end + + function [Attributes,Data,Children]=exportState(obj) + % Export the object current state + Attributes.Wavelength=obj.Wavelength; + Attributes.BandwidthMode=obj.BandwidthMode; + % no Data is saved in this class + Data=[]; + Children=[]; + end + end + + methods (Static=true) + function funcTest(SerialPort) + % Unit test of object functionality + + if nargin<1 + error('mic.KuriosFilter::SerialPort must be defined') + end + + %Creating an Object and Testing setPower, on, off + fprintf('Creating Object\n') + TF=mic.KuriosFilter(SerialPort); + fprintf('Set to minimum wavelength\n') + TF.setWavelength(TF.MinWavelength); + fprintf('Delete Object\n') + %Test Destructor + delete(TF); + clear TF; + + end + end + +end \ No newline at end of file diff --git a/src/+mic/@KuriosFilter/gui.m b/src/+mic/@KuriosFilter/gui.m new file mode 100644 index 00000000..ee2f6611 --- /dev/null +++ b/src/+mic/@KuriosFilter/gui.m @@ -0,0 +1,100 @@ +function guiFig = gui(obj) +%gui Graphical User Interface foe attenuator + +%Prevent opening more than one figure for same instrument +if ishandle(obj.GuiFigure) + guiFig = obj.GuiFigure; + figure(obj.GuiFigure); + return +end + + +%Open figure +guiFig = figure('NumberTitle','off','Resize','off','Units','pixels','MenuBar','none',... + 'ToolBar','none','Visible','on', 'Position',[100 200 450 190]); + +%Construct the components +handles.output = guiFig; +guidata(guiFig,handles); + +minWavelength=obj.MinWavelength; +maxWavelength=obj.MaxWavelength; +Nstep = maxWavelength-minWavelength-1; + +handles.sliderWavelength=uicontrol('Parent',guiFig,'Style','slider','units','pixels','Min',minWavelength,... + 'Max',maxWavelength,'Value',minWavelength,'SliderStep',[1/Nstep 1/Nstep],... + 'Position', [118 44 200 35],'Callback',@sliderfn); +handles.textminWavelength = uicontrol('Style','text','String','Min',... + 'Position',[35 60,80,20],'FontSize',10); +handles.valueminWavelength = uicontrol('Style','text','String',[num2str(minWavelength),' ','nm'],... + 'Position',[48 40,70,20]); +handles.textmaxWavelength = uicontrol('Style','text','String','Max',... + 'Position',[325 60,80,20],'FontSize',10); +handles.valuemaxWavelength = uicontrol('Style','text','String',[num2str(maxWavelength),' ','nm'],... + 'Position',[337 40,70,20]); +handles.textSetWavelength = uicontrol('Style','text','String','Set Wavelength',... + 'Position',[50 100,150,20],'FontSize',10); +handles.SetWavelength = uicontrol('Style','edit','String',num2str(minWavelength),... + 'Position',[190 97,80,25],'FontSize',10,'Callback',@setWavelength); +handles.textWavelengthUnit=uicontrol('Style','text','String','nm',... + 'Position',[270 100,50,20],'FontSize',10); + +handles.textSetBWmode = uicontrol('Style','text','String','Set Bandwidth Mode',... + 'Position',[50 130,150,20],'FontSize',10); +handles.SetBWMode = uicontrol('Style','popupmenu','String',obj.BWModes,... + 'Position',[190 127,120,25],'FontSize',10,'Callback',@setBWmode); + + +% Create a property based on GuiFigure +obj.GuiFigure = guiFig; +obj.GuiFigure.Name = obj.InstrumentName; + +%Prevent closing after a 'close' or 'close all' +obj.GuiFigure.HandleVisibility='off'; + +%Save Propeties upon close +obj.GuiFigure.CloseRequestFcn = @closeFigure; + +%Initialize GUI properties +properties2gui(); + + function closeFigure(~,~) + gui2properties(); + delete(obj.GuiFigure); + end + + function sliderfn(h,~) + sliderValue=round(get(h,'Value')); + set(handles.SetWavelength,'String',num2str(sliderValue)) + obj.setWavelength(sliderValue) + %gui2properties(); + end + + function setWavelength(h,~) + textValue=str2double(get(h,'String')); + set(handles.sliderWavelength,'Value',textValue) + obj.setWavelength(textValue) + %gui2properties() + end + + function setBWmode(h,~) + idx = get(h,'value'); + obj.setBWmode(obj.BWModes{idx}) + end + +%% All figure have these functions but will be different contents + + function gui2properties() + %obj.Wavelength=str2double(get(handles.SetWavelength,'String')); + end + + function properties2gui() + if isempty(obj.Wavelength) || isnan(obj.Wavelength) + obj.Wavelength=obj.MinWavelength; + end + idx = find(strcmp(obj.BWModes, obj.BandwidthMode)); + set(handles.SetBWMode,'value',idx) + set(handles.sliderWavelength,'Value',obj.Wavelength) + set(handles.SetWavelength,'String',num2str(obj.Wavelength)); + end +end \ No newline at end of file