Read data from DSP task
data = mdaqDSPRead(linkID, signalID, vectorSize, vectorCount, timeout); data = mdaqDSPRead(signalID, vectorSize, vectorCount, timeout);
This function reads data from Xcos generated DSP application. Function can be used only for Ext modelss model in external mode. Xcos model has to contain SIGNAL block with defined ID. Function blocks execution until it gathers all requested samples or 'timeout' is reached. For example, if a user wants to read data from DSP application where SIGNAL block with ID=13 is connected to MUX block which is passing 4 doubles (data size = 4), the function call will be as follows: mdaqDSPRead(13, 4, 1, 1). In that case, timeout is set to 1 second.
Signals reading mechanism is buffering data for all signal ONLY from one data request. The data request is performed when there is no data available at specific signal ID. To keep data coherency over the time there is a recommendation to read all signals. Example below:
linkID: Valid connection link id (optional)
signalID: SIGNAL block identification number from XCOS model
vectorSize: SIGNAL block data size
vectorCount: number of vectors to read
timeout: maximum amount of time to wait for data in seconds
This example shows how to modify and read DSP application data during its execution. The example uses Xcos model with 'MEM Read' and SIGNAL blocks and a script which modifies and reads DSP data with mdaqDSPWrite() and mdaqDSPRead() functions. The mdaqDSPBuild() function is used to build executable from existing Xcos model. When built, resulting binary file path is passed as a first argument to mdaqDSPInit() function which initializes DSP and configures the model frequency and its execution duration. After calling mdaqDSPStart() DSP application is started on MicroDAQ DSP.
When DSP application is started 'MEM Read' block reads data from memory index 1 every model step. By calling mdaqDSPWrite() function we change the value of number located at index 1. This way we can change the DSP application parameter during its execution. Apart from reading our model performs multiplication by 2 and after that operation it passes value to SIGNAL block which sends data to the host PC. This modified value can be read by mdaqDSPRead() function.
Xcos model used in examples below:
Example 1: Using standard DSP API
Freq = 10; // Hz Druration = 5; // seconds signalID = 1; memIndex = 1; disp("Building DSP model..."); mdaqDSPBuild(mdaqToolboxPath() + filesep() + "examples" + filesep() +"dsp_rw_demo.zcos"); disp("Starting DSP model..."); mdaqDSPInit('dsp_rw_demo_scig\dsp_rw_demo.out', Freq, Druration); mdaqDSPStart(); disp("Passing value 2 to DSP model..."); mdaqDSPWrite(memIndex, 2); disp("Reading data from DSP model..."); data1 = mdaqDSPRead(signalID, 1, 10, -1); disp(data1); disp("Passing value 4 to DSP model..."); mdaqDSPWrite(memIndex, 4); disp("Reading data from DSP model..."); data2 = mdaqDSPRead(signalID, 1, 10, -1); disp(data2); disp("Waiting for the end of execution..."); mdaqDSPWait(-1); disp("End of execution DSP model"); | ![]() | ![]() |
Example 2: Using DSP task API
Freq = 10; // Hz Druration = 5; // seconds signalID = 1; memIndex = 1; // Create DSP task dsp = mdaqDSPTask(); disp("Building DSP model..."); mdaqDSPBuild(mdaqToolboxPath() + filesep() + "examples" + filesep() +"dsp_rw_demo.zcos"); disp("Starting DSP model..."); dsp.init('dsp_rw_demo_scig\dsp_rw_demo.out', Freq, Druration); dsp.start(); disp("Passing value 2 to DSP model..."); dsp.write(memIndex, 2); disp("Reading data from DSP model..."); data1 = dsp.read(signalID, 1, 10, -1); disp(data1); disp("Passing value 4 to DSP model..."); dsp.write(memIndex, 4); disp("Reading data from DSP model..."); data2 = dsp.read(signalID, 1, 10, -1); disp(data2); disp("Waiting for the end of execution..."); dsp.waitUntilDone(-1); disp("End of execution DSP model"); | ![]() | ![]() |