When I run a s-function block generated by legacy code tool, matlab system error dialog will be show up. Why?

5 views (last 30 days)
Hello all,
I am new to creat S-functions from C code and also not good at c coding. I use the Legacy Code Tool to incorporate my code. It can be compiled successfully. Then i used "legacy_code('slblock_generate',def)" command to generate the block. However, when I tried to run it, the matlab system error dialog was show up.
Your help is much appreciated!
Liwa
-------------------------- putcmda.h ---------------------------------
#ifndef PUTCMDA_H_
#define PUTCMDA_H_
//put command acknowledge for a specific command to the output buffer
void putcmda(char* const out, int cmd_no);
#endif
-------------------------- putcmda.c ---------------------------------
#include <stdio.h>
#include <string.h>
#include "putcmda.h"
#define NUM_CMD 4 //number of commands (STR_CMDS)
#define MAX_CMD_LEN 6 //max length of commands (STR_CMDS)
#define STR_CMDS {"start","stop","info","get"}
const char cmd[NUM_CMD][MAX_CMD_LEN] = STR_CMDS;
#define STR_CMD "cmd"
#define STR_CMD_ACK "cmd_ack"
//*****************************************************************************
//
void putcmda(char* const out, int cmd_no)
{
if(cmd_no > 0 && cmd_no <= NUM_CMD)
{
strcpy(out, "{\"");
strcpy(out + strlen(out), STR_CMD_ACK);
strcpy(out + strlen(out), "\":\"");
strcpy(out + strlen(out), cmd[cmd_no -1]);
strcpy(out + strlen(out), "\"}");
}
else *out = '\0';
}
-------------------------- LCT SCRIPT ---------------------------------
def = legacy_code('initialize');
% Populate the data struture
def.SourceFiles = {'putcmda.c'};
def.HeaderFiles = {'putcmda.h'};
def.SFunctionName = 'legacy_pcasfcn';
def.OutputFcnSpec = 'putcmda(uint8 u1, uint8 y1[30])';
def.SampleTime = [-1,0];
% Generate the S-function
legacy_code('sfcn_cmex_generate', def);
% Compile the MEX-file
legacy_code('compile', def);
% Generate a TLC-file
legacy_code('sfcn_tlc_generate', def);
-------------------------- System ERROR --------------------------------

Accepted Answer

Liwa
Liwa on 12 Feb 2014
I found the error. In the LCT script, it should be def.OutputFcnSpec = 'putcmda(uint8 y1[30], uint8 u1)'. Thank you all.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!