I don't find the way to get the string specified in the dialog box of an S-function (C, level 2) block and save it in a variable, inside the .c file corresponding to the block.
Through *mxGetPr(ssGetSFcnParam(S, 0)) I can only get the first position value in the string. The parameter entered in the dialog block what it is related to the ssGetSFcnParam(S, 0) is '123'. In the mask editor of the block the type is 'edit'.
#define S_FUNCTION_NAME ver_file_data #define S_FUNCTION_LEVEL 2 #define NPARAMS 14 #define DVC_TYPE(S) ssGetSFcnParam(S, 0) static void mdlInitializeSizes(SimStruct *S){ DECL_AND_INIT_DIMSINFO(outputDimsInfo); ssSetNumSFcnParams(S, NPARAMS); /* Number of expected parameters */ ssSetSFcnParamTunable(S, 0, 0); ssSetSFcnParamTunable(S, 1, 0); #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; } #endif ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, NUM_INPUTS)) return; if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return; /* Output Port 0 */ ssSetOutputPortWidth(S, 0, 1); ssSetOutputPortDataType(S, 0, SS_UINT8); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); } static void mdlInitializeSampleTimes(SimStruct *S){ ssSetSampleTime(S, 0, -1); ssSetOffsetTime(S, 0, 0.0); } static void mdlOutputs(SimStruct *S, int_T tid){ ssPrintf("DVC_IND_NO = %x\n",*mxGetPr(DVC_IND_NO(S))); } mdlRTW (SimStruct *S){ }
Before getting anything through the outputport, I would like to be able to print with ssPrintf("DVC_IND_NO = %x\n",*mxGetPr(DVC_IND_NO(S))); the 123.
Thank you, best regards.
mxGetPr returns a pointer to double
, so makes no sense if the parameter is a char
array. And in using *mxGetPr
you are saying that you want the value that is pointed to (i.e. the first element, if it is a multi-element double
array), which is why you are only getting the first value.
If the input is expected to be a string (i.e. array of char
) then you should be using mxArrayToString to access it.
Either way, you should definitely be using helper functions like mxIsChar and mxIsDouble to check the data type before using the appropriate function to access the data.