Using Default URIs End of trail navigation bar

Table of Contents > QUARC > User's Guide > QUARC Targets > Communicating with the Target

Specifying a Model and/or Target URI

While using the default model URI is the most convenient technique for specifying how Simulink will communicate with the real-time code for the model, there are some circumstances in which it is necessary to specify a different URI for a specific model. For example, a base station could be used to generate code for a set of unmanned ground or aerial vehicles (UGVs or UAVs), with one Simulink model defined for each vehicle. If all the vehicles are running the same Linux target type then specifying a default model URI for the Linux target will not be sufficient to differentiate between the vehicles. In this case, each Simulink model will need to be assigned a different model URI so that the real-time code for each model is directed to the appropriate unmanned vehicle.

Both a model URI and a target URI may be specified explicitly in the configuration parameters for a model. The configuration parameters may be accessed via the Configuration Parameters dialog or the Model Explorer interface. This topic shows how to use the Model Explorer interface to change the model and/or target URI, but a very similar procedure is used with Configuration Parameters dialog. The actual parameter that needs to be modified is the same in both cases.

Perform the following steps to set the model or target URIs for a particular model configuration using the Model Explorer interface:

  1. Open Model Explorer by selecting Model Explorer from the View menu of the diagram, clicking on the Launch Model Explorer button on the toolbar, or pressing Ctrl+H. You may have to make the diagram a little wider to see the full toolbar.

  2. Expand the node for your model in the treeview in the Model Hierarchy pane as shown below and click on the Configuration item below it. If you have renamed or copied the configuration then click on the name of the desired configuration.

  3. Click on the Code Generation item in the Contents list in the middle of the Configuration Parameters dialog. A set of tabbed panes will appear on the right-hand side of the Model Explorer window. Choose the Interface tab among the tabbed panes on the right-hand side of the Model Explorer window.

  4. Look at the MEX file arguments field. This field can contain up to four comma-separated entries:

    ['<model arguments>'[, '<model URI>'[, '<target URI>'[, <affinity>]]]]

    where the <model arguments> are the command-line arguments passed to the model when it is run, the <model URI> entry is the URI used to communicate with the real-time code for streaming data and parameters, and the <target URI> is the URI used to communicate with the QUARC Target Manager for downloading and running code. The affinity entry determines the CPUs on which the communications thread is allowed to run on the host. The [] indicate entries that are optional.

    For example, if the MEX file arguments field contains the line:

    '-w -d /tmp -uri %u'

    then no model URI or target URI has been specified, so the default model URI and target URI will be used. The "%u" format specifier in the command-line arguments will be replaced with the model URI. Hence, the arguments passed to the model on the command line when it is run may be '-w -d /tmp -uri tcpip://mytargetbox:17001'. These arguments are passed to the model in argc and argv when its main entry point is invoked. By passing the model URI to the model as a command-line parameter, the URI used by the model (as a server) and by Simulink to communicate with the model (as a client) are guaranteed to be consistent.

    Consider another example. If the MEX file arguments field contains the line:

    '-w -d /tmp -uri %u', 'tcpip://embeddedbox:17001'

    then the model URI is set to 'tcpip://embeddedbox:17001'. No target URI has been specified, so it will be derived from the model URI using the default target URI associated with the tcpip communication protocol. Note that in order to provide a model URI, the model arguments must be specified. An empty string, '', may be used for the model arguments if none are desired.

    Warning If multiple models will be run at the same time, then the model URI for each model should be unique. For example, suppose two models had the same model URI: 'tcpip://embeddedbox:17001'. The first model to be run will begin listening on TCP/IP port 17001 for connections from the corresponding Simulink diagram running on the host. The second model will attempt to listen on TCP/IP port 17001 as well, but will fail because the TCP/IP port is already in use by the first model. Hence, the second model will exit with an error and Simulink will fail to connect to it. The solution is to specify a different model URI, such as 'tcpip://embeddedbox:17002', for the second model so that the TCP/IP ports do not conflict.

    The model URI may contain the "%m" format specifier, which is replaced with the model name. The "%m" format specifier is the only valid format specifier within a model URI. It is typically used with the shared memory and pipe protocols as the "hostname" in the URI because doing so makes the URI unique for each model automatically. Hence, if the default model URI is shmem://%m:1 then every model will be given a unique model URI because Simulink cannot open two models with the same name at the same time.

    Finally, if the MEX file arguments field contains the line:

    '-w -d /tmp -uri %u', 'tcpip://embeddedbox:17001', 'tcpip://%h:17000'

    then the model URI is set to 'tcpip://embeddedbox:17001'. The target URI is also specified. The "%h" format specifier in the target URI is replaced with the hostname from the model URI. Hence, the target URI becomes 'tcpip://embeddedbox:17000'. Note that in order to provide a target URI, both the model arguments and the model URI must be specified. An empty string, '', may be used for the model arguments if none are desired. An empty string, '', may also be used for the model URI, in which case the default model URI will be employed.

    Refer to the qc_get_target_uri reference page for a complete list of the format specifiers that may be used in a target URI.

    For more information on the affinity and the performance gains achievable with certain targets, as well as format specifiers that may be used in the model arguments and other details, please refer to the MEX-file arguments reference page.

  5. Click OK to apply the changes and then save the model. The MEX file arguments only need to be configured once for a particular model, unless you wish to change them. They do not have to be set each time you wish to build code for that model.

 

navigation bar