This short and silent caption-based tips and tricks video came from a subscriber emailing me for help on getting change events to execute correctly with SysML proxy ports. In this first of two videos, I thought I'd recap some of the fundamentals about how change events in Rhapsody statecharts work, and what they're for. The key tips in this video are really that you need to make sure that you use the setter operation when changing the value of attributes / value properties. Setters and getters (what are often called a mutators and accessors in C++) are auto-generated. The setter will follow the convention of the word set followed by the name of the attribute capitalized. Change events are used as triggers in Rhapsody statecharts for reacting to a change of data. They also follow a naming convention which is the characters 'ch' (for change) followed by the name of property (capitalized). Hopefully the video explains for those who're interested!
Thursday, 1 October 2020
IBM Engineering Rhapsody Tip #84 - Getting statecharts to react to change events (Advanced)
Here's some of the transcript, in case it helps:
Change events were originally developed to work with SysML flow ports. However they also work with SysML newer proxy ports. This video explains how to get them working for both.
In this project I have two parts both with a ‘batteryLevel’ property. In the IBD they’re connected via similarly named SysML flow ports; the port type introduced in the original SysML spec to handle data and material flow.
If I run the simulation then you’ll notice that the batteryLevel is not forwarded. This is because the setter is not being used in the sending blocks statemachine. Let’s correct that.
For those geeks amongst you, it’s actually the code in the autogenerated setter that causes the flow to occur. If you don’t use the setter whenever the value changes, then you don’t get a flow.
We’re now getting the flow. However, partC is not currently reacting to it. This is where a change event comes in. A change event in Rhapsody begins with a ch prefix.
You can now see the battery level change event occurring
In summary, change events are based on a ch followed by the name of attribute (with first letter capitalised). They require that the publisher of the change uses the setter.
So, how do we get them to work for proxy ports? Well, that's the next video.