[Scilab-users] Creating C function blocks in scilab 5.5.2

classic Classic list List threaded Threaded
1 message Options
Steve Steve
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Creating C function blocks in scilab 5.5.2

Hello,

I have been using scilab version 5.5.2 (64 bit) under Windows 7 (64 bit).
For current project I need to be able to create xcos blocks wich behavior
is prescribed by my own C language source code. I have found following
excellent tutorial  https://www.scicos.org/ScicosCBlockTutorial.pdf
<https://www.scicos.org/ScicosCBlockTutorial.pdf>  .

At first I have installed the MinGw toolbox 0.9.3. The installation seems
to be successful because the function haveacompiler returns true. Then I
have written the source code according to the above mentioned tutorial

// This is the computational function for a scicos model block.
    // The model is of a variable-gain integrator with hard high and low
limits.
   
        #include "c:\Program
Files\scilab-5.5.2\modules\scicos_blocks\includes\scicos_block4.h"
        #include <math.h>
        #include <stdio.h>
        #include <stdlib.h>
       
        #define r_IN(n, i) ((GetRealInPortPtrs(blk, n+1))[(i)])
        #define r_OUT(n, i) ((GetRealOutPortPtrs(blk, n+1))[(i)])
       
        // parameters
        #define Lhi (GetRparPtrs(blk)[0]) // integrator high limit
        #define Llo (GetRparPtrs(blk)[1]) // integrator low limit
       
        // inputs
        #define in (r_IN(0,0)) // integrator input
        #define gainp (r_IN(1,0)) // integrator gain when x > 0
        #define gainn (r_IN(2,0)) // integrator gain when x <= 0
       
        // states
        #define X (GetState(blk)[0]) // integrator state
        #define Xdot (GetDerState(blk)[0]) // derivative of the integrator
output
       
        // outputs
        #define out (r_OUT(0,0)) // integrator output
        #define Igain   (r_OUT(1,0)) // integrator gain
       
        // other constants
        #define surf0 (GetGPtrs(blk)[0])
        #define surf1 (GetGPtrs(blk)[1])
        #define surf2 (GetGPtrs(blk)[2])
        #define mode0 (GetModePtrs(blk)[0])
       
        // if X is greater than Lhi, then mode is 1
        // if X is between Lhi and zero, then mode is 2
        // if X is between zero and Llo, then mode is 3
        // if X is less than Llo, then mode is 4
        #define mode_xhzl 1
        #define mode_hxzl 2
        #define mode_hzxl 3
        #define mode_hzlx 4
       
        void lim_int(scicos_block *blk, int flag)
        {
        double gain = 0;
       
        switch(flag)
        {
        case 0:
        // compute the derivative of the continuous time state
        if((mode0 == mode_xhzl && in < 0) || mode0 == mode_hxzl)
        gain = gainp;
        else if((mode0 == mode_hzlx && in > 0) || mode0 == mode_hzxl)
        gain = gainn;
        Xdot = gain*in;
        break;
       
        case 1:
        // compute the outputs of the block
        if(X >=Lhi || X <= Llo)
        Igain = 0;
        else if (X > 0)
        Igain = gainp;
        else
        Igain = gainn;
        out = X;
        break;
       
        case 9:
        // compute zero crossing surfaces and set modes
        surf0 = X - Lhi;
        surf1 = X;
        surf2 = X - Llo;
       
        if(get_phase_simulation() == 1)
        {
        if(surf0 >= 0)
        mode0 = mode_xhzl;
        else if(surf2 <= 0)
        mode0 = mode_hzlx;
        else if(surf1 > 0)
        mode0 = mode_hxzl;
        else
        mode0 = mode_hzxl;
        }
        break;
        }
        }

After that I have called the function `ilib_for_link` with following
arguments `ilib_for_link('lim_int','lim_int_comp.c',[],"c")`

The function returns following output:

ilib_for_link('lim_int','lim_int_comp.c',[],"c")
       Generate a loader file
       Generate a Makefile
       Running the Makefile
       Compilation of lim_int_comp.obj
       Building shared library (be patient)
     
    !------------- Compile file lim_int_comp.c --------------                              
!
    !                                                                                      
!
    !x86_64-w64-mingw32-gcc.exe -c -DWIN32 -D_MSC_VER -DSTRICT -DFORDLL
-I"C:/PROGRA~1/SCILAB!
    !     ~1.2/libs/MALLOC/includes"
-I"C:/PROGRA~1/SCILAB~1.2/modules/core/includes" -I"C:/P!
    !     ROGRA~1/SCILAB~1.2/modules/api_scilab/includes"
-I"C:/PROGRA~1/SCILAB~1.2/modules/c!
    !     all_scilab/includes"
-I"C:/PROGRA~1/SCILAB~1.2/modules/output_stream/includes" -I"C!
    !     :/PROGRA~1/SCILAB~1.2/modules/jvm/includes"
-I"C:/PROGRA~1/SCILAB~1.2/modules/local!
    !     ization/includes"
-I"C:/PROGRA~1/SCILAB~1.2/modules/dynamic_link/includes" -I"C:/PR!
    !     OGRA~1/SCILAB~1.2/modules/mexlib/includes"
-I"C:/PROGRA~1/SCILAB~1.2/modules/time/i!
    !     ncludes" -I"C:/PROGRA~1/SCILAB~1.2/modules/windows_tools/includes"
-I"C:/PROGRA~1/S!
    !     CILAB~1.2/libs/f2c" -I"C:/PROGRA~1/SCILAB~1.2/libs/hashtable"
-I"C:/PROGRA~1/SCILAB!
    !     ~1.2/libs/intl" -m64   lim_int_comp.c                                            
!
    !                                                                                      
!
    !lim_int_comp.c: In function 'lim_int':                                                
!
    !                                                                                      
!
    !lim_int_comp.c:76:7: warning: implicit declaration of function
'get_phase_simulation' [-!
    !     Wimplicit-function-declaration]                                                  
!
    !                                                                                      
!
    !    if(get_phase_simulation() == 1)                                                    
!
    !                                                                                      
!
    !       ^~~~~~~~~~~~~~~~~~~~                                                            
!
    !                                                                                      
!
    !------------- Link files --------------                                                
!
    !                                                                                      
!
    !x86_64-w64-mingw32-gcc.exe --shared lim_int_comp.o
-L"c:\cygwin64\x86_64-w64-mingw32\li!
    !     b"
-LC:\Users\Stepan\AppData\Roaming\Scilab\scilab-5.5.2\mingwlib_x64 -lstdc++
-lgf!
    !     ortran -lMALLOC -lblasplus -lf2c -llapack -lcore -lcore_f
-lintersci -loutput_strea!
    !     m -ldynamic_link -linteger -loptimization_f -ljvm
-lscilocalization -lintl -llinpac!
    !     k_f -lcall_scilab -ltime -lapi_scilab -lscilab_windows -lscicos
-lscicos_blocks -ls!
    !     cicos_blocks_f -lscicos_f -o liblim_int.dll
-Wl,--out-implib=liblim_int.a -Wl,--ex!
    !     port-all-symbols -Wl,--enable-auto-import -Wl                                    
!
    !                                                                                      
!
    !x86_64-w64-mingw32-gcc.exe: error: unrecognized command line option
'-Wl'; did you mean !
    !     '-W'?                                                                            
!
    !                                                                                      
!
    !Makelib:102: recipe for target 'liblim_int.dll' failed                                
!
    !                                                                                      
!
    !make: *** [liblim_int.dll] Error 1                                                    
!
     !--error 10000
    ilib_compile: Error while executing Makelib.
    at line      25 of function dlwCompile called by :  
    at line      51 of function ilib_compile called by :  
    at line      94 of function ilib_for_link called by :  
    ilib_for_link('lim_int','lim_int_comp.c',[],"c")

It seems to me that the problem is that prototype for get_phase_simulation
function is
missing. Has anybody already encountered this problem? Thanks for any
suggestions.



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users