<< Introduction C/C++ code integration mdaqBlock >>

MicroDAQ toolbox >> MicroDAQ toolbox > C/C++ code integration > Custom 'My step' Xcos block for MicroDAQ

Custom 'My step' Xcos block for MicroDAQ

This guide shows how to build custom Xcos block which can be used for code generation and host simulation mode

Defining block functionality

Before MicroDAQ Xcos block creation a requirements defining functionality and block interface has to be defined. Our new block will be described by the following properties:

Our custom block will be named 'My_step', it has three parameters 'Step time', 'Initial value', 'Final value' and 'Terminate value'. All block parameters are scalars, and has default values: 'Step time' - 1, 'Initial value' - 0, 'Final value' - 1, 'Terminate value' - 0. Block shall have one output port, output port size is 1. Block doesn't have input ports.

Custom 'Step' block step by step

'My_step' block in simulation mode

If block.use_sim_script is set to false (%F - by default) then C source will be compiled to shared library which will be used in simulation mode. It guarantees the same code on host (simulation mode) and target (code generation) side. In order to use this option the external C compiler is required. List of supported compilers can be found at: https://help.scilab.org/doc/5.5.2/en_US/supported_compilers.html. If compiler cannot be provided or user want to have different behaviour in simulation mode, the _sim.sci script can be used instead.

Generated block files can be used to implement block code for standard simulation mode. In order to add code for simulation mode generated mdaq_my_step_sim.sci file needs to be edited. The mdaq_my_step_sim.sci file contains code which will be executed in simulation mode. Function mdaqBlockAdd() generates file which contains block parameters variables which has to be used to change block output.

Generated mdaq_my_step.sci file:

// Generated with MicroDAQ toolbox ver: 1.1.
function block=mdaq_my_step_sim(block, flag)

    global %microdaq
    if %microdaq.dsp_loaded == %F then

        step_time = block.rpar(1);
        initial_value = block.rpar(2);
        final_value = block.rpar(3);
        terminate_value = block.rpar(4);
        select flag
        case -5 // Error
        case 0 // Derivative State Update
        case 1 // Output Update
        case 2 // State Update
        case 3 // OutputEventTiming
        case 4 // Initialization
        case 5 // Ending
        case 6 // Re-Initialisation
        case 9 // ZeroCrossing
        else // Unknown flag

Similar to C source file we have to add Scilab code which will be performing 'step' function.

Report an issue
<< Introduction C/C++ code integration mdaqBlock >>