我认为没有任何方法可以输入 100 多个警报或变量。作为最低要求,您必须评估每个警报条件以设置它的警报。
我觉得有用的一种方法是定义一个包含所有警报的枚举列表,然后使用它来设置警报数组中的各个警报位。如果您只想设置一个警报标志,则可以迭代整个数组。或者,如果您有多个标志,则可以相应地对枚举进行分组和迭代。
VAR
arrAlarm: ARRAY [0 .. ALARM_SIZE] OF BOOL;
bFlag: BOOL;
bFlag1, bFlag2: BOOL;
i: INT;
END_VAR
(* Example code for setting alarmbits. This could mean 100+ lines... *)
arrAlarm[ALARM_CircuitBreaker1] := IO_a;
arrAlarm[ALARM_CircuitBreaker2] := IO_b;
arrAlarm[ALARM_CircuitBreaker3] := IO_c;
arrAlarm[ALARM_Temperature1] := IO_d > 100;
arrAlarm[ALARM_Temperature2] := IO_e > 100;
arrAlarm[ALARM_Temperature3] := IO_f > 100;
arrAlarm[ALARM_EmergencyStop] := NOT IO_g;
(* Example code for setting alarm flags. This could be even simpler if only one flag *)
bFlag := FALSE;
FOR i := 0 to ALARM_SIZE - 1 DO
IF arrAlarm[i] THEN
bFlag := TRUE;
END_IF;
END_FOR;
bFlag1 := FALSE;
FOR i := ALARM_Temperature1 to ALARM_Temperature3 DO
IF arrAlarm[i] THEN
bFlag1 := TRUE;
END_IF;
END_FOR;
bFlag2 := FALSE;
FOR i := ALARM_CircuitBreaker1 to ALARM_EmergencyStop DO
IF arrAlarm[i] THEN
bFlag2 := TRUE;
END_IF;
END_FOR;
(* Definition of alarms. These could be an extract from a definition file *)
TYPE E_ALARM :
(
ALARM_Temperature1,
ALARM_Temperature2,
ALARM_Temperature3,
ALARM_CircuitBreaker1,
ALARM_CircuitBreaker2,
ALARM_CircuitBreaker3,
ALARM_EmergencyStop,
ALARM_SIZE,
);
END_TYPE