Start of trail End of trail navigation bar

Table of Contents > QUARC > User's Guide > QUARC Basics for Scripts

Basic Procedures

Once the initial configuration of QUARC is complete, scripts may be created, built and then run on target machines. The first step after creating a MATLAB script is to generate code and build it for the desired target. Once it is built, the script may then be run on the target. This section explains the procedures involved in building and running a script on a target. The following list may be used to refer to each topic:

Building a Script

To build a script to run in real-time on a target, use the qc_build_script command. The qc_build_script command performs the following sequence of operations. These operations are all performed automatically when you build the script, but are listed here to give you a better understanding of how QUARC generates code.

Main generation
The qc_build_script command generates a main C file that will serve as the entry point for the generated code. The main C file will be called script_main.c, where script is the name of the script for which code is being generated. If this source file already exists, then by default qc_build_script will not overwrite it. Hence, it is possible to modify the C code.
Build script generation
The qc_build_script command generates a build script that may be used to build the real-time code. The build script will be called script_build.m, where script is the name of the script for which code is being generated. If the build script already exists, then by default qc_build_script will not overwrite it. Hence, it is possible to modify the build script.
Code generation
After generating the main C file and build script, if required, the qc_build_script command invokes the build script to generate the C code for the script and to build a real-time "executable" for the desired target type. QUARC gives the executable the extension .rt-<target type>, where <target type> is the name of the type of target. For example, the extension .rt-win64 is used for the QUARC Win64 target.

Once a build script has been generated, it can be invoked directly to build the script executable instead of re-running qc_build_script. It is also possible to run qc_build_script each time, since it does not overwrite the build script or main C file by default. See the qc_build_script documentation for other options such as updating the target in a build script, overwriting existing files, or generating files without building.

Running a Script

After building the real-time code for a MATLAB script using the qc_build_script command, the code may now be run on the QUARC target. To run a script executable on a QUARC target, the qc_run_script command may be used. The script executable may also be run directly from Windows Explorer.

The qc_run_script commands takes the script executable name, including file extension, as its argument along with any arguments to pass to the script itself. For example, to run the myscript.rt-win64 script executable, use the command:

qc_run_script myscript.rt-win64

To pass it arguments, simply add those arguments to the end of the command line, as follows:

qc_run_script myscript.rt-win64 -kp 7.3

Note that spaces delineate arguments, so the above example will pass two arguments, "-kp" and "7.3", to the myscript QUARC "executable".

The above command could also be specified in the equivalent functional form as:

qc_run_script('myscript.rt-win64', '-kp', '7.3')

Note that all the arguments to qc_run_script are strings. Hence, to use a variable for one of the arguments, the variable value must be converted to a string. For example, suppose the scalar gain contained the desired value of Kp. Then the following command could be used to pass the value of gain as an argument to the script:

qc_run_script('myscript.rt-win64', '-kp', num2str(gain))

The target on which the script executable will be run is determined by the target URI. QUARC uses Universal Resource Identifiers (URIs) for its communications paradigm. In short, a URI identifiers the protocol and address of the target. For example, the URI tcpip://remhost:17000 identifies a remote target named "remhost" listening on TCP/IP port 17000.

The target URI used for a script executable is returned by the qc_get_target_uri function when passed the script exeecutable name e.g. qc_get_target_uri('myscript.rt-win64').

To run the script executable on a different target, the -t target_uri option may be passed to the qc_run_script command. For example:

qc_run_script -t tcpip://remhost:17000 myscript.rt-win64

 

navigation bar