How can I write to a XCP parameter using Canoe .XCP and CAPL? - canoe

How can I write to an XCP parameter using Canoe .XCP and CAPL script? We can measure these parameters but can not change them, is it even possible?

CANoe creates a system variable for each .XCP parameter.
You setup the parameters in the XCP/CCP window.
In CAPL you can read and write the value of the parameters by accessing the corresponding system variables. Just check the symbol explorer. The system variables should all be in namespace XCP.
So changing the parameter a0 of device XcpSim in CAPL would be something like
#XCP::XcpSim::a0 = 17;
This example is taken directly from the CANoe documentation.

Related

Simulink code generation: set tunable parameters programmatically

I use Simulink Coder to generate code from a huge model. I use a rsim target with tunable parameters to be able to give the executable variable inputs via a parameter file.
I can specify which model parameters should be tunable (by default all parameters will be in-lined in generated code on compile time) via the code generation settings:
code generation options > optimization > signals and parameters > configure default parameter behavior
Here I can manually choose from all workspace variables the ones I want to be globally tunable:
Q: Is there a way to add a variable (given its name) to this list programmatically?
For example if a have list of 50 variables i would want to add them to the tunables list, via a MATLAB script without having to add every single one manually. Or loop over the list and set the tunable setting on each one.
I can generate a parameter struct which contains a list of tunable parameters using rsimgetrtp('model_name'). But I was not able to find a function to actually set the parameters in the first place.
I use Matlab 2015b for this, since its legacy code.

Access to "hidden" variables in Simulink

Some example models that are included in the Simulink library, include some variables that their value is not visible. For instance, in the model power_PVarray_grid_det the sample time of the powergui is defined as Ts_Power. I can not figure out the value of this variable. Is there a way to find these hidden variables, have access to them and change their value?
Thanks in advance

How to programmatically configure the tunability of model parameters?

I'm porting a large Simulink model from Simulink R2010a → R2017b.
The main model is basically a glue-layer for many interwoven reference models. My objective is to generate a standalone executable out of this main model using Coder.
Parameter tunability in this context is not done via the Signals and Parameters section on the Optimization tab in the Model Configuration Parameters dialog (as is the case in stand-alone models), but rather, via constructing Simulink.Parameter objects in the base workspace, and referencing those in the respective referenced models, or in their respective model workspaces.
Now, AFAIK, in R2010a it was enough to set
new_parameter.RTWInfo.StorageClass = 'Auto';
new_parameter.RTWInfo.CustomStorageClass = 'Define';
to make the parameter non-tunable and convert it into a #define in the generated code. In R2017b, this is no longer allowed; the StorageClass must be 'Custom' if you set a non-empty CustomStorageClass:
new_parameter.CoderInfo.StorageClass = 'Custom'; % <- can't be 'Auto'
new_parameter.CoderInfo.CustomStorageClass = 'Define';
But apparently, this does not make the parameter non-tunable:
Warning: Parameter 'OutPortSampleTime' of '[...]/Rate Transition1' is non-tunable but refers to tunable variables (Simulation_compiletimeConstant (base workspace))
I can't find anything in the R2017b documentation on making parameters non-tunable, programatically; I can only find how to do it in stand-alone models via the dialog, but that's not what I want here.
Can anyone point me in the right direction?
NOTE: Back in the day, Simulink Coder was called Real-Time Workshop (well, Real-time Workshop split into Coder and several other things), hence the difference RTWInfo vs. CoderInfo. Note that RTWInfo still works in R2017b, but issues a warning and gets converted into Coderinfo automatically.
In generated code it should appear as #define, the way you specified it.
https://www.mathworks.com/help/rtw/ug/choose-a-built-in-storage-class-for-controlling-data-representation-in-the-generated-code.html
Btw, yes, it's a bit confusing, because in m-file you specify CustomStorageClass = 'Define';, in GUI you specify Storage class as Define (custom), but in documentation they say Storage Class as Defined.
I am not sure why warning about tunability shows up.

Experiment annotation in Dymola/Modelica

I am trying to change the simulation settings(startTime,stopTime,Interval) for an experiment based on the size of the external file that is presented to the model.
Experiment annotation allows one to set these simulation settings like this,
annotation(Experiment(startTime=0,stopTime=10,Interval=500));
Now I am trying to set these values based on a parameter declared in the same model. This parameter basically scans the external file to find its size. Modelica doesn't recognize the following declaration of the same annotation?
model ExperimentAnnotation
parameter Integer start = 0;
parameter Integer stop = 10;
parameter Integer size = 100;
equation
annotation(Experiment(startTime=start,stopTime=stop,Interval=size));
end ExperimentAnnotation;
Is there a work around for this? Kindly advise.
Thanks.
Using non-literal values for the startTime-annotation etc is not legal Modelica - according to section 18.4; and not supported in Dymola.
As I understand it the parameter doesn't have a literal value in the model, but the parameter-value is based on reading some file.
In Dymola you could use "Add Command" to add a script-command that reads the external file and then calls simulateModel with the correct values.

Get parameter values from .m-file into GUI

To keep it short, I'm developing a software tool where I would like to import
parameters into GUI from .m-files, but I can't find how to import the parameters.
I'm using iugetfile to 'reach it' but how do I insert the parameter values?
If I open the file in MATLAB (command window), then I get the parameters in
the workspace. Is there an easy way to read the parameters into GUI to be able
to use them in functions there?
The way to write data into gui is using set. For example: set(handles.,'String','content'). You can see examples of writing and reading values from here: (mathworks link)
I would use .mat instead .m if you need to read parameter values.