quarc_model_std_io_demo.mdl
Open this model

QUARC Model Standard I/O Demo

This example demonstrates how to use the Scan and Print blocks from the QUARC Targets library to interact with the model standard I/O. For details of these blocks, please refer to the Scan block and the Print block reference pages in the QUARC documentation.

Model Standard I/O Demo Simulink Diagram

The reason for executing these blocks in an asynchronous thread is that the Scan block is blocking and should not be placed in the main diagram. For information on the asynchronous threads, you can refer to the Asynchronous Threads section.

Configuring the Demonstration

To set up the demonstration, you need to open a QUARC console to be able to interact with the model standard I/O. Information on the QUARC console can be found in the QUARC Console - Model Standard I/O reference section.

Note that you need to open a console specific to the model. To open a QUARC console for your model, choose the QUARC/Console... menu item in the model window.

QUARC Console

Demonstration

Select Build from the QUARC menu of the diagram, or press Ctrl+B while the diagram is the active window. A great deal of output will appear in the Diagnostic Viewer about the progress of the build. If you cannot see the Diagnostic Viewer, you can open it by selecting View/Diagnostic Viewer from the menu of the diagram, or clicking on the View Diagnostics hyperlink at the bottom of the diagram. If you have MATLAB R2013b or earlier then the output will appear in the MATLAB Command Window.

Click on the Connect to Target button or select Connect to Target from the Simulation menu of the diagram to connect to the model.

Start the model by clicking on the Run button or selecting Run from the Simulation menu of the diagram. The Start item of the QUARC menu may also be used to both connect and start the model in one operation.

In the QUARC console, the user is asked to input a number. Input a number and press Enter. The QUARC console would look similar to the following figure once you pressed Enter.

QUARC Console

Now, enter a string rather than a number. The model would complain that the number you entered is invalid.

QUARC Console

Warning Because standard I/O is always blocking on the Windows target, it may be necessary to press a character and then press Enter in a QUARC Console before an asynchronous thread containing a Scan block can terminate. This restriction can prevent other block's termination functions from executing until the asynchronous thread has exited.

Referring to the above warning, in order to stop the model, click on the Stop button or select Stop from the Simulation menu of the diagram and then press a character followed by the Enter key in the QUARC console. Notice that the messages regarding the model being terminated appear on the console. It is only when you press a character followed by Enter that the model terminates after you request a stop using the Simulink model window.

Running the example on a different target

To run the example on a different target, refer to the instructions on the Running QUARC Examples on Remote Targets page.