In Simulink R2011a, Data Store blocks have been improved to support bus signals and more. To give you a quick idea, these enhancements can transform the syntax you are used to on the left to what you see on the right! This new syntax simplifies the model and the generated code. In this post I will show you some of the new capabilities that make this possible.
Data Stores can now be used with buses! To connect a nonvirtual bus signal to a data store, all you have to do is specify the name of the bus object in the Data Type field of the Data Store Memory block:
Optionally, you can also specify a MATLAB structure as the bus initial value. I recommend using the function Simulink.Bus.createMATLABStruct or the Bus Editor to generate the MATLAB structure from a bus object.
Accessing specific elements of a bus or a array
Before R2011a, Data Store Write and Data Store Read blocks had only one port. With this port, you could write or read the entire memory region.
While implementing bus support, we added the option to write or read specific elements of a bus or an array. To allow this, a new Element Assignment tab has been added to the Data Store Read and Data Store Write blocks. Using this tab, you can select the components of the bus you want to write or read.
Let's look at an example. Once I have created bus object and configured the Data Store Memory block to use it, I open the dialog of a Data Store Read or Write block and select the Element Assignment tab. For this example, I decide to write the second column of element A.b.b1 and the 4th element of A.b.b2.
Configured that way, the Data Store Write and Data Store Read have one port per assigned element, and the names of the selected elements are displayed on the blocks. Here is what a simple model looks like:
If you generate code for the model, you will notice that this way to read and write memory is efficient, avoiding extra data copies.
To learn more about this feature, look at the documentation titled Accessing Specific Bus and Matrix Elements. You will find out that it supports the previously existing features of buses and data store, including global data store, access from the MATLAB Function block and arrays of buses.
Now it's your turn
Did you have a need to pass bus signal through data store in the past? Are you going to take advantage of this feature? Let us know by leaving a comment here.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.