File Sort (SRT)

This information applies to the
CompactLogix
5370,
ControlLogix
5570,
Compact GuardLogix
5370,
GuardLogix
5570,
CompactLogix
5380,
CompactLogix
5480, and
ControlLogix
5580 controllers. Controller differences are noted where applicable.
The SRT instruction sorts a set of values in one dimension (Dim to vary) of the array into ascending order.
Available Languages
Ladder Diagram
RSL5K_SRT Ladder Diagram_v31
Function Block
This instruction is not available in function block.
Structured Text
SRT(Array,Dimtovary,Control);
Operands
Ladder Diagram
Operand
Type
Format
Description
Array
SINT
INT
DINT
REAL
Array tag
array to sort
specify the first element of the group of elements to sort
Dimension to vary
DINT
Immediate
(0, 1, 2)
which dimension to use
the order of the dimensions is: array[0,1,2]
Control
CONTROL
Tag
control structure for the operation
Length
DINT
Immediate
number of elements of the array to sort
Position
DINT
Immediate
current element in the array
initial value is typically 0
Length and Position (corresponding to .LEN and .POS in the control tag) are pseudo-operands. For details, see Pseudo-operand initialization.
Structured Text
Operand
Type
Format
Description
Array
SINT
INT
DINT
REAL
Array tag
array to sort
specify the first element of the group of elements to sort
Dimension to vary
DINT
Immediate
(0, 1, 2)
which dimension to use
the order of the dimensions is: array[0,1,2]
Control
CONTROL
Tag
control structure for the operation
Length
DINT
Immediate
Number of elements of the array to sort.
The specified Length and Position values are accessed from the .LEN and .POS members of the CONTROL structure.
Position
DINT
Immediate
current element in the array
initial value is typically 0
The specified Length and Position values are accessed from the .LEN and .POS members of the CONTROL structure.
See Structured Text Syntax for more information on the syntax of expressions within structured text.
CONTROL Structure
Mnemonic
Data Type
Description
.EN
BOOL
The enable bit indicates the SRT instruction is enabled.
.DN
BOOL
The done bit is set when the instruction has operated on the last element in the Array.
.ER
BOOL
The error bit is set when either .LEN < 0 or .POS < 0. Either of these conditions also generates a major fault.
When .ER bit is set, the instruction does not execute.
.LEN
DINT
The length word specifies the number of elements in the array on which the instruction operates.
.POS
DINT
The position word identifies the current element that the instruction is accessing.
Description
The SRT instruction sorts a set of values in one dimension (Dim to vary) of the Array into ascending order.
IMPORTANT:
You must test and confirm that the instruction does not change data that you don’t want it to change.
The SRT instruction operates on contiguous data memory. For the
CompactLogix
5370,
ControlLogix
5570,
Compact GuardLogix
5370, and
GuardLogix
5570 controllers
only, the scope of the instruction is constrained by the base tag. The SRT instruction will not write data outside of the base tag but can cross member boundaries. If you specify an array that is a member of a structure, and the length exceeds the size of that array you must test and confirm that the SRT instruction does not change data you do not want changed.
In the
CompactLogix
5380,
CompactLogix
5480,
ControlLogix
5580,
Compact GuardLogix
5380, and
GuardLogix
5580 controllers
, the data is constrained by the specified member.
In this transitional instruction, the relay ladder toggles the rung-condition-in from false to true for the instruction to execute.
Affects Math Status Flags
Controllers
Affects Math Status Flags
CompactLogix
5380,
CompactLogix
5480,
ControlLogix
5580,
Compact GuardLogix
5380, and
GuardLogix
5580 controllers
No
CompactLogix
5370,
ControlLogix
5570,
Compact GuardLogix
5370, and
GuardLogix
5570 controllers
Yes
Major/Minor Faults
A major fault will occur if:
Fault type
Fault code
.POS < 0 or .LEN < 0
4
21
Dimension to vary > number of dimensions
4
20
Length > end of array
4
20
See
Common Attributes
for operand related faults.
Execution
Ladder Diagram
Condition / State
Action Taken
Prescan
N/A.
Rung-condition-in is false
.EN bit is cleared to false
.EN bit is cleared to false
.DN bit is cleared to false
Rung-condition-in is true
The instruction executes
Postscan
N/A.
Structured Text
Condition / State
Action Taken
Prescan
See Prescan in the Ladder Diagram table
Normal execution
Since this instruction requires a transition to execute it is executed false and then true. See the Ladder Diagram table for details.
Postscan
See Postscan in the Ladder Diagram table.
Examples
Example 1
Sort DINT_array, which is DINT[4,5].
SRT Example 1
Ladder Diagram
RSL5K_SRT Ladder Diagram__example1_v31
Structured Text
IF sort1 then
control_1.LEN := 4;
control_1.POS := 0;
SRT(DINT_array[0,2],0, control_1);
END_IF;
Example 2
Sort DINT_array, which is DINT[4,5].
File Sort (SRT) (10)
Ladder Diagram
RSL5K_SRT Ladder Diagram__example2_v31
Structured Text
ctrl.LEN := 4;
ctrl.POS := 0;
SRT(DINT_array[0,2],0, ctrl);
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.