How to get information of Code mappings elements?

조회 수: 5 (최근 30일)
Chuyen
Chuyen 2025년 2월 5일
편집: Harsh 2025년 5월 28일
Hello everyone,
I am developing a script to assign "Shortname" field in Property Inspector of a block as below script and it worked for me. However, I do not want to make "Mapped to" fixed as 'ArTypedPerInstanceMemory' and I changed it as mappingObj.mapSynthesizedDataStore('','','Shortname', objName); or even mappingObj.mapSynthesizedDataStore('Shortname', objName);. But after I changed it, the "Shortname" could not be objName as below script returned. Do you know any solutions to resolve this issue, only apply for Shortname, or are there any APIs I can get the information from Code Mappings?
if strcmp(blkType,'myblock')
mappingObj = autosar.api.getSimulinkMapping(mdlName);
try
mappingObj.addSynthesizedDataStore(objName);
mappingObj.mapSynthesizedDataStore(objName,'ArTypedPerInstanceMemory','Shortname', objName);
end
end
Thank you so much!

답변 (1개)

Harsh
Harsh 2025년 5월 28일
편집: Harsh 2025년 5월 28일
You're trying to dynamically assign the "Shortname" property to a synthesized data store in an AUTOSAR model without hardcoding the "Mapped To" type (e.g., 'ArTypedPerInstanceMemory'). The issue arises because omitting the mapping type causes the "Shortname" assignment to fail.
The solution is to first retrieve the existing mapping type and then reapply the mapping with the desired "Shortname".
1. Get the Simulink to AUTOSAR mapping object - Use the "autosar.api.getSimulinkMapping" function to access the AUTOSAR mapping for your model.This object allows you to query and modify AUTOSAR properties for Simulink elements.
mappingObj = autosar.api.getSimulinkMapping(mdlName);
2. Retrieve the current AUTOSAR variable type for the data store - Use the "getDataStore" function to get the current mapping type (e.g., 'ArTypedPerInstanceMemory') for the synthesized data store "objName".This ensures you preserve the existing mapping configuration.
arVarType = getDataStore(mappingObj, objName);
3. Reapply the mapping with the existing type and set the "Shortname" - Use the "mapDataStore" function to reassign the data store with the retrieved type and update the "Shortname" field.This avoids hardcoding the mapping type while still allowing you to customize the "Shortname".
mapDataStore(mappingObj, objName, arVarType, 'Shortname', objName);
Refer to the following documentation pages for the APIs mentioned in above answer:

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by