Tool collection for converting data types
With this entry we provide you with a tool collection of conversion functions. The functions are divided into four groups and are described in a brief overview below.
- Converter for floating point and fixed-point numbers
- Converter for string data types
- Converter for date/time and time operations
- Converter for various conversion functions
The detailed description for each conversion block is available in the added documentation with the following division:
- Description of the functions
- Block parameter lists of the functions
- Example of an application
- Technical data
The code for the conversion blocks and examples in form of a STEP 7 project or a STEP 7 library are available as download.
Converter for floating point and fixed-point numbers
- Converting a 32 bit floating point number into a 64 bit floating point number and vice versa
Using both functions FC21 "32TO64" and FC22 "64TO32" you convert the floating point numbers into the required 32 bit or 64 bit data format.
- Converting floating point numbers between the S7 and S5 format
Since the S7 real format differs from the S5 floating point format, it is not possible without conversion to adopt the formats into the respective other controller. Functions "S7ToS5-Floating" and "S5ToS7-Floating" are available for the conversion into the respective format.
- Converting a variable from data type DINT to INT
Function "DINT_TO_INT" enables you to convert a data double-word 32 bit integer into a data word 16 bit integer for the three programming languages LAD/FBD/STL. The conversion is checked for the limit values -32768 and 32767 and the result is displayed in a Boolean variable.
Converter for string data types
- Converting an integer into ASCII characters
Function "INT_TO_ASCII" converts an integer into an ASCII character without programming the intermediate step via a string variable.
- Converting string variables in ASCII text format
Function "PRGEN" converts a string variable entirely into ASCII text format. Here the first two bytes of the string (contain the maximum and actual length specification of the string) are replaced by the ASCII code for "line break" and "line feed". This is necessary for certain applications, for example, if the string variable is printed out directly on a printer.
Converter for date/time and time operations
- Converting Time to DINT and vice versa
Function "TIME_TO_DINT" enables storing a variable of data type Time in five data double-words as integer. It is divided into the components "days, hours, minutes, seconds and milliseconds". Reconversion occurs with function "DINT_TO_TIME".
- Converting DATE_AND_TIME to STRING and vice versa
Function "DT_TO_STRING" converts a DATE_AND_TIME variable to a string using a date and time character sequence. The character sequence in the string variable is stored in the following format: DD/MM/YY hh:mm:ss:ccc. The separators in the date representation can be selected at random. Reconversion occurs with function "STRING_TO_DT".
Note: During the conversion the information for the week day is not considered.
Converter for various conversion functions
- Converting numbers in binary code to gray code and vice versa
Gray code is a symmetrical way of generating code where neighboring numbers differ in only one single dual number. Three functions respectively are available for converting binary code to gray code and vice versa. The only difference between the function groups is that the output variable is available in formats "byte, word and DWORD".
- Temperature conversion from degree Celsius to degree Fahrenheit or from degree Celsius to degree Kelvin and vice versa
The following four functions are available for converting temperature values into different units:
- Converting degree Celsius to degree Fahrenheit using the function "Tmp_C_F" and
the reconversion with function "Tmp_F_C"
- Converting Kelvin to degree Celsius with function "Tmp_K_C" and
reconversion with function "Tmp_C_K"
|Content of the downloads||Download|
|SIMATIC STEP 7 code of the conversion blocks|
Used test environment:
|PC platform||2.33GHz 2GB RAM|
|Operating system||Windows XP SP2|
|SIMATIC STEP 7||V5.4 with SP3 + HF1|