Converter
This function block converts a binary, numeric or text value into a "Dynamic Text” or vice versa. Furthermore it supports the copying of “Dynamic Texts”.
For the conversion of numeric values (besides BIT) a format string can be connected with the "format" input to get a special representation (such as a hexadecimal value or limited number of fractional digits). The standard conversion is performed when no format string is linked to the function block.
The conversion of single values is provided for all data types. An additional vector conversion can be performed only for the data type TEXT. The single texts of the vector are written into the allocated memory one after another and without the terminating 0 for the conversion into a “Dynamic Text”. However, the maximum length of 4095 characters cannot be exceeded. The other way round the “Dynamic Text” is divided in partial texts with a terminating 0, which are written into the vector elements.
When using a target system with Unicode support, the “Dynamic Texts” are coded in the UTF8 format. Therefore standard texts can only be assigned loss-free, if they agree with the UTF8 format. Otherwise characters with a value above 127 are replaced by question marks. The reverse conversion of “Dynamic Texts” into standard texts is also limited. Question marks with a value above 127 will be written instead of Unicode characters.
Format string
The format string, optionally used by converting numerical values, has to meet the target system specific conventions of the sprintf function. An overview of the most relevant features will be given here.
The format instruction always starts with the percentage symbol (%). It is followed by a number of optional parameters and ends with the specifier of the type of the input value. The parameters have to be given in the correct order and without a blank space between them, or they cannot be interpreted correctly. The formal description is the following:
%[flags][width][.precision][length]type specifier
A valid example is: %.2f
It is possible to add any text before and/or after the format instruction. This has no influence on the conversion, but the text will be part of the output. Consider that the input "format" only allows a limited number of characters. It is recommended to use the Append function block to add more text.
Type specifier:
The type specifier is a necessary parameter and specifies the expected data type and the basic display of the input value.
- d or i – decimal integer values
- x – hexadecimal integer values
- f – floating point values
- e – scientific notation of floating point values using the e character
- g – using the most compact style for floating point values (f or e)
Flags:
The flags are the first parameter(s) and are used to control the justification of the output. These parameters are not as commonly used.
- Minus (-): Left align within the given field (default is right align)
- Plus (+): Enforce the display of a sign (even with positive values)
- Space: If no sign is going to be written, a blank space is inserted before the value.
Width:
The second optional parameter defines the minimum number of characters written. If the value to be printed is shorter than this number, the result is padded with blank spaces.
Precision:
This parameter always starts with a dot and is a number, which is interpreted according to the specified type.
- Using d, i or x: defines the minimum number of characters to be written – if the value is shorter than this number, the result is padded with leading zeros.
- Using e or f: defines the number of digits after the decimal point – if necessary, it will be filled with trailing zeros
- Using g: Number of significant digits
Length:
The last optional parameter modifies the size of the data type and so the range of acceptable values. For our system there is no need for this parameter, except one.
- I64 (used with i or d:): 64 Bit integer value – is needed to cover the whole range of the LONGLONG data type
Parameters
The parameter dialog can be used to select the data types of the input and the output. Furthermore the size of an output vector can be determined, when converting to TEXT.
Signals
Name | I/O | Type(s) | Function |
---|---|---|---|
in | I | BIT, UCHAR, WORD, LONG, LONGLONG, FLOAT, DOUBLE, TEXT, DYNTEXT | Input signal |
format | I | TEXT | Format (optional) |
out | O | BIT, UCHAR, WORD, LONG, LONGLONG, FLOAT, DOUBLE, TEXT, DYNTEXT | Output signal |
Visualization
The selected data types are represented by the colors in the symbol.
Comment
The parameter dialog can only be opened in edit mode.