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,
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 oscillator model.
addpath(fullfile(matlabroot,'toolbox','rtw','targets','xpc','xpcdemos')); mdlOpen = 0; systems = find_system('type', 'block_diagram'); if ~any(strcmp('xpcosc', systems)) mdlOpen = 1; open_system(fullfile(matlabroot,'toolbox','rtw','targets','xpc','xpcdemos','xpcosc')); end
Run the model in Simulink® to observe its dynamic behavior.
Start the development computer model.
set_param(bdroot,'SimulationCommand','start'); pause(3); % Wait for 3 sec.
View plot window.
Close plot window.
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.
set_param('xpcosc','xPCisDownloadable','off'); set_param('xpcosc','RTWVerbose','off'); rtwbuild('xpcosc'); 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 target model if we opened it.
if (mdlOpen) bdclose('xpcosc'); end
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)
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
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)
The Microsoft Visual Studio project associated with these examples is located in the Simulink Real-Time API folder here: