MATLAB Command Line
Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:
quarc_serial_interfacing_read_binary_demo; quarc_serial_interfacing_write_binary_demoQUARC Serial Interfacing Binary Demo
This example consists of a writer model that emulates a serial device and a reader model that normally acts as a controller. It demonstrates how to use the Stream Call, Stream Answer, Stream Read, and Stream Write blocks from the QUARC Targets Library to transfer binary data via serial port. For a detailed description of these models and how they operate, please refer to the Intermediate Communications section of the QUARC documentation.
Configuring the Demonstration
To set up the demonstration, double-click on the Stream Call block in the
quarc_serial_interfacing_read_binary_demo.mdl model and on the
Stream Answer block in the quarc_serial_interfacing_write_binary_demo.mdl
model and ensure the URI upon which to listen and
URI of host to which to connect parameters respectively
are set correctly. In particular, ensure the port numbers in the URI reflect the correct
COM port. The port is the number following the hostname. For example, "serial://localhost:6"
refers to serial port COM6
.
To run this demonstration on a single computer, there must be two serial ports available that are connected by a serial crossover cable or NULL modem cable. It is best if the hardware flow control lines RTS and CTS are included in the cable. Furthermore, the port being used by the writer should be different from the port being used by the reader. Otherwise an error will occur whenever you start the second model because a single serial port doesn't accept more than one connection at a time.
If the serial cable does not support hardware flow control lines then the flow option in the URI of both models must be set to flow=none or the serial connection may not function correctly! |
Demonstration
Select Ctrl+B while each 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 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.
from the menu of each diagram, or pressDouble-click on the "Received" Scope block in the quarc_serial_interfacing_read_binary_demo.mdl model to open the scope if it's not already open. Do the same for the "Sent" scope block in the quarc_serial_interfacing_write_binary_demo.mdl model.
Click on the
button or select from the menu of the diagrams to connect to the models.Start the models by clicking on the quarc_serial_interfacing_read_binary_demo.mdl first.
button or selecting from the menu of the diagram. The item of the menu may also be used to both connect and start the model in one operation. Start theA sine wave will show up in the "Sent" scope.
The sampling time can be changed by updating the value of Fixed-step size in the . If the quarc_serial_interfacing_read_binary_demo.mdl is being run on a different computer then it may be necessary to run it at a slightly higher sampling rate to ensure it doesn't fall behind the writer model (since sampling periods can differ very slightly between computers, particularly from different manufacturers).
Click on the
button or select from the menu of each diagram to stop the model. The item of the menu may also be used.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.
Be sure to adjust the URI of each block appropriately as described in the Configuring the Demonstration section. Refer to the Serial Protocol page for the ports and options available on a particular target.
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.