Search code examples
twincat

Writing memory bit value - TwinCat 2


I've been trying to write values to memory bits if certain conditions are verified, but so far not very successfully. In the piece of code presented below I have 3 variables which I've set to 1, therefore the condition returns the value TRUE (I've tested this). However, the values of variables "M_ALARME_BENCH_STOP" and "M_ALARME_BENCH_WARN" (memory bits) do not comute to the desired values. What am I doing wrong/missing?

IF ((S_DHW_IN_TP = 1) AND (IU_DHW_IN_TP = 1) AND (C_DHW_IN_TP = 1)) THEN
    M_ALARME_BENCH_STOP := TRUE;
    M_ALARME_BENCH_WARN := FALSE;
ELSIF ((S_DHW_IN_TP = 0) AND (IU_DHW_IN_TP = 1) AND (C_DHW_IN_TP = 1)) THEN
    M_ALARME_BENCH_WARN := TRUE;
    M_ALARME_BENCH_STOP := FALSE;
ELSE
    M_ALARME_BENCH_WARN := FALSE;
    M_ALARME_BENCH_STOP := FALSE;
END_IF

Solution

  • The piece of code you provided should work as you described. Are you sure, that these 2 variables are not being set somewhere else in your code after this IF statement?

    You can check it by placing a breakpoint directly after END_IF. If they are set to desired values on the breakpoint, then they are probably reset somewhere else.