×

Subscribe to newsletter

subscribe to our weekly newsletter to get notified with latest story and article Subscribe now!




PLC BLOG | Siemens string data types and string function
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


Siemens string data types and string function

string data type store character . range of character for string data types is 0 to 255. for example STRING[3]='plc' or string="hellow word". in brackets you can declare range of character. for example STRING[2], so this store only 2 character. in Siemens string is complex data type. siemens Complex data types define data groups that are larger than 32 bits. string Defines a group with a maximum of 254 characters (data type CHAR). The standard area reserved for a character string is 256 bytes long. This is the space required to save 254 characters and a header of 2 bytes. You can reduce the memory required for a string by defining the number of characters that will be stored in the character string. for example string[3] = 'plc'. You must enclose your character string in single quotation marks. string is one dimensional array with a maximum 254 character.


Format of the Data Type STRING

Format of the Data Type STRING

    STRING[n] or string: where 'n' specifies the length of the character string. A maximum length of 254 characters is permitted. If no length is specified, the default setting is 254 characters.
    for example
  • string[7]='siemens' string length is 7, this store only 7 character without space.
  • string[8]='plc blog' in this example total 7 character and one space so total character length is 8.


string data type declaration

make a data block (DB) declare string data types with length and save the data block.

declare your string data type in data block

    in this data block input_string1, input_string2 and output_string have 254 character length. input_string_lenth have 6 character length.


string function block

Following iec string blocks available in siemens, for inserting theses blocks go to projectr > libraries > IEC than select your string block

    basic string blocks:
  • FC21 LEN
  • FC20 LEFT
  • FC32 RIGHT
  • FC26 MID
  • FC2 CONCAT
  • FC17 INSERT
  • FC4 DELETE
  • FC31 REPLACE
  • FC11 FIND

    Comparing STRING function blocks:
  • FC10 EQ_STRNG
  • FC13 GE_STRNG
  • FC15 GT_STRNG
  • FC19 LE_STRNG
  • FC24 LT_STRNG
  • FC29 NE_STRNG

    Converting string Data Type Formats
  • FC16 I_STRNG
  • FC5 DI_STRNG
  • FC30 R_STRNG
  • FC38 STRNG_I
  • FC37 STRNG_DI
  • FC39 STRNG_R



some of the example of string function blocks


FC 21 : LEN

A STRING variable contains two lengths, the maximum length which is given in square brackets when the variables are being defined, and the current length which is the number of currently valid characters. The current length must be smaller than or equal to the maximum length. The number of bytes occupied by a string is 2 greater than the maximum length. The function FC21 outputs the current length of a string as a return value. A blank string (' ') has the length zero. The maximum length is 254. The function does not report any errors.
    Parameters of FC 21
  • input S is string data type
  • OUTPUT RET_VAL is INT data type

FC 21 : LEN

    This function blocks have one input as string , output of this block is int type when. Output return length of input string. For example if your input string is 'plc' output is 3. if input of this block is 'plc blog' than output is 8 (7 character and 1 for space).


FC10 EQ_STRNG

FC10 blocks is string comparison block it compares two input string if both input sting is equal than it return 1 at the output (RET_VAL) otherwise 0.
    parameters of FC 10
  • input S1 and S2 are string data type
  • OUTPUT RET_VAL is bool data type

FC10  EQ_STRNG

    if the input of S1 is 'siemens' and input of S2 is 'Siemens' than output RET_VAL is 1 otherwise output is 0.


FC11 FIND

The function FC11 provides the position of the second string (IN2) within the first string (IN1). The search starts on the left; the first occurrence of the string is reported. If the second string is not found in the first, zero is returned. The function does not report any errors.
    parameters of FC 11
  • input IN1 string data type : STRING variable to be searched in
  • input IN2 string data type : STRING variable to be found
  • OUTPUT RET_VAL is INT data type : Position of the string found

FC11  FIND

  • if the input string of IN1 is 'plc blog' and input string of IN2 is 'plc' than output RET_VAL is 1 otherwise output is 0.
  • if the input string of IN1 is 'plc blog' and input string of IN2 is 'blog' than output RET_VAL is 5 otherwise output is 0.


FC13 GE_STRNG

FC13 is a string comparison blocks, if string value of S1 is greater than or equal to the string value of S2 than output RET_VAL is 1 otherwise 0.
    parameters of FC 13
  • input S1 and S2 are string data type
  • OUTPUT RET_VAL is bool data type

FC13  GE_STRNG

    if the input of s1 is plc and input value of s2 is 'blog' than output is zero if the value of s1 is 'plc' and value of s2 is 'plc' than output is 1.


 
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


Suggested Post


 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

comment