When I run a s-function block generated by legacy code tool, matlab system error dialog will be show up. Why?
8 views (last 30 days)
Show older comments
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 --------------------------------
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Data Representation in Generated Code in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!