Create an App for Analog Triggered Data Acquisition by Using Stateflow Charts
This example shows how to create an analog-triggered data acquisition app by using Stateflow®, Data Acquisition Toolbox™, and App Designer.
数据采集工具箱provides functionality for acquiring measurement data from a DAQ device or audio soundcard. For certain applications, an analog-triggered acquisition that starts capturing or logging data based on a condition in the analog signal being measured is recommended. Software-analog triggered acquisition enables you to capture only a segment of interest out of a continuous stream of measurement data. For example, you can capture an audio recording when the signal level passes a certain threshold.
This example app, created by using App Designer and Stateflow, shows how to implement these operations:
使用状态流图来控制应用程序状态逻辑。
Discover available DAQ devices and select which device to use.
配置设备采集参数。
Display a live plot in the app UI during acquisition.
Perform a triggered data capture based on a programmable trigger condition.
将获取的数据保存到一个MATLAB® base workspace variable.
By default, the app opens in design mode in App Designer. To run the app click theRun按钮或从命令行执行应用程序:
AnalogTriggerAppStateflow
要求
This example app requires:
MATLAB R2020a or later.
数据采集工具箱(supported on Windows® only).
Stateflow (for creating and editing charts only).
支持万博1manbetx的DAQ设备或声卡。例如,任何支持模拟输入的国家仪器或测量计算设备万博1manbetx
电压
或者IEPE
测量和背景获取。Corresponding hardware support package and device drivers.
应用状态和状态流图
When creating an app that has complex logic, consider the various states that correspond to the operating modes of the app. You can use a Stateflow chart to visualize and organize these app states. Use transitions between states to implement the control logic of your app. For example, the fileAnalogTriggerAppLogic.sfx
定义控制此应用程序逻辑的状态流图。图表可以根据应用程序中的操作或数据驱动条件在状态之间过渡。例如,如果您单击Startbutton, the chart transitions from the配置
状态到Acquisition
state. If the value of the signal crosses the specified trigger level, the chart transitions from theLookingForTrigger
状态到捕获达塔
state.
Integrating the App with the Stateflow Chart
在MATLAB应用和状态流图之间建立双向连接startupFcn
应用程序的功能,创建图表对象并将其句柄存储在应用程序属性中。
app.Chart = AnalogTriggerAppLogic(app=app);
The app uses this handle to trigger state transitions in the chart. For example, when you clickStart,StartButtonPushed
app callback function calls theacquisitionStart
input event for the chart. This event triggers the transition from the配置
状态到Acquisition
state.
为了评估图表中不是事件的过渡条件,该应用将step
图表对象的功能。例如,在从设备中获取数据时dataAvailable_Callback
app function periodically calls thestep
function. When the trigger condition is detected, the chart transitions from theLookingForTrigger
State to the捕获达塔
state.
In the Stateflow chart, store the app object handle as chart local data. To share public properties and call public functions of the app, the Stateflow chart can use this handle in state actions, transition conditions, or transition actions.