Table of Contents
String Constant
Outputs a constant string value.
Library
MATLAB Command Line
Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:
qc_open_library('quarc_library/Strings')Description
The String Constant block is similar to the
MATLAB Command Line
Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:
doc simulink/constantuint8
characters)
rather than a numeric value. The value of the string may be tuned online just like a Constant
block's value. The string that is output always has the given maximum length.
The string is normally not evaluated so that it is output exactly as entered. However, by checking the Evaluate string value option the string is evaluated and the resulting value is output. The expression must evaluate to a string. It is typically the name of a MATLAB workspace variable containing a string value.
When the string is not being evaluated, the String Constant block allows format specifiers to be included in the string. These format specifiers begin with a '%' character and are replaced with the appropriate value. For example, the date and time at which the model was started may be substituted using the '%{date}' and '%{time}' expressions in the string. Refer to the qc_perform_substitutions function for a full list of the format specifiers available. It also replaces standard C escape sequences such as '\n' with the appropriate ASCII character.
If format specifiers which change frequently, such as '%{time}' or '%{instance}', are used in the string value then the String Constant block cannot be placed in a referenced model, because the value will change from the time the code is built to when the code is run. As a result, Simulink will insist that the code be rebuilt because block parameters in referenced models are inlined. Instead, use the String Constant block in the top-level model and pass its output as a signal from the top-level model to an input port of the referenced model.
When using format specifiers, sometimes characters are added to the string that are not desirable under the circumstances. For example, the string returned by '%{time}' includes colons because it takes the form 'HH:MM:SS'. If the output string is intended as a filename, then these colons would result in an illegal filename.
Since the time can be quite useful for data logging as part of a filename, QUARC resolves this problem via
the String type parameter. The String type option may be used to
coerce the resulting string into a particular format. For example, setting the String type
parameter to file
forces the output to be a valid file path. In this case, if '%{time}'
were part of the string value then the output of the String Constant block would contain the time, but the colons
would be replaced with hyphens, which are valid in a filename.
Helpful Hints
Parameter Tuning
Unlike most blocks, the length of the String value parameter may be changed without recompiling the model. The reason is that the output is always a vector whose length is determined by the Maximum length parameter, not by the length of the String value field. This tunability can speed up development significantly when using strings in Simulink.
Input Ports
This block has no input ports.
Output Ports
value
The string value. The data type of this output is uint8
(UTF-8 code unit), which is the
data type used by QUARC for strings. The string is guaranteed to be null-terminated. If the
Use variable-size output option is checked then this output is variable-size.
Data Type Support
This block outputs the string as a null-terminated vector of UTF-8 characters or uint8
values.
It supports writing this string as a variable-size output. See Variable-Size Signals
for more information on variable-size signals.
Parameters and Dialog Box
String value (tunable online)
The value of the string. If the Evaluate string value option is unchecked then this parameter is interpreted literally and is not evaluated. Otherwise it is evaluated as a MATLAB expression. The expression must evaluate to a string. It is typically the name of a MATLAB workspace variable, but can be any MATLAB expression, such as a call to sprintf.
When the value is not being evaluated it may include format specifiers. Refer to the qc_perform_substitutions function for a list of format specifiers available. The arrow button to the right of the String value field may be used to select format specifiers to append to the string value.
If you are using the keyboard to navigate the block parameters, use the Alt+Down key combination on the arrow button to open the drop-down list of format specifiers. |
Evaluate string value (tunable online)
Normally this option is not checked. In this case, the String value parameter is not evaluated but output directly from the block.
Checking this option causes the String value parameter to be evaluated and the resulting string output.
String type (tunable online)
This option is only used when the string is not being evaluated. It indicates the purpose for which the string is being used and coerces the output of the String Constant block accordingly. The table below enumerates the different string types.
Type |
Description |
---|---|
text |
The string is straightforward text. No changes are made to the resulting output. |
file |
The string is intended as a filename. Illegal characters are removed or replaced. |
URI |
The string is intended as a URI. Illegal characters are removed or replaced. |
variable |
The string is intended as a variable name. Illegal characters are removed or replaced and the string may be truncated to namelengthmax
.
MATLAB Command Line Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window: doc namelengthmax |
Maximum string length
The maximum length of the string argument in code units (bytes), including the null-terminator. The output will be a vector of this length. If the Use variable-size output option is checked then the dimension of the output will vary with the length of the string.
Sample time
The sample time of the block. A sample time of 0 indicates that the block will be treated as a continuous time block. A positive sample time indicates that the block is a discrete time block with the given sample time.
A sample time of -1 indicates that the block inherits its sample time. Since this is a source block, only inherent the sample time when it is placed in a conditionally executed subsystem, like a Triggered or Enabled Subsystem, or in a referenced model.
The default sample time is set to inf, which indicates that the block is a constant.
To set the sample time to the fundamental sampling time of the model, use the qc_get_step_size function, which is a QUARC function that returns the fundamental sampling time of the model. The fundamental sampling time of the model is the sampling time entered in the Fixed step size field of the Solver pane of the Configuration parameters.
Use variable-size output
Enabling this option causes the value output to be variable-size. In this case, as the string constant is modified, the size of the output varies dynamically. If this option is not checked then the output is a fixed-size vector. Refer to Variable-Size Signals for more information on variable-size signals.
Targets
Target Name |
Compatible* |
Model Referencing |
Comments |
---|---|---|---|
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
Last fully supported in QUARC 2018. |
|
Rapid Simulation (RSIM) Target |
Yes |
Yes |
|
S-Function Target |
No |
N/A |
Old technology. Use model referencing instead. |
Normal simulation |
Yes |
Yes |
See Also
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.