Middle String (MID)
This information applies to the
CompactLogix
5370, ControlLogix
5570, Compact GuardLogix
5370, GuardLogix
5570, Compact GuardLogix
5380, CompactLogix
5380, CompactLogix
5480, ControlLogix
5580, and GuardLogix
5580 controllers.The MID instruction copies a specified number of ASCII characters from a string and stores them in another string.
Available Languages
Ladder Diagram
Function Block
This instruction is not available in function block.
Structured Text
MID(Source,Qty,Start,Dest);
Operands
There are data conversion rules for mixed data types within an instruction. See Data conversions.
Ladder Diagram and Structured Text
Operand | Type | Format | Description | Notes |
---|---|---|---|---|
Source | ANY_STRING | Tag | The string to copy characters from | String types are: default STRING data type with max 82 length of characters for the string. any new string type you created with configurable length of characters for the string. |
Quantity | SINT
INT
DINT | Immediate
tag | The number of characters to copy | The Start plus the Quantity must be less than or equal to the length size of the Source plus 1. |
Start | SINT
INT
DINT | Immediate
tag | The position of the first character to copy | Enter a number between 1 and the DATA size of the Source. |
Destination | ANY_STRING | Tag | The string to copy the characters to |
See Structured Text Syntax for more information on the syntax of expressions within structured text.
Description
The MID instruction copies a group of characters from the Source and places the result in the Destination.
- The Start position and Quantity define the characters to copy.
- Unless the Source and the Destination are the same tag, the Source remains unchanged.
Affects Math Status Flags
No
Major/Minor Faults
A minor fault will occur if: | Fault Type | Fault Code |
---|---|---|
The LEN value of the Source string tag is greater than the DATA size of the Source string tag. | 4 | 51 |
The length of output string is larger than the DATA size of the destination string tag. | 4 | 52 |
The Start or Quantity value is invalid. | 4 | 56 |
Execution
Ladder Diagram
Condition | Ladder Diagram Action |
---|---|
Prescan | N/A |
Rung-condition-in is false | N/A |
Rung-condition-in is true | The instruction executes. |
Postscan | N/A |
Structured Text
Condition | Action |
---|---|
Prescan | See Prescan in the Ladder Diagram table |
Normal execution | See rung-condition-in is true in the Ladder Diagram table. |
Postscan | See Postscan in the Ladder Diagram table |
Example
In the baggage handling conveyor of an airport, each bag gets a bar code. Characters 9 through 17 of the bar code are the flight number and destination airport of the bag. After the bar code is read (bag_read.EM is on), the MID instruction copies the flight number and destination airport to the bag_flt_and_dest string. Subsequent rungs use bag_flt_and_dest to determine where to route the bag.
Ladder Diagram
Structured Text
IF bag_read.EM THEN
MID(bag_barcode,9,9,bag_flt_and_dest);
bag_read.EM := 0;
END_IF;
Provide Feedback