How to "Create new data" for a custom library block

Hello all,
I am creating a custom library block for my project which I followed mask concept as Unit delay block. However, I got some difficulties on creating New data for my state variable. Currently, I can only create a state variable which will be stored in data dictionary by default; however, I would like to create as following Unitdelay concept. But I could not find any documents which introduced how to do these stuffs for custom library block.
Or whether are there any Parameter options available for creating this on Mask Editor? Please give me some hints here. Thank you so much!

4 comentarios

Can you illustrate with an example of what your unit delay block does? and try to explain your use case as well.
Chuyen
Chuyen el 4 de Dic. de 2023
Editada: Chuyen el 4 de Dic. de 2023
Hello Madhan, I am not sure the image I attached from the begginning was clear or not because I am new to use this page. The unit delay I used is the native Simulink block. Now I would like to find the way to imitate that concept for my custom library block.
Currently, I have a library block I have created by myself which had the mask including state name; however, that state variable will be stored in data dictionary for global access. Now I want to migrate this location to Model workspace as Matworks concept. And I found out that the Unit delay block has "State Attributes" tab in its mask similar as I expected. That is why I want to refer it but do not know any references. Hope it is clear for you. Thank you for taking a look at this and waiting for you feedback.
sorry I haven't worked with data dictionary yet, so can"t help you
Chuyen
Chuyen el 5 de Dic. de 2023
Editada: Chuyen el 5 de Dic. de 2023
Anyway, thank you for addressing here. I am still finding some sources which introduce that but there is nothing so far. Not sure Mathworks supports to manupilate it programatically.

Iniciar sesión para comentar.

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 5 de Dic. de 2023
Editada: Fangjun Jiang el 5 de Dic. de 2023
Create a Mask for your customized library block, then when you double click the block, you will have a dialog to specify that parameter, just like the dialog you got when double click the UnitDelay block. The built-in "three dot action button" always appears on the side. Click the button and you will see the "Create variable" or "ParameterName: Create ..." option.

13 comentarios

Fangjun, just to understand. State Name is just a like Identifier name of the block?
Fangjun Jiang
Fangjun Jiang el 6 de Dic. de 2023
Editada: Fangjun Jiang el 6 de Dic. de 2023
Good point, @madhan ravi. State name is different than a typical parameter.
  1. State name is optional and can be left blank. The user can specify a name and a Simulink.Signal object to control the code generation variable name and properties.
  2. For a typical parameter, the user can specify MyParam=1 or MyParam=Simulink.Parameter(1). It will be passed to inside the mask InternalParam=MyParam. But for a State name, it does not work that way. The Simulink.Signal object name has to match the State name, but the State name can't be passed.
  3. Maybe the OP is having difficulty masking this "parameter" because it is a variable name. When it applies to a library block, it may require calling set_param() to change the name inside the mask dynamically. It also involves "parameterized library link".
+1, thank you Fangjun for explaining the actual issue in lamens terms :)
Chuyen
Chuyen el 8 de Dic. de 2023
Hello @Fangjun Jiang, thank you for answersing my query. However, my customized library was created to have "three dot action" connecting directly to create a new variable in sldd. Because my model always includes sldd and mdlwsp at the same time. Actually, in my block, there was a state name box which also includes "three dot action", but now I want it can be similar as Unit delay block which has option to connect to Model Workspace. Hope it clear for you.
Chuyen
Chuyen el 8 de Dic. de 2023
An example for my current state variable:
What I configged it in Mask Editor is Promote type:
Do you have any ideas on it?
Fangjun Jiang
Fangjun Jiang el 8 de Dic. de 2023
Editada: Fangjun Jiang el 8 de Dic. de 2023
Okay, so the question is really about why you see different options regarding data source (model workspace, base workspace, sldd) when you click the "three dot action" button.
The three options should always be available for new variables (two options if SLDD is not used). Try a new UnitDelay block or a new instance of your customized library block. Make sure the "enable model access to base workspace" option is checked at the model properties, "external data" tab.
For existing variables, I guess the option is limited (or constrained) to the current data source, because it wants to keep it consistent.
At your dialog showing "T3", try to change it to a new name, "T4", click apply and then click the "three dot action" button, you should see three data source options available.
Chuyen
Chuyen el 11 de Dic. de 2023
Hello Fangjun, I have tried your solution with some diffirent trials but it seems not worked as expected. Even I changed both checking "enable model access to base workspace" option and change the name of state varibale, the three dot is still only sldd (data dictionary).
By default, my model will be created and include data dictionary, so it will automatically connect to sldd. However, I could not see any option from mask editor which will support in background to connect to model workspace.
It seems to me "T4" already exists in the SLDD. The variable has to be new to have multiple options.
If you need further help, please create a simple example model in R2022b to demonstrate the issue and attach the mode.
Chuyen
Chuyen el 11 de Dic. de 2023
Thank you Fangjun for supporting me on this point. The reason here that we have a system to create a new model with sldd and that's why has this issue. I can attach model here but the background script for running it will be very big. I will try to demonstrate by myself.
If "T4" is automatically created in SLDD by a callback function, then it explains why you always see SLDD as the only option.
The function to create a variable in base workspace is assignin('base', VarName, VarValue).
Chuyen
Chuyen el 13 de Dic. de 2023
Editada: Chuyen el 13 de Dic. de 2023
maybe it's not I meant, I want this "T4" will be in Model workspace, not in base workspace. And of cource, I have a script to put it in sldd, but Model workspace will be a different story. That's why I want to refer Unit delay state name structure.
For new variables, the model workspace option should always be there.
There is API for model workspace too.
Chuyen
Chuyen el 14 de Dic. de 2023
Thank you so much. I will take a look

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink en Centro de ayuda y File Exchange.

Productos

Versión

R2023b

Etiquetas

Preguntada:

el 4 de Dic. de 2023

Comentada:

el 14 de Dic. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by