Adding Your Library to Library Browser - 2022.2 English

Vitis Model Composer User Guide (UG1483)

Document ID
UG1483
Release Date
2023-01-13
Version
2022.2 English

To use the imported blocks in your library, you can simply open the Simulink model of your library, and copy blocks into a new Model Composer model. However, if you want to see your library listed in the Library Browser, and be able to drag and drop blocks from the library into new models, after running the xmcImportFunction command you must prepare your library using the following process.

  1. Enable Library Browser parameter.
  2. Save the library.
  3. Create slblocks.m script for the library.
  4. Add path to MATLAB, or add library to MATLAB path.
  5. Refresh Library Browser.
Tip: Setting up the library using this process is only required for newly created libraries, rather than existing libraries which have already been setup.

To enable the library to be available in the Library Browser, you must turn on the EnableLBRepository parameter for the library. After importing a block into a new library using xmcImportFunction, with the library open, you must use the following command from the MATLAB command line prior to saving your library:

set_param(gcs,'EnableLBRepository','on');

This parameter identifies the library as belonging to the Library Browser. However, that is just the first step. Save the library by clicking File > Save from the main menu, or by clicking the button in the toolbar.

Libraries in the Library Browser also require the presence of a script in the same directory as the library model, called slblocks.m, that defines the metadata associated with the library. You can create this script by copying an existing script from another library, or copying it from the MATLAB installation, or by editing the following text and saving it as slblocks.m:
function blkStruct = slblocks 
  % This function adds the library to the Library Browser
  % and caches it in the browser repository

  % Specify the name of the library
  Browser.Library = 'newlib';
  % Specify a name to display in the library Browser  
  Browser.Name = 'New Library';

  blkStruct.Browser = Browser;
Notice the Browser.Library specifies the name of the library model minus the .slx file extension, and Browser.Name specifies the display name that will appear in Library Browser.
Note: Each library should appear in a separate directory, with the <library>.slx file and the slblocks.m script for that library.
After creating the library and the slblocks.m script, you need to either add the library location to the MATLAB path so that MATLAB can find it, or copy the library to a folder that is already on the MATLAB path. You can type path at the MATLAB command prompt to see the current path that MATLAB uses. You can also add the library directory to the MATLAB path using the following commands:
addpath ('library_folder')
savepath

Where:

  • 'library_folder'
  • savepath is a string that saves the current search path to pathdef.m.
Tip: To remove a folder from the MATLAB path you can use the following command sequence:
rmpath ('library_folder')
savepath

Finally, to view the new library in the Library Browser, from the left side of the Library Browser window right-click and select the Refresh Library Browser command. This will load the library into the tool. You should now be able to view the imported blocks and drag and drop them into your models.