<< mdaqDSPIsDone DSP managment mdaqDSPStart >>

MicroDAQ toolbox >> MicroDAQ toolbox > DSP managment > mdaqDSPRead

mdaqDSPRead

Read data from DSP task

Calling Sequence

data = mdaqDSPRead(linkID, signalID, vectorSize, vectorCount, timeout);
data = mdaqDSPRead(signalID, vectorSize, vectorCount, timeout);

Description

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:

//------ NO DATA LOSS ----
t0 = mdaqDSPRead(1, vectorSize, vectorCount, timeout); <-- first data request, recv samples from time t0, for all signals  
t0 = mdaqDSPRead(2, vectorSize, vectorCount, timeout); <-- samples from time t0 
t0 = mdaqDSPRead(3, vectorSize, vectorCount, timeout); <-- samples from time t0

//------ DATA LOSS ----
t0 = mdaqDSPRead(1, vectorSize, vectorCount, timeout); <-- first data request, recv samples from time t0, for all signals  
t1 = mdaqDSPRead(1, vectorSize, vectorCount, timeout); <-- second data request, recv samples from time t1, for all signals  
t1 = mdaqDSPRead(2, vectorSize, vectorCount, timeout); <-- samples from time t1 
t1 = mdaqDSPRead(3, vectorSize, vectorCount, timeout); <-- samples from time t1

Arguments

Examples

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:

xcos(mdaqToolboxPath() + filesep() + "examples" + filesep() +"dsp_rw_demo.zcos");

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");

See Also


Report an issue
<< mdaqDSPIsDone DSP managment mdaqDSPStart >>