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 2010.
Open the oscillator model.
mdlOpen = 0; systems = find_system('type', 'block_diagram'); if isempty(strmatch('xpcosc', systems, 'exact')) mdlOpen = 1; open_system('xpcosc'); end
Run the model in Simulink® to observe its dynamic behavior.
% Start the development computer model. set_param(bdroot,'SimulationCommand','start'); % Start the development computer model. pause(3); % Wait for 3 sec.
% View plot window. open_system([bdroot,'/Scope']);
% Close plot window. close_system([bdroot,'/Scope']);
% Build the model and download to the target computer set_param('xpcosc','xPCisDownloadable','off'); % Do not download after building. set_param('xpcosc','RTWVerbose','off'); % Configure for a non-Verbose build. rtwbuild('xpcosc'); % Build and download application. if exist('tg','var'),tg.close;end % Close the target connection.
### Starting Simulink Real-Time build procedure for model: xpcosc ### Successful completion of build procedure for model: xpcosc ### 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.dlm... button, navigate to and select the application file
xpcosc.dlm. Click the Open button to close the Select a DLM 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.dlm 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: