Quick Start Part 3

In part 2 of this tutorial, you implemented the logic for requirement #4 and used a stitch to connect it to your diagram for requirement #3 from part 1. Recall the list of requirements:

Note

Temperature Display Requirements:

  1. The Temperature Display shall have two temperature sensors, one outside sensor and one inside sensor, which read temperatures in Celsius as 32-bit floating point values.
  2. The display shall sample the sensor data and update every 100 milliseconds.
  3. The temperature °F shall be calculated from the temperature °C with the following equation: °F = °C × 9/5 + 32
  4. For each sensor the display shall indicate Sensor Broken if the temperature is greater than 150°F or less than -150°F.

All the software logic for a single sensor is now modeled, but requirement #1 specifies that there is both an indoor and an outdoor sensor. Ideally, the logic we modeled can be reused between the two sensors. CertSAFE makes this sort of reuse within a project very easy.

Just like in part 2, you can achieve this by using either a diagram or a stitch. In this case, both work well. However, when dealing with many variables or many instances, stitches may be easier to work with than diagrams. We’ll focus on doing this with diagrams first, then show how this can be done with stitches.

Reuse in diagrams

As a diagram, you could model the first requirement like this:

ALT

To model the above, start by creating a new diagram. Then go to the Projects view and drag the Process Sensor Data stitch from part 2 into the new diagram as a component. Repeat this one more time (or copy the component using right-click-and-drag) to get a second Process Sensor Data component. Then, connect the components up to different diagram inputs and outputs. You should give the indoor and outdoor copies distinct I/O names since the sensors are independent and can record different values.

Reuse in stitches

Let’s try building the same structure in a stitch. Create a new stitch and drag the Process Sensor Data stitch from the Projects view to the left-hand pane of the new stitch editor. Repeat this again to create two child units of type Process Sensor Data, as in the image below:

ALT

The stitch editor groups multiple child units of the same type together in the left-hand table. Notice that CertSAFE automatically appended a string of hexadecimal characters after the name. To differentiate the two definitions from each other, CertSAFE needs an unique identifier, called a child name. Every child unit in a diagram or stitch definition has a child name. If you have not assigned a child name to a child unit, CertSAFE will give that unit a default child name and append a hexadecimal number to the end of that child name that is unique within the parent diagram or stitch. CertSAFE will also append the unique hexadecimal number to the end of any child unit that shares a child name with anything else in the parent diagram or stitch. Setting an explicit child name yourself on a component isn’t necessary, but doing so can help clarify the structure of a model to other readers and make navigating the model easier.

In a diagram, you can change a component’s child name by selecting the component and editing the “Child name” property in the Properties view. In a stitch, you can change a child unit’s name by double-clicking on the name in the left-hand pane of the stitch editor. (Remember, child units are represented in the left-hand pane as rows with a blue background.) For this example, you can rename the child Process Sensor Data units to “Process Indoor Data” and “Process Outdoor Data” to help keep them straight.

Recall that there are two types of rows in the right-hand table: the top-level names with a light blue background, and the second-level entries with a white background. The top-level entries are variable names in the stitch itself. These are analogous to exported and non-exported names in diagrams, which is why these are the rows we have to mark as exported names of the stitch. The second-level entries are names of child I/Os, represented as (child name) ● (I/O name).

As we saw in part 2, the stitch editor automatically connects together child I/Os that have the same name by mapping them to a stitch-level variable with that name. In this case, CertSAFE has mapped both of the two °C inputs of the Process Sensor Data instances to “°C” and both of the two Sensor Broken outputs to “Sensor Broken”, which is not what we want. To create the desired connections in your stitch, you will need to use custom name mapping, specifying the new variable names and remapping the Process Sensor Data I/Os explicitly.

In our diagram above, we made up names like “°C Indoor” so that we had distinct identifiers for the inputs and outputs of the two sensors. You will want to do the same thing in your stitch. You can add a new variable name to your stitch by clicking the Add Var button at the bottom-right of the stitch editor and typing in a name. If you don’t see the Add Var button, try adjusting the width of the stitch editor window by making it wider.

ALT

Do this for each of the four I/Os, and mark them as Exported Names through the Properties view. Remember that you can copy symbols like “°C” from the requirements text or from other places in your project if you don’t want to look up how to type them. Also remember that you can select multiple variables at once to change all of them to Exported Names.

At this point, you have all the variables ready, but nothing is actually connected correctly. Your stitch should look like this:

ALT

Stitch variables shown in black are explicitly declared in the file on disk, while variables shown in gray only exist because some child I/O is mapped to them. Child I/Os shown in black are explicitly mapped to a custom name, while child I/Os shown in gray are automatically mapped to their default name. This helps you keep track of which parts of the stitch will need to be updated if other files in the project change.

To remap a child I/O to be connected to a different stitch variable, select the child I/O in the right-hand table and drag it over the stitch variable you want to map it to. For example, you will want to drag Process Indoor Data ● Sensor Broken onto Sensor Broken Indoor. Remember, stitch variables have a blue background, and child I/Os have a white background. The final stitch should look like this:

ALT

Save the stitch under the name “Process All Sensors”.

Instance navigation

With the Process All Sensors stitch complete, we can run a simulation to check that both sensors work correctly in the combined system. Create a new simulation with the Process All Sensors stitch as the simulation root. As usual, you can drag variable names in from the Instance view to add them to your simulation. Before you do that, though, expand the rows in your Instance tree so you can see the full structure of the system.

ALT

At this point, our model is starting to get a bit complicated. We now have four diagram instances total: an indoor and an outdoor instance for each of our two diagram definitions. If you double-click on a diagram or stitch row in the Instance view, CertSAFE will open that diagram or stitch in instance mode.

Up until now, you’ve probably been opening resources in the project through the Projects view. When you open a diagram or stitch through the Projects view, it opens in definition mode, which allows you to edit the definition of the resource and thereby modify all of its instances at once. In instance mode, on the other hand, you are looking at a particular instance of the diagram or stitch within the current root. You cannot edit while in instance mode; you have to switch back to definition mode to make changes, and then any changes you make will affect all instances of that definition. You can toggle between definition and instance mode in the editor for a diagram or stitch by pressing the “D/I” button at the top-left of the editor tab, or by pressing the ` (backtick) or ~ (tilde) key.

When in instance mode, the bar at the top of a diagram or stitch editor changes to a more complex control called the breadcrumbs bar that allows you to navigate the instance hierarchy. If you click on the drop-down arrow at the right side of the breadcrumbs bar, you can view a list of all the instances of the definition you are looking at. In this model, you can use the breadcrumbs bar drop-down to switch between the indoor and outdoor instances of each diagram or of the Process Sensor Data stitch.

ALT

You can also navigate up and down between instances inline in the editor by clicking on different parts of the path in the breadcrumbs bar. This works just like the path controls in Windows Explorer and other file manager programs, except instead of the file system you are navigating the instance hierarchy (which is the same tree you see in the Instance view).

ALT

You can also navigate down into a component in a diagram by mousing over it and clicking on the icon in the tooltip. This works in definition mode, too.

ALT

Canonical names

In instance mode, rather than displaying the name of a variable in a definition of a diagram, CertSAFE will show a canonical name based on what the variable is connected to. For example, the indoor instance of the Temperature Conversion diagram is displayed like this:

ALT

Instead of “°C”, CertSAFE now shows the input as “°C Indoor”, which is the name from the stitch you created earlier in this tutorial. This helps you keep track of where values are coming from and going to. The name shown for °F does not change because we have not given a more specific name for the variable at a higher level in the instance hierarchy.

Also, the °C variable is displayed as blue because it is an input to the current root. °F is still shown as black because it is not an input or output of the current root, but merely an intermediate value used in a later computational step.

Probes

Now that you know how to view different diagram instances, try making a simulation with different inputs for the indoor and outdoor instances, like the one shown below:

ALT

You can see that the model is generally working correctly, but what if we want more information on how the values are being calculated? CertSAFE can help by displaying intermediate computation steps in the form of probes.

When you have a diagram open in instance mode and you are looking at a simulation, you can see probes in the diagram that show you the values at each intermediate point.

ALT

The values shown in the probes are based on the current location of the time cursor in the last simulation editor you clicked on. You can move the time cursor back and forth to see the values at different points in time. (You have to move the diagram and simulation editors side-by-side to see this, or lock the time cursor and switch between the two tabs.) Different instances of a diagram will show different probe values too, of course, since they represent independent subsystems with their own inputs and outputs. In this case, you should be able to switch between the indoor and outdoor instances of your diagrams using the breadcrumbs bar or Instance view and see different values at each step of the computation.

If the probes are getting in the way of seeing logic in your diagrams, they can be disabled. At the bottom of the screen is the Fast Options Bar. This bar contains numerous settings that can quickly change the display of your project in CertSAFE. The third button from the left controls whether probes are displayed or not. It also has a drop-down menu which lets you select how the values in the probes are displayed, and a text box that lets you change the displayed precision when showing floating-point values in decimal. For more information about this feature, and other options in the Fast Options Bar, see the Fast Options Bar documentation.

ALT

None of the buttons in the Fast Options Bar affect the functionality of your model - they only change how you interact with the CertSAFE software. You can mouse over any of the controls in the Fast Options Bar to get a pop-up tooltip with a short description of what that control does.

Conclusion

This quick start guide gave a brief look at some of the most commonly-used features of CertSAFE. For more information on specific features, you can browse through the other articles listed in the sidebar. You can also take a look at the Glossary for a summary of the terminology used in the CertSAFE user interface with links to more information.