1

在过去的几天里,我在 Scicoslab 中遇到了一个难以理解的问题。
我一直在用 C 语言为 scicos 编写一些通信块(将数据发送到外部应用程序),然后用它自己的代码包装它们。问题是,即使代码正常工作(我已经检查了所有可能的输出),scicos 也会给我这个错误消息:sicosim: error. Type 0 not yet supported by outtb. 错误屏幕截图


这是 Sensor Dispatcher Block 的 c 函数的代码:

    int bro_sens_send (scicos_block *block)
{
    int rc, i;
    bro_fist_t packet[BUFFER_SIZE];

    for (i = 1; i < block->nin; i++) {
        bro_encode_sci_datablock(&packet[i-1], block->inptr[i]);
    };

    printf ("Data for first block: %i, %i, %.2f\n", packet[0].port, packet[0].operation, packet[0].data);

    rc = send(block->inptr[0][0], packet, sizeof(bro_fist_t) * BUFFER_SIZE, 0);

    if (rc < 0)
    {
        perror("send() failed");
        return -1;
    }

    printf("%d bytes of data were sent\n", rc);
    return 0;
}

int bro_sens_read (scicos_block *block)
{
    int rc, i;
    bro_fist_t packet[BUFFER_SIZE];

    rc = recv(block->inptr[0][0], packet, sizeof(bro_fist_t) * BUFFER_SIZE, 0);
    printf("%d bytes of data were received\n", rc);
    if (rc < 0)
    {
        perror("recv() failed");
        return -1;
    }

    printf("Starting to set outputs :3 [%i]\n", block->nout);

    for (i = 0; i < block->nout; i++) {
        printf("Next Step defining outputs :D [%i]\n", i);
        bro_decode_sci_datablock(&packet[i], &block->outptr[i][0]);
        printf("Output value for port %i is: %.2f[%i]\n", i, block->outptr[i][0], block->outsz[(2*block->nout)+i]);

    }

    return 0;
}

void bro_comm_sens_disp (scicos_block *block, int flag)
{
    switch (flag) {
        case 1: /* set output */
            bro_sens_send(block);
            bro_sens_read(block);
            break;
        case 2: /* get input */
            break;
        case 4: /* initialisation */
            break;
        case 5: /* ending */
            break;
        default:
            break;
    }
}


这是块定义的代码(在 scilab 代码中):

function [x,y,typ] = SENS_Disp(job,arg1,arg2)
    x=[];y=[];typ=[];
    select job
    case 'plot' then
        exprs=arg1.graphics.exprs;

        standard_draw(arg1)
    case 'getinputs' then
        [x,y,typ]=standard_inputs(arg1)
    case 'getoutputs' then
        [x,y,typ]=standard_outputs(arg1)
    case 'getorigin' then
        [x,y]=standard_origin(arg1)
    case 'set' then
        x=arg1
        model=arg1.model;graphics=arg1.graphics;
        exprs=graphics.exprs;
    case 'define' then
        model       = scicos_model()
        model.sim   = list('bro_comm_sens_disp',4)
        model.out   = [1;1;1;1;1;1;1]
        model.out2  = [1;1;1;1;1;1;1]
        model.outtyp= [1;1;1;1;1;1;1]
        model.in    = [1;3;3;3;3;3;3;3]
        model.in2   = [1;1;1;1;1;1;1;1]
        model.intyp = [3;1;1;1;1;1;1;1]
        model.evtin = []
        model.rpar  = []
        model.ipar  = []
        model.dstate=[1];
        model.blocktype='c'
        model.dep_ut=[%t %f]
        exprs=[]
        gr_i=['xstringb(orig(1),orig(2),[''Sensors'';+''Dispatcher''],sz(1),sz(2),''fill'');']
        x=standard_define([3 2],model,exprs,gr_i)
    end
endfunction


该块的第一个输入端口是用于通信的套接字描述符,而其他七个连接到设置块。输出返回从外部应用程序接收到的数据。我尝试浏览 Scilab 代码,并且我了解到我收到的错误告诉我数据类型设置错误,但我已经检查过,但情况并非如此。
以下是输出错误的 Scicoslab 代码:

/*set vectors of outtb*/
                for (j=0; j<nlnk; j++) { /*for each link*/
                        subheader=(int *)(listentry(il_state_outtb,j+1)); /*get header of outtbl(j+1)*/
                        outtbsz[j]=subheader[1]; /*store dimensions*/
                        outtbsz[j+nlnk]=subheader[2];

                        switch (subheader[0]) { /*store type and address*/
                                /*matrix of double*/
                        case 1  :
                                switch (subheader[3]) {
                                case 0  :
                                        outtbtyp[j]=SCSREAL_N;  /*double real matrix*/
                                        outtbptr[j]=(SCSREAL_COP *)(subheader+4);
                                        break;

                                case 1  :
                                        outtbtyp[j]=SCSCOMPLEX_N;  /*double complex matrix*/
                                        outtbptr[j]=(SCSCOMPLEX_COP *)(subheader+4);
                                        break;

                                default :
                                        Scierror(888,\
                                                 "%s : error. Type %d of double scalar matrix not yet supported "
                                                 "for outtb.\n",\
                                                 fname,subheader[3]);
                                        FREE(outtbptr);
                                        FREE(outtbtyp);
                                        FREE(outtbsz);
                                        FREE(opar);
                                        FREE(oparsz);
                                        FREE(opartyp);
                                        FREE(oz);
                                        FREE(ozsz);
                                        FREE(oztyp);
                                        FREE(lfunpt);
                                        freeparam;
                                        FREE(outtb_elem);
                                        break;
                                }
                                break;

                                /*matrix of integers*/
                        case 8  :
                                switch (subheader[3]) {
                                case 1  :
                                        outtbtyp[j]=SCSINT8_N;  /*int8*/
                                        outtbptr[j]=(SCSINT8_COP *)(subheader+4);
                                        break;

                                case 2  :
                                        outtbtyp[j]=SCSINT16_N;  /*int16*/
                                        outtbptr[j]=(SCSINT16_COP *)(subheader+4);
                                        break;

                                case 4  :
                                        outtbtyp[j]=SCSINT32_N;  /*int32*/
                                        outtbptr[j]=(SCSINT32_COP *)(subheader+4);
                                        break;

                                case 11 :
                                        outtbtyp[j]=SCSUINT8_N; /*uint8*/
                                        outtbptr[j]=(SCSUINT8_COP *)(subheader+4);
                                        break;

                                case 12 :
                                        outtbtyp[j]=SCSUINT16_N; /*uint16*/
                                        outtbptr[j]=(SCSUINT16_COP *)(subheader+4);
                                        break;

                                case 14 :
                                        outtbtyp[j]=SCSUINT32_N; /*uint32*/
                                        outtbptr[j]=(SCSUINT32_COP *)(subheader+4);
                                        break;

                                default :
                                        Scierror(888,\
                                                 "%s : error. Type %d of integer scalar matrix not yet supported "
                                                 "for outtb.\n",\
                                                 fname,subheader[3]);
                                        FREE(outtbptr);
                                        FREE(outtbtyp);
                                        FREE(outtbsz);
                                        FREE(opar);
                                        FREE(oparsz);
                                        FREE(opartyp);
                                        FREE(oz);
                                        FREE(ozsz);
                                        FREE(oztyp);
                                        FREE(lfunpt);
                                        freeparam;
                                        FREE(outtb_elem);
                                        break;
                                }
                                break;

                        default :
                                Scierror(888,"%s : error. Type %d not yet supported for outtb.\n",fname,subheader[0]);
                                FREE(outtbptr);
                                FREE(outtbtyp);
                                FREE(outtbsz);
                                FREE(opar);
                                FREE(oparsz);
                                FREE(opartyp);
                                FREE(oz);
                                FREE(ozsz);
                                FREE(oztyp);
                                FREE(lfunpt);
                                freeparam;
                                FREE(outtb_elem);
                                return 0;
                                break;
                        }
4

1 回答 1

0

好的。经过很长时间,我已经解决了这个问题。有一个函数在错误的内存空间中设置了一个值。问题是没有任何错误消息或警告。问题出在执行此操作的函数中:

block->outptr[0][3] = 0;

在一个只有 3 个输出端口的块中。这在数据注册表中写入了错误的数据。删除后一切正常。

于 2010-08-25T13:22:29.180 回答