S-Function Crashes MatLab when "ssSetInpu​tPortRequi​redContigu​ous" is used

3 vues (au cours des 30 derniers jours)
Bettina
Bettina le 23 Jan 2014
Hello everybody,
I try to get used to Simulink C-Code S-Functions and I have done a little test coding. Everything worked, but when I use the "ssSetInputPortRequiredContiguous" MatLab crashes completely. As I have not so deep knowledge of C-Code, perhaps someone can help me?
Here is my code - it only works, when I disable line 15
#define S_FUNCTION_NAME myfunc3_1
#define S_FUNCTION_LEVEL 2
#include <simstruc.h>
#include "math.h"
extern real_T myfunc(real_T x); //external function "myfunc" just calculates the square-root
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 0);
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 2);
ssSetInputPortDirectFeedThrough(S, 0, 1);
ssSetInputPortDataType(S, 0, SS_DOUBLE);
ssSetInputPortRequiredContiguous(S, 0, true); //<= this is the line, that crashes Matlab!
ssSetOutputPortWidth(S, 0, 2);
ssSetOutputPortVectorDimension(S, 0, 2);
ssSetOutputPortDataType(S, 0, SS_DOUBLE);
ssSetOutputPortWidth(S, 1, 1);
ssSetOutputPortDataType(S, 1, SS_DOUBLE);
ssSetNumSampleTimes(S, 1);
}
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0);
}
static void mdlOutputs(SimStruct *S, int tid)
{
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
real_T *y0 = ssGetOutputPortRealSignal(S,0);
int_T width = ssGetOutputPortWidth(S,0);
real_T *y1 = ssGetOutputPortRealSignal(S,1);
y0[0] = *uPtrs[0];
y0[1] = *uPtrs[1];
*y1 = myfunc(*uPtrs[0]);
}
static void mdlTerminate(SimStruct *S)
{
UNUSED_ARG(S); /* unused input argument */
}
#ifdef MATLAB_MEX_FILE
#include "simulink.c"
#else
#include "cg_sfun.h"
#endif
When I mexed this and run the Simulink model, where this s-function is implemented, the result is: "Matlab has encountered an internal problem and needs to close". Details:
MATLAB crash <file:C>:\Users\...\AppData\Local\Temp\matlab_crash_dump.5252-1:
------------------------------------------------------------------------ Segmentation violation detected at Thu Jan 23 13:10:15 2014 ------------------------------------------------------------------------
Configuration: Crash Decoding : Disabled Default Encoding: windows-1252 MATLAB Root : C:\Program Files\MATLAB\R2012b MATLAB Version : 8.0.0.783 (R2012b) Operating System: Microsoft Windows 7 Processor ID : x86 Family 6 Model 42 Stepping 7, GenuineIntel Virtual Machine : Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot™ 64-Bit Server VM mixed mode Window System : Version 6.1 (Build 7601: Service Pack 1)
Fault Count: 1
Abnormal termination: Segmentation violation
Register State (from fault): RAX = 00000000a2049d60 RBX = 00000000a23f3350 RCX = 00000000a22671e0 RDX = 4022000000000000 RSP = 00000000040481e0 RBP = 00000000a2049e48 RSI = 00000000a2165070 RDI = 00000000a2166f60
R8 = 00000000a23f3330 R9 = 00000000a23f3340
R10 = 0000000000000004 R11 = 00000000a2049e48
R12 = 000000000000127f R13 = 00000000a17fa1e0
R14 = 0000000000000004 R15 = 0000000074ee93b0
RIP = 000007fef65c1063 EFL = 00010202
CS = 0033 FS = 0053 GS = 002b
Stack Trace (from fault): [..] This error was detected while a MEX-file was running. If the MEX-file is not an official MathWorks function, please examine its source code for errors. Please consult the External Interfaces Guide for information on debugging MEX-files.
If this problem is reproducible, please submit a Service Request via: http://www.mathworks.com/support/contact_us/
A technical support engineer might contact you with further information.
Thank you for your help.
Has someone an idea, what my fault is? Thanks in advance!!! Best Regard, Bettina

Réponses (0)

Catégories

En savoir plus sur Simulation dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by