フィルターのクリア

Combining Scripts with AppDesigner

2 ビュー (過去 30 日間)
David Cutler
David Cutler 2021 年 3 月 25 日
回答済み: Vidhi Agarwal 2024 年 5 月 30 日
I am using Matlab to control some linear stages and a scope. the application needs to run in a couple of modes, 1) manual mode (for debugging setup) and 2) automated mode (for functional tests). I would normally use a "main loop" (ex. main.m) to manage hardware activities and a GUI to set parameters and display results. How do I do this AppDesign? I've not seen a way to do my normal approach, is there a better approach for AppDesigner.

回答 (1 件)

Vidhi Agarwal
Vidhi Agarwal 2024 年 5 月 30 日
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:
Hope this helps!!

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by