String To Enum — Control Systems/Strings
Control_Systems/Strings/String_To_Enum · 1 input / 1 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++
Description#
The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.
String to Enum
Control Systems / Strings
Turns text into the member of an enumerated type whose name it is:
with a type Hue of members Red = 10, Green =
20 and Blue = 30, the text Green gives Green,
whose value is 20. The match is exact and case-sensitive, as in Simulink:
green, Green, Green , an empty text
and the value 20 written as text all name no member. Text that names
no member stops the run.
Ports
- Input – the text u (
str,ICoreString), one value. - Output – the member (
enum,ICoreEnum) of the type below, carried as the member's own value, one value [1,1].
Parameters
- Output data type –
Enum: Name, where Name is an enumerated type the project defines withdefineEnum. Nothing else is accepted, as in Simulink. The default,Enum: SlDemoSign, is Simulink’s own, and names a type a project must define before the block runs. - Sampling Time (s) – zero or less inherits the solver's rate. It does not cross to Simulink, whose block has no rate parameter.
When a run is refused
A type the project does not define; an output data type that is not an enumeration; and, while the model runs, text that names no member, in Simulink’s words: Input string 'Purple' of block '…' does not match any enumerated value in enumerated data type 'Hue'.
Code export
Python, MATLAB, Java, Rust, C and C++: the text is matched against the member names written into the code, and the output is the member’s value as a 32-bit integer, which is how every target carries an enumeration. Generated code cannot stop a run: text that names no member gives the type’s default member there. The HDL targets and PLC Structured Text do not carry text, so an export to one stops and names the block.
Simulink bridge
Import and export, mapped to simulink/String/String to Enum. Output
data type crosses as OutDataTypeStr, and the type itself as the
Simulink.defineIntEnumType line every exported enumeration gets. The
rate does not cross.
Notes
- To turn text into a plain integer code by a list instead, use Machine Learning / Preprocessing / Label Encoder, which answers a code of its own for text it does not know rather than stopping.
Code facts#
| Fact | Value |
|---|---|
| registered type | Control_Systems/Strings/String_To_Enum |
| family | Control_Systems/Strings |
| solver environment class | ICoreBlock_0_Control_Systems_1_Strings_2_String_To_Enum |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Strings/String_To_Enum/ICoreBlock_0_Control_Systems_1_Strings_2_String_To_Enum.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Strings/String_To_Enum/ICoreBlock_0_Control_Systems_1_Strings_2_String_To_Enum.h |
| default size on canvas | 90 × 60 px |
| ports at insert | 1 in, 1 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++ |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreString | — |
| 2 | out | ICoreEnum | — |
Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.
Configuration variables#
| Config variable | Default | Simulink parameter |
|---|---|---|
Output data type | Enum: SlDemoSign | OutDataTypeStr |
Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.
Simulink bridge#
| support | Support::Both |
| Simulink path | simulink/String/String to Enum |
| port-count rule | PortsParam:: |
SampleTime parameter | no — the counterpart defines none; the rate stays on the ICore side |
| ICore config | Simulink parameter | Value translation |
|---|---|---|
Output data type | OutDataTypeStr | passes through |
Caveat (shown to the user): OutDataTypeStr is
Enum: <type>on both sides, and the type crosses as the
Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h
Description vs code#
The checker has a blind spot here — it could not resolve something (a grouped port bullet, a computed config name), which is reported and never counted as a pass. A reader has to settle it:
B0no sample under docs/generated/samples/ — nothing to cross-check (P8.1)
The verdict above is
tools/docs/check_block_descriptions.py(P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.
File banner (developer view)#
The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).
String to Enum -- text in, the enumeration member of that name out Measured on R2026a (2026-09-11):
BlockType=StringToEnum, 1 in / 1 out, ONE parameter,OutDataTypeStr, defaultEnum: SlDemoSign, taking nothing butEnum: <class>(int32andInherit: autoare refused); no SampleTime. The match is EXACT and case-sensitive against the member NAMES: "Red" gives Red, while "red", " Red", "Red ", "" and the member's value "10" are refused. Text that names no member STOPS the run, mid-run as at constant folding: "Input string 'Purple' of block ... does not match any enumerated value in enumerated data type 'zb6Hue'". The output carries the members' OWN values (10/20/30), not their positions.The enumeration is BF19.3's ICoreEnum: the port matrix holds the member's value and the type's name rides on the side carrier, which this block sets as Data Type Conversion does.
Sample results#
No sample run is committed for this block. Samples come from the headless harness (DOCS_PLAN.md P8.1) into docs/generated/samples/; until one exists this block's behaviour is witnessed by the parity and export-verification suites, not by a plot here.