Hi David Cutler,
I understand you have a query regarding the approach to manage an application with manual and automated modes for hardware control in MATLAB App Designer.
Following are the steps to follow with a sample snippet of code, which can help you in getting started:
- Use App Designer to add necessary UI components (buttons, sliders, UIAxes, etc.) for both modes.
- Use “startupFcn(app)” to set up hardware connections, potentially storing the connection as a property of the app.
function startupFcn(app)
% Initialization code for your hardware
app.hardwareConnection = initializeHardwareConnection(); % Example function
end
- Define a property to track the current mode ('manual' or 'automated').
properties (Access = private)
mode = 'manual'; % Default mode
end
- Use UI components (switches, buttons) to allow the user to change modes, adjusting UI elements and functionality accordingly.
function ManualSliderValueChanged(app, event)
newPosition = app.ManualSlider.Value;
moveLinearStage(app.hardwareConnection, newPosition); % Example function
end
- Link UI component callbacks (e.g., sliders for linear stages) directly to hardware control functions.
- Trigger automated sequences with a button, using a loop or timer for task execution. Ensure mechanisms are in place for safe stopping and mode switching.
function StartAutomatedModeButtonPushed(app, event)
app.mode = 'automated';
while strcmp(app.mode, 'automated')
performAutomatedTask(app.hardwareConnection); % Example function
drawnow; % Allow GUI updates and callback processing
if stopConditionMet() % Implement this function as needed
app.mode = 'manual';
end
end
end
- Update UIAxes or similar components with real-time data or results from the hardware.
- Implement “CloseRequestFcn” to properly close hardware connections and clean up resources when the app closes.
function CloseRequestFcn(app)
closeHardwareConnection(app.hardwareConnection); % Example function
delete(app);
end
For better understanding of “startupFcn” , “drawnow” or “UIAxes” refer to the following documentation:
- https://www.mathworks.com/help/matlab/creating_guis/app-designer-startup-function.html
- https://www.mathworks.com/help/matlab/ref/matlab.ui.figureappd-properties.html
Hope this helps!!