Created
July 3, 2025 12:02
-
-
Save raacampbell/49b0fb693392dce836884899c34f6e0b to your computer and use it in GitHub Desktop.
Switches the lights of ScanImage microscope enclosures on and off
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function switchEnclosureLights() | |
| % Switches the lights of the microscope enclosure on and off | |
| % | |
| % function switchEnclosureLights() | |
| % | |
| % Purpose | |
| % Switches the microscope enclosure lights on and off. Uses the ScanImage ResourceStore | |
| % to communicate with the DAQ and cache the last state of the lights. The lights will | |
| % not be turned on when the PMTs are on. The PMTs can not be turned on when then lights | |
| % are on. | |
| % | |
| % Usage | |
| % Set up a user button widget in ScanImage and have it call this function when pressed. | |
| % The text of the button will change based on light state. This is handled by this | |
| % function. | |
| % | |
| % You will need to set the DIO line and widget name variables, below, to match your system. | |
| % Set t_line to the device, port, and line number for your TTL signal. | |
| t_line='/scan/port0/line1'; | |
| % Widget Name: set the following variable to make the widget name that your button is on | |
| widgetName='Mic. Lights'; | |
| persistent hButton hPmtWidgets | |
| % Get the SI object | |
| hSI = evalin('base','hSI'); % get hSI from the base workspace | |
| PMTs_are_On = any(hSI.hPmts.powersOn); | |
| % Do not turn on the lights if any PMT is on. | |
| if PMTs_are_On | |
| disp('PMTs on: Lights will not turn on!') | |
| return | |
| end | |
| % If we have not previously connected to the button and PMTs we do so now | |
| if ~most.idioms.isValidObj(hButton) | |
| % The user button widget | |
| hResource = dabs.resources.ResourceStore.filterByNameStatic(widgetName); | |
| hWidget = hResource.findWidgets(); | |
| hWidget = hWidget{1}; | |
| hButton = hWidget.hButtons; | |
| % The PMTs | |
| hPmts = dabs.resources.ResourceStore.filterByClassStatic('dabs.resources.devices.PMT'); | |
| hPmtWidgets = {}; | |
| for pmtIdx = 1:numel(hPmts) | |
| hPmtWidgets(end + 1) = hPmts{pmtIdx}.findWidgets(); | |
| end | |
| end | |
| % Connect to the DIO line | |
| rs = dabs.resources.ResourceStore(); | |
| pp=rs.filterByName(t_line); | |
| % Switch lights and change button state based on the DIO line state | |
| if pp.lastKnownValue==0 || isnan(pp.lastKnownValue) | |
| pp.setValue(true) | |
| hButton.String = 'Lights currently on'; | |
| for pmtWidgetIdx = 1:numel(hPmtWidgets) | |
| hPmtWidget = hPmtWidgets{pmtWidgetIdx}; | |
| children = hPmtWidget.hAx.Children; | |
| for child = children(:)' | |
| % Matlab only iterates over row vector arrays | |
| child.HitTest = 'off'; | |
| end | |
| end | |
| elseif pp.lastKnownValue==1 | |
| pp.setValue(false) | |
| hButton.String = 'Lights currently off'; | |
| for pmtWidgetIdx = 1:numel(hPmtWidgets) | |
| hPmtWidget = hPmtWidgets{pmtWidgetIdx}; | |
| children = hPmtWidget.hAx.Children; | |
| for child = children(:)' | |
| child.HitTest = 'on'; | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment