Tuesday, 2 June 2020

Reflections on last week

One of the topics I covered in my instructor-led web-based Rhapsody training to the USA last week was use case modeling.

I like to keep it topical and hence we did a brainstorm of use cases for the UK's NHS COVID Tracing App which was interesting. Quite an engaging topic and a great one to discuss the benefits of using use case diagrams and activity diagrams to explore requirements definition work!

Here's a few screenshots from the short session (work in progress):













MBSE Webinar series - June 2020

I have some Rhapsody-related webinars with IBM coming up if anybody is interested:

Registration Links
4th June @ 3pm CET - Systems Modelling Hints, Tips & Tricks
11th June @ 12pm CET - Dovetailing Model Based Systems Engineering with Requirements Management
18th June @ 3pm CET - Simplifying SysML for the Real World

Sunday, 24 May 2020

IBM Rhapsody Tip #78 - Keeping user code consistent using Refactor: Rename

This short (silent) tips and tricks video takes a quick look at the Refactor: Rename dialog, available in IBM Rational Rhapsody when you right-click elements generated into code like types and classes. The key thing is that Refactor: Rename does more than just update references; it's a form of search and replace dialog and will do an update inside user code sections as well. Using the dialog you can review both before and after the rename. This helps you keep user code sections consistent when refactoring names of elements such as classes, operations, types and attributes.


Monday, 4 May 2020

Rhapsody 9.0 usability enhancements in the Transition features window

While doing the last video, here's a few things I noticed in the Rhapsody 9.0 release related to usability enhancements (the IBM Engineering Systems Design Rhapsody covers both systems and software engineering).

Firstly, the Guard edit frame on the Transition features window is bigger:

This is 8.4:










This is 9.0:












This is simple, but useful (I don't know about you but I often put a return in the guard so that it shows on a different line in the Statechart).

Secondly, the trigger selection now incorporates an active search capability.

This is 8.4:










This is 9.0:
















This new pick-list capability is also present in other dialog's, i.e. it's been working its way through the Rhapsody UI for a releases now.

There's further information on the 9.0 release here.

This bit comes under the "Further enhancements to Combo boxes for model selection: active search on all elements selected" bullet point.

It's nice to see that usability features continue to be thought about, even in the old areas of the UI.

IBM Rhapsody Tip #77 - How to animate user-defined types in sequence diagrams (serialization)

With thousands of properties to explore IBM Rational Rhapsody is a powerful and configurable tool for both systems and software engineering. This short silent tips and tricks video comes at subscriber request!
















In the video I use IBM Engineering Systems Design Rhapsody 9.0 but the same works for (most) earlier versions.

Here's the transcript:

This silent video covers how to get Rhapsody to show the value of user-defined types in an animated sequence diagram.Let's first have a look at the model. It's a C++ one I created that sends a couple of argument-carrying events to control a traffic light sequence. These events have arguments typed by an enum type and a struct type.

By default, when we animate these in a sequence diagram then raw, rather than type-aware values are shown. Fortunately, this is can be fixed. Let's look at the easy way first. On the properties for the Type we can set the property CPP_CG::Type::GenerateSerializationFunctions.











With this property set, Rhapsody will automatically generate the magic code needed to show meaningful text values when animating. Serialize is just a fancy way of saying 'convert this type to text'. Unserialize is the opposite, i.e. 'convert text (a char *) to a type value'. An unserialize function is used when you type text into the Generate Event dialog.













With the GenerateSerializationFunctions property set to SerializationAndUnserialization, Rhapsody automatically generates global serialize and unserialize functions into the .h/.cpp files for the application. Let's have a peek! Here is the auto-generated serialize function.












This is an auto-generated unserialize function.












Note the function's signatures. We need to match these when creating our own. Any user-defined functions would need to take the same argument and return types.

Here are some user-defined serialize/unserialize functions. They are global functions, i.e. contained by a package.








It's important that animation is turned off.







In this user-defined serialization function, I'm converting the enum type to a char * of Y(es), N(o), F(lash), or E(rror). My user-defined unserialization function does the opposite, i.e. converts a char * to the enum type.

We can tell Rhapsody to use these with the properties CPP_CG::Type::AnimSerializeOperation and CPP_CG::Type::AnimUnserializeOperation. We also need to turn off the auto-generation of serialization functions.












When we rebuild and run we can now see the user-defined serialization in play on the sequence diagram.










The user-defined unserialization is also in play!











In summary, you can easily get Rhapsody to auto-generate serialize and unserialize functions for types by setting the GenerateSerializationFunctions property, or (less easily) you can also create your own serialize/unserialize functions for animation, and tell Rhapsody to use them via properties. Just make sure the arguments and return values match and be careful about releasing memory ;-)

Thursday, 23 April 2020

Useful cookbook of different code generation properties for Rhapsody in C++

Rhapsody's usage for generation of C++ for embedded real-time software targets is over 20 years old now. Of course, both it and language have moved on. There's an old IBM tech specialist adage that if Rhapsody doesn't do what you want out-of-the-box then there's probably a property you can set! Of course, find the right property can be a challenge (there are even properties that work that are not in the factory prp's related to backwards compatibility). For those doing code generation with IBM Rhapsody in C++ I thought I'd share a link. This IBM support white paper provides an accumulation of information related to questions that IBM support have had, and hence provides a useful reference of ideas and inspiration:
https://www.ibm.com/support/pages/customize-code-generation-using-ibm-rational-rhapsody-c

Thursday, 16 April 2020

Rational Rhapsody Tip #76 - Using Visual Studio source-code debugger with Rhapsody (Advanced)

This 7' 35" Rhapsody advanced tips video came from some recent work helping a client migrate a project created with a really old iLogix Rhapsody version (5.02) to a later Rhapsody version (8.3.1). Because the framework has changed quite bit, it proved useful to be able to step-through the executing framework code at source-level to get a real handle on what was happening. Many thanks to Hartmut W at BTC Embedded Systems AG in Germany who produce and support the Rhapsody TestConductor add-on. He provided some of the advanced tips here (they are experts in formal testing of code afterall ;-). I particularly like the trick to recompile the framework with USE_PDB=TRUE, and setting programmatic breakpoints so that you can add them directly in Rhapsody. Hope it helps someone!
















Here's a transcript:

This silent video covers 3 tips on source-code level debugging a model-driven Rhapsody application with the Visual Studio IDE.

Many thanks to Hartmut W @ BTC (maker of Rhp TestConductor add-on) for a couple of advanced tips.

This model has a configuration with animation enabled. We can generate and build the code from Rhapsody (model-driven). I've modified Rhapsody 8.4's MSVC environment to use the Visual Studio 2019 compiler here but these tips apply equally to earlier versions. This results in an exe. With animation enabled, it talks back to Rhapsody via a port so that you can interact with it, e.g., in a panel or animated statechart. This is model-level debugging and can help correct "the bigger picture". Often, however, we also want to step through and debug at code-level. Well, this is surprising easy to do with Visual Studio ;-)

Suppose, for example, we want to set a code-level break point in this transition? Firstly, we open up the Visual Studio IDE. Choose to open a project or solution, and browse to select the executable (.exe) that Rhapsody generated. Now, open up the source file, e.g., .cpp, that you want to step through in Visual Studio. This is the folder where the source code is generated by Rhapsody for this configuration. We can now locate where we want to set the breakpoint and set a breakpoint in the code (e.g. F9).

Now, when we run the .exe from Visual Studio, it will break when it gets to this line. Voilà !! We can now debug at code level.

Oh dear, we've stepped into a Framework (OxF) class here. Time for the second tip!

The application object files are linked with a library that contains base classes for many elements such as statecharts, events and threads. This is known as the OxF (Object eXecution Framwork). The OxF model/code/libraries are in the installation OMROOT/Share folder. To step through OxF code we need to recompile it with a change to one of the switches. Locate the config's CPP_CG::MSVC::buildFrameworkCommand property and change USE_PDB=FALSE to USE_PDB=TRUE. Choose Code > Build Framework to rebuild the OxF libraries using the active configuration's settings. This may take a couple of minutes.

Let's rebuild and link the application now. We can now debug again using the new PDB info available for the OxF. We're now able to step into the source code that is part of the OxF framework. e.g. OMReactive is the base class for classifiers that have statecharts and OMThread is the base class that iterates over the event queue. We can also set breakpoints in the Framework code (if we want).

Time for the final tip! With Visual Studio Professional we can also set breakpoints programmatically in Rhapsody. To programmatically add a breakpoint, we first add crtdbg.h to the config's include or additional sources path. We can now add a _CrtDbgBreak(); directly into code in the model.

Optionally, if we run from Rhapsody then we could Attach to Process... in Visual Studio. However, I first want to remove all non-programmatic breakpoints. Visual Studio will break itself when it gets to the _CrtDbgBreak(); in the code. Ta-dah! ;-)

That's it then, 3 tips for source-level debugging Rhapsody applications using Visual Studio:
1. Open .exe/source files and run from VS
2. Recompile OXF with USE_PDB=TRUE to code-level debug framework (optional)
3. Using programmatic breakpoints by including crtdbg.h and using _CrtDbgBreak(); (requires VS Pro)