This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Simple Client Application With the .NET API

This example shows a C# client application that uses the Simulink® Real-Time™ API for Microsoft® .NET Framework to interface with the target computer. Developed using Microsoft® Visual Studio®, the client application loads, starts, and controls the oscillator real-time application, xpcosc.mldatx.

For more information about Simulink Real-Time API for Microsoft .NET Framework, see the Simulink Real-Time documentation.


  • To open the project files, you must have installed Microsoft Visual Studio.

Open the Model

Open the oscillator model.

mdlOpen = 0;
systems = find_system('type', 'block_diagram');
if ~any(strcmp('xpcosc', systems))
  mdlOpen = 1;

Run the Model

Run the model in Simulink® to observe its dynamic behavior.

Start the development computer model.

pause(3);  % Wait for 3 sec.

View plot window.


Close plot window.


Build the Model

Build the model and download to the target computer

  • Do not download after building.

  • Configure for a non-Verbose build.

  • Build and download application.

  • Close the target connection.

if exist('tg','var'),tg.close;end
### Starting Simulink Real-Time build procedure for model: xpcosc
Warning: This model contains blocks that do not handle sample time
changes at runtime. To avoid incorrect results, only change
the sample time in the original model, then rebuild the model. 
### Successful completion of build procedure for model: xpcosc
### Created MLDATX ..\xpcosc.mldatx
### Download process is disabled. 

Close the Model

Close the target model if we opened it.

if (mdlOpen)

Open the Client Application (Example 1)

Open the client application: Oscillator Client (Example 1)

Set the Target TCP/IP Address and Target TCP/IP Port to match your target computer configuration.

Figure 3: Oscillator Client Application (Example 1)

Find xpcosc.mldatx

Next, by clicking the Find xpcosc.mldatx... button, navigate to and select the application file xpcosc.mldatx. Click the Open button to close the Select application file window.

Figure 4: File Find dialog box

Confirm your target computer is booted and connected to the development computer, then:

  • Click the Connect button to connect to the target computer

  • Click the Load button to load the application on to the target computer

  • Click the Run button to start the application running

If you have a monitor connected to the target computer, you will see the oscillator simulation results displayed in a target scope. You can change the damping parameter by moving the slider. When done:

  • Click the Stop button to stop the application from running

  • Click the Unload button to unload the application from the target computer

  • Click the Disconnect button to disconnect from the target computer

Open the Client Application With Host Scope (Example 2)

Host scopes can be used to view signals on the development computer. This example uses host scopes to view the oscillator command and response within a client plot figure.

Open the client application: Oscillator Client (Example 2)

As before, set the Target TCP/IP Address and Target TCP/IP Port to match your target computer configuration and then use the Find xpcosc.mldatx button to navigate to and select the real-time application file.

Click the Connect, Load, and Run buttons. You should see the oscillator command and response signals in the plot figure.

Figure 5: Oscillator Client Application With Host Scope (Example 2)

Project Files

The Microsoft Visual Studio project associated with these examples is located in the Simulink Real-Time API folder here: Project Folder