String to DINT (STOD)

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 String to DINT (STOD) instruction converts the ASCII representation of an integer to an integer or REAL value.
Available Languages
Ladder Diagram
STOD_LD_avail_v31
Function Block
This instruction is not available in function block.
Structured Text
STOD(Source,Dest);
Operands
There are data conversion rules for mixed data types within an instructions. See
Data Conversion
.
Ladder Diagram and Structured Text
Operand
Type
Format
Description
Notes
Source
String type
Tag
The tag that contains the value in ASCII
String types are:
  • Default STRING data type
  • Any new string type you create
Destination
SINT
INT
DINT
Tag
The tag to store the integer value
If the Source value is a floating-point number, the instruction converts only the non-fractional part of the number (regardless of the destination data type).
See
Structured Text Syntax
for more information on the syntax of expressions.
Description
The STOD instruction converts the Source to an integer and places the result in the Destination.
  • The instruction converts positive and negative numbers.
  • If the Source string contains non-numeric characters, the STOD converts the first set of contiguous numbers:
The instruction skips any initial control or non-numeric characters, except the minus sign in front of a number.
If the string contains multiple groups of numbers that are separated by delimiters (e.g., /), the instruction converts only the first group of numbers.
Affects Math Status Flags
In Ladder Diagrams only. See
Math Status Flags
.
Major/Minor Faults
Type
Code
Cause
Recovery Method
4
51
The LEN value of the string tag is greater than the DATA size of the string tag.
Check that no instruction is writing to the LEN member of the string type tag.
In the LEN value, enter the number of characters that the string contains.
4
53
The output number is beyond the limits of the destination data type.
  • Reduce the size of the ASCII value, or
  • Use a larger data type for the destination
See
Common Attributes
for operand-related faults.
Execution
Ladder Diagram
Condition
Action Taken
Prescan
N/A
Rung-condition-in is false
N/A
Rung-condition-in is true
The instruction executes.
Destination is cleared
The instruction converts the Source.
Postscan
N/A
Structured Text
Condition
Action
Prescan
See Prescan in the preceding Ladder Diagram table
Normal execution
See rung-condition-in is true in the preceding Ladder Diagram table.
Postscan
See Postscan in the preceding Ladder Diagram table
Example
When MV_read.EM is set, the STOD instruction converts the first set of numeric characters in MV_msg to an integer value. The instruction skips the initial control character ($06) and stops at the delimiter (\).
Ladder Diagram
STOD_LD_ex_v31
Structured Text
IF MV_read.EM THEN
STOD(MV_msg,MV_msg_nmbr);
MV_read.EM := 0;
END_IF;
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.