×
Siemens Industry Online Support
Siemens AG
Entry type: FAQ Entry ID: 10913338, Entry date: 08/15/2007
(2)
Rate

Which functions and IEC standard functions exist in STEP 7 for converting and comparing string variables?

  • Entry
  • Associated product(s)

Configuration Notes:
There is a series of functions and IEC standard functions available in STEP 7 for converting and comparing string variables. You can find the IEC standard functions in the block editor catalog under "Libraries / Standard Library / IEC Function Blocks", and the technical description of the functions and on how to parameterize the variables are available via the STEP 7 Online Help (F1 key).

IEC standard functions for converting and comparing string variables:
 

No. Description:
1 FC5 DI_STRNG: Conversion of a DINT-type variable into a STRING-type variable.


Fig. 01
2 FC10 EQ_STRNG: Compares the content of two STRING-type variables to see if they are "equal".


Fig. 02
3 FC13 GE_STRNG: Compares the content of two STRING-type variables to see if they are "greater than or equal to".


Fig. 03
4 FC15 GT_STRNG: Compares the content of two STRING-type variables to see if they are "greater than".


Fig. 04
5 FC16 I_STRNG: Conversion of an INT-type variable into a STRING-type variable.


Fig. 05
6 FC19 LE_STRNG: Compares the content of two STRING-type variables to see if they are "less than or equal to".


Fig. 06
7 FC24 LT_STRNG: Compares the content of two STRING-type variables to see if they are "less than".


Fig. 07
8 FC29 NE_STRNG: Compares the content of two STRING-type variables to see if they are "not equal".


Fig. 08
9 FC30 R_STRNG: Conversion of a REAL-type variable into a STRING-type variable.


Fig. 09
10 FC37 STRNG_DI: Conversion of a STRING variable into a DINT-type variable.


Fig. 10
11 FC38 STRNG_I: Conversion of a STRING variable into an INT-type variable.


Fig. 11
12 FC39 STRNG_R: Conversion of a STRING variable into a REAL-type variable.


Fig. 12

IEC standard functions for editing string variables:
 

No. Description:
1

FC2 CONCAT: Concatenating STRINGs.


Fig. 13
2 FC4 DELETE: Deleting a STRING.


Fig. 14
3

FC17 INSERT: Inserting a STRING.


Fig. 15
4 FC20 LEFT: Left part of a STRING.


Fig. 16
5 FC21 LEN: Length of a STRING.


Fig. 17
6 FC26 MID: Middle part of a STRING.


Fig. 18
7 FC31 REPLACE: Replacing a STRING.


Fig. 19
8 FC32 RIGHT: Right part of a string.


Fig. 20

Sample programs for converting string variables:
 

No. Description:
1 Conversion of a string variable into a floating point number
The download "String_R" contains FC104 for converting a string into a floating point number. In contrast to the IEC function FC39, the string can appear here in simplified format, e.g. '+''1''2''.''3''4' or '-''1''2''.''3''4'. In the case of calls in the OB1, for instance, the following input and output variables (Fig. 21) must be parameterized:


Fig. 21

The variables for the string are contained as a "CHAR" data type in the DB100 data block. The start of the string (here, from data byte 1) is defined by the parameter "Str_DBB_NO", and the length of the string (here, 5 bytes) is defined by the parameter "LEN".


Fig. 22

The parameter "ERROR" contains the value 'True' if the first byte of the string is not "+" or "-", if the values are outside the range 0 to 9 (Fig. 22), or if there is more than one point within the string.

String_R.zip ( 32 KB )

The attached download contains a STEP 7 project with the blocks described above. Copy the ZIP file into a separate folder and then start the file with a double-click. The STEP 7 project is now unpacked automatically with all the associated subdirectories. You can use the SIMATIC Manager to open and process the extracted project.

Note on billable software:
We also recommend the sample programs listed below, which you can find on the Internet under the Entry ID specified. You can pay with your SIMATIC Card / Automation Value Card AVC.

  • The three length dimensions (length, width, thickness) are read into the CP340 via RS232 in order to evaluate the values in the S7-300 and display them on an OP. Entry ID 8797119. This sample program enables you to evaluate an ASCII string (e.g. with length details), which is sent to a CP340 via RS232, in your SIMATIC controller.

  • Conversion of a "CHAR field" into a "string variable". Entry ID 25629271. An "ARRAY of character" is converted into a "string variable" in this example.

  • Conversion of an integer into ASCII characters without using the STRING data type. Entry ID 25629271. In the attached sample program, an integer is broken down into individual ASCII characters via a function.

  • Conversion of a DATE_AND_TIME variable into a string variable. Entry ID 25629271

Keywords:
ASCII code, Data evaluation, Strings, Data transfer

Security information
In order to protect technical infrastructures, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art IT security concept. Siemens’ products and solutions constitute one element of such a concept. For more information about cyber security, please visit
https://www.siemens.com/cybersecurity#Ouraspiration.
Rate entry
no rating
Requests and feedback
What do you want to do?
Note: The feedback always relates to the current entry / product. Your message will be forwarded to our technical editors working in the Online Support. In a few days, you will receive a response if your feedback requires one. If we have no further questions, you will not hear from us.