Basic Data Types
BOOL
Type
The BOOL
data type represents a binary value: 1
(true) or 0
(false). It’s commonly used for conditions, switches, and digital I/O.
Examples:
IF Start_Button THEN
Motor_Running := 1;
END_IF;
Use BOOL
for:
-
Inputs like push buttons or limit switches
-
Outputs like motors, lights, alarms
-
Internal flags and conditions
Integer Types
DINT
- 32-bit signed integer: range from -2,147,483,648 to 2,147,483,647
Examples:
Count := Count + 1;
Speed_Setpoint := 100;
Real Numbers
REAL
-
32-bit floating-point number
-
Supports decimal values like 23.7, -5.25, etc.
-
Used for math, measurement, and analog signals
Examples:
Temperature := 21.5;
Flow_Rate := Flow_Rate + 0.1;
Use REAL when:
-
Working with temperature, pressure, or flow sensors
-
Performing calculations that require fractions
Note: Use := to assign decimal values, and avoid mixing DINT and REAL types without proper conversion if needed.
Type Examples
Here's a few examples of Data Types in Structured Text:
Variable | Type | Explanation |
---|---|---|
Motor_Running | BOOL | Indicates whether the motor is running (on/off). |
Count | DINT | Stores a running total as a 32-bit integer. |
Temperature | REAL | Holds a temperature value with decimal precision. |