| Embedded IDE Link™ CC | ![]() |
Execute ANSI® C or General Extension Language (GEL) expressions on target
result = cexpr(cc,'expression',timeout)
result = cexpr(cc,'expression')
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
A string with C syntax, whose variables reside in the local scope of the target processor
A routine mapped to GEL functions defined in the current CCS project
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:
cexpr returns a result in MATLAB software when you use a C statement as the expression argument. In the first example syntax in "Examples." result = cexpr(cc,'x.a'), MATLAB software returns result = the value of x.a on the target. In more concrete form, the syntax result = cexpr(cc,'x.b=10') sets x.b to 10 on the target and returns result = 10 to your MATLAB software workspace.
When your expression arguments are GEL functions, cexpr does not return results to MATLAB software.
Combining C and MATLAB expressions requires that you use single quotation marks around the C expressions to isolate them from the MATLAB interpreter. MATLAB software performs the functions it understands and then passes the rest to the target for evaluation. The target returns the result to the MATLAB desktop.
Pay attention to the scope of the program you are accessing. Only variables within the current scope of the program in CCS and on the target respond to cexpr. To access variables using cexpr, the variables must be either global or within the current scope. When you try to read or write to a variable outside the current scope, MATLAB software returns errors like the following:
??? EvalC: identifier not found: variablename. ??? EvalC: line(1), unexpected token: variablename.
Generally, variables within the program main are available without extra effort. To get to variables defined locally in subprograms, use breakpoints and the runtohalt input option in run to set your program to the right scope, then use cexpr to return the information.
For more information on GEL and GEL files, refer to your CCS documentation.
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 Syntax | Description |
|---|---|
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.
![]() | cd | cleanup | ![]() |
| © 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 |