MATLAB: How to share data between different forms in a GUI Application while using xPC Target 4.3 (R2010a)

Simulink Real-Time

I have designed a GUI in Microsoft Visual Studio 2008 C# to communicate with my xPC Target. The primary form controls most of the system testing, but there are several other forms that focus on specific parts of the model and which are called from the primary form to adjust the parameters of the model or to just deal with collecting signal data from narrow areas of the design.
When we switch from one form to another, the new form apparently has to connect to the target and download another copy of the .dlm file to the target before it can have access to the target's parameters and signals. If another .dlm file is downloaded to the model by the new form, all of the accumulated model information and anything that has been changed from the original default values are lost and the system is essentially starting all over again.
I want to use multiple forms called by the user from the primary form in order to access the target without losing any information or resetting the model.

Best Answer

There are many ways to share data between multiple forms in a given application - below is one such implementation where we have modified the constructor of Form 2 to accept an xPCTargetPC object so that Form1 and 2 can share the same connection rather than having to reconnect or re-download the model.
The following are the specifications of the attached application:
1) Form 1 has an associated xPCTargetPC component.
2) Form 1 is used to connect and disconnect from the target while Form 2 is
used to Start/Stop the application on the target and also to set the Gain
Value.
3) xPCTargetPC object associated with Form1 is passed to Form2 when it is
created.
The following are the steps to run the application:
- Reboot the target with the xPC Kernel
- Build and download the demo 'xpcosc' onto the target with the stop time set to inf
- Execute tg.close at the MATLAB prompt to close the connection that exists between MATLAB and the target
- Open the project in Visual Studio 2008
- Build and Run the Application
- Click on Connect
- Click on Open Form 2
- Now start/stop the application on the target using Form 2.
Note that the application was not re-downloaded onto the target at any point
of time.