Relational expressions, also known as comparison operators, are used to compare two values (operands) and return a Boolean result: either TRUE or FALSE. These operators are essential in programming logic because they help determine whether a specific condition is met. If the comparison is valid, the result is TRUE; otherwise, it is FALSE.
These operators are mainly used in conditional statements such as if, if-else, while, and for loops. They allow the program to evaluate conditions and take appropriate actions based on the result.
In industrial automation or PLC programming, relational expressions are used to compare real-time values such as sensor levels, timer values, counter presets, and setpoints.
These operators function similarly to comparison blocks used in ladder diagrams or graphical programming. They are often combined with conditional instructions to control process flow and automate decision-making.
Overall, relational expressions are a vital part of any control logic or software program. They enable intelligent decision-making, real-time evaluation, and the creation of responsive and efficient systems.
Expressions are calculated during the runtime of the program and return a value. An expression consists of operands (such as constants, tags or function calls) and optionally out of operators. Expressions can be linked together or nested within each other by operators.Common relational operators include:
The less than operator (<) in Siemens SCL is used to compare two operands. These operands can be constant values, numeric variables, strings, real numbers, or inputs such as process signals and sensor statuses. If the value of operand 1 is less than the value of operand 2, the expression returns TRUE; otherwise, it returns FALSE.
In the following example, two input values "level_1_sts" and "level_2_sts" are being compared to constant values 30 and 45 respectively using the less than operator.
The logic checks whether "level_1_sts" is less than 30 or "level_2_sts" is less than 45. If either of these conditions is TRUE, then the output "motor_1" is turned ON (set to TRUE), and "motor_2" is turned OFF (set to FALSE).
If neither condition is TRUE — meaning both "level_1_sts" is 30 or more, and "level_2_sts" is 45 or more — then both "motor_1" and "motor_2" are turned OFF.
This type of condition is helpful in process control applications where actions must be taken based on threshold values. For instance, if the tank level drops below a certain point, the motor can be started automatically to refill the tank.
The greater than operator (>) in Siemens SCL compares two values. It returns TRUE when the first operand is greater than the second. This is useful in control systems where actions are triggered when a variable, such as temperature or pressure, exceeds a threshold.
In this example, if the temperature value exceeds 70, motor_1 is activated, and motor_2 is deactivated. If the temperature is not above 70, the program checks if the manual switch is active. If it is, it turns off motor_1 and turns on motor_2. If neither condition is met, both motors remain off.
This logic demonstrates how the greater than operator works with IF and ELSIF conditions to create responsive control behavior based on real-time values.
The equal to operator (=) in Siemens SCL is used to compare two values and checks whether they are the same. If the comparison is true, it returns TRUE; otherwise, it returns FALSE. This operator is commonly used to compare binary signals such as inputs, outputs, or status flags in automation systems.
In this example, the condition checks if the value of "level_1" is TRUE. If the condition is satisfied, it means that a certain level has been reached or a sensor is active. As a result, motor_1_sts is set to 1, indicating that the motor should start or is in a running state.
This type of comparison is useful when monitoring digital signals such as switches, sensors, or control flags to initiate actions based on their states.
The less than or equal to operator (<=) in Siemens SCL is used to check whether the first operand is less than or equal to the second operand. If this condition is true, the result is TRUE; otherwise, it returns FALSE. This operator is commonly used in control logic where actions need to be taken when a value drops below or matches a threshold.
In this example, the logic checks whether the value of #level_1_value is less than or equal to 30. If this condition is satisfied, it means the level is low or critical. As a result, motor_1 is turned ON to possibly refill or balance the level.
This type of conditional comparison is useful in automation for triggering motors, pumps, alarms, or valves based on specific process thresholds such as tank levels, temperatures, or pressure values.
The greater than or equal to operator (>=) in Siemens SCL is used to compare two values. It returns TRUE if the first operand is greater than or equal to the second operand. This operator is useful when you want to include both threshold and above-threshold values in your condition.
In the given example, the program checks if the temperature is greater than or equal to 70. If this condition is TRUE, it means the system is overheating or reaching a high level. As a result, motor_1 is turned ON and motor_2 is turned OFF.
If the temperature is below 70, the program checks if the manual switch is activated. If it is TRUE, the logic turns OFF motor_1 and turns ON motor_2.
If neither of the conditions is satisfied, both motors are turned OFF. This control logic is helpful in real-time automation for handling temperature-based decisions with fallback to manual control.
The not equal to operator (<>) in Siemens SCL is used to compare two values and checks whether they are different. If the first operand is not equal to the second operand, the result is TRUE; otherwise, it returns FALSE. This operator is essential when a specific value must be excluded from the logic condition.
In this example, the program checks if the status value of "level_1_sts" is not equal to 30. If this condition is TRUE, meaning the level is not at 30, motor_1 is turned ON and motor_2 is turned OFF.
If the status is exactly equal to 30, then both motor_1 and motor_2 are turned OFF. This logic can be used for filtering out specific values or preventing certain actions when a process reaches a defined state.