cexpr

Execute ANSI® C or General Extension Language (GEL) expressions on target

Syntax

result = cexpr(cc,'expression',timeout)
result = cexpr(cc,'expression')

Description

result = cexpr(cc,'expression',timeout) executes the specified expression on the target processor referred to by cc and returns a result. If your program includes data in complex data structures and arrays, cexpr offers one way to access the data.

To run cexpr on your target, you must load a program to the processor. Your target processor does not need to be running the loaded program to execute cexpr. In operation cexpr is equivalent to using the CCS Command Line dialog box. Refer to your CCS documentation for more information about using the command line in CCS.

When you place single quotation marks around the expression argument, MATLAB® software ignores the enclosed string, passing it to your target. The target processor evaluates the expression and returns the result to MATLAB software. Any part of the expression argument that is not in single quotation marks gets evaluated by MATLAB software and sent to the target processor along with the quoted portion. Using single quotation marks, you can combine MATLAB, GEL, and ANSI C expressions within one cexpr command so that MATLAB software sets a value on the target. The target uses the value and returns the result to your MATLAB software workspace. Refer to "Examples" for a code example that mixes C and MATLAB functions in one command.

After you execute the function, MATLAB software waits timeout seconds for CCS to confirm successful completion of the operation. If the wait exceeds timeout seconds, MATLAB software returns an error. Often, the time-out error means the confirmation was delayed but the operation succeeded.

Enter expression as a string in single quotation marks defining either a C expression, a GEL command, or a combination of both C and GEL. CCS defines the syntax for expression as either

result = cexpr(cc,'expression') is the same as the preceding syntax except the timeout value defaults to the global time-out in cc. Use get(cc) to determine the global time-out value.

When you use cexpr, a few points can help you work effectively:

For more information on GEL and GEL files, refer to your CCS documentation.

Examples

cexpr covers a broad range of uses. To introduce some of the possibilities, the following examples use both the C expression and GEL expression forms. Because executing the examples requires that specific variables and functions exist on the target, you cannot execute the code shown.

cexpr SyntaxDescription

result = cexpr(cc,'x.a')

Returns the value of field a in structure x stored on your target. For this example, expression is x.a and result contains the value stored in x.a on the target.

result = cexpr(cc,'StartUp()')

Executes the GEL function StartUp on the target processor. expression is 'StartUp', a function in the GEL file that loads each time you start CCS. Note that GEL function names are case sensitive — StartUp is not the same as startup. In this example, result is NULL or empty because GEL functions do not generate return values. Do not use an output argument with GEL expressions as input arguments.

result = cexpr(cc,'x.b = 10')

Sets and returns the value of the field b in structure x. Here the assignment statement in single quotation marks replaces expression. x.b must be a structure in memory on your target and in the current program scope. After execution, result contains the value 10 returned from the target.

result =cexpr(cc,['x.c[2] =' int2str(z)])

Sets the value of x.c[2] to the string represented by integer z. In MATLAB software, result contains the value stored in x.c[2] as returned from the target. Notice that the C expression is in single quotation marks, and the MATLAB int2str is not. Using single quotation marks directs MATLAB software to ignore the C string that applies to the target processor and to evaluate int2str.

A note about the final example — the variable z must be in your MATLAB workspace for int2str to work. In contrast, x.c[2] defines a value on your target, not in the MATLAB environment.

See Also

address, read, write

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS
 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS