String Length (SLEN) Instruction

Mnemonic (Keyboard Shortcut) = SLEN

Icon / Button =

Purpose

To determine the Number of Characters in a String.

Instruction Parameters

 

Parameter

Parameter Type

Requirements

Description

Enable

Ladder Input

Must Have

Level-driven.  When Enable is ON, the instruction will operate every scan.  When Enable is OFF, instruction is not solved and its output is not updated.

Input

String

Must Have

The String to be examined.  Up to 128 Characters.

Length

Numerical Tag

Must Have

Tag that holds the determined Length (Number of Characters) of the Input String.  Spaces are counted as Characters.

 

Note: Tag Values are updated immediately
as each Ladder Rung is executed,
top to bottom.  However, Tag Values
representing physical Outputs
are only applied to the physical Output
after the END statement of the
last Task to be scanned is reached.
 Outputs in Remote
Base Groups have additional limitations regarding Update
Intervals.

Instruction Configuration

When String Length Instruction is selected the window shown below opens with defaults shown.

Parameter
Configuration Table

String Length

Instruction


(SLEN)

Notes

Input

 

 

 

 

 

 

 

 

 

Enter a String
Length up to 128 Characters.

Length

 

 

 

Enter a Tag
to hold determined Length.

Application Example

In the following example, the String Length instruction is used to determine the actual text Length contained inside of a String Tag.  The String has embedded data from an outside device (flow meter, operator interface, etc.) that is variable in Length.

  

The String Length instruction is used in conjunction with the Find String instruction to calculate the size of the data value so that it can be extracted and used for whatever purpose is needed.  The following ladder is extracting variable Flow Data (Flow1=987) from a String by locating the text Flow1=.  This Rung determines the String Length of 9.

 

The Find String instruction is used to search specified data within the String by using From and To Indices. The String Length is used in the To Index (last element in the String to search).  In this example the String is being searched From 1 To 9.  If the Flow increases to over 999, then the String Length will change to 10.

Math is performed to determine an offset by adding the Found Index (1) to the text Flow1= (6 characters).  This will be used to separate the data from the text.

 

Math is now performed to determine the Flow Data Length.  A value of one (1) must be added to the String Length (Base 1).  Subtracting the Found Index Offset shows that the Flow Data Length is 3.

With the gathered information, the Flow Data can be extracted using the Found Index Offset and Flow Data Length in the Extract String instruction.

Related Topics Link IconRelated Topics

Related Topics


Rate this post