0
IF  IP_emo:=FALSE THEN
    State:= OFF_Mode;
ELSE
    State :=OFF AND  IP_emo:=TRUE AND start_Btn:=TRUE OR start_Btn:=False;
    State:= Monitor_Mode;
END_IF

I am not sure why I am getting error 4024 on this code requiring a := before "THEN". Can someone help me?

mrsargent
  • 2,267
  • 3
  • 19
  • 36
Ruach02
  • 1
  • 1

2 Answers2

2

Disclaimer: Not sure what plc you are using or what error 4024 means but I can comment on the format of your code if you use a typcicaly IEC 61131 plc language (which most plcs are).

First, the := i an assignment operator. The = is a comparison operator. So in your if statment you would use

IF IP_emo = FALSE THEN

or alternatively (depending on which plc you use. typically all IEC 61131 languages are the same though)

IF NOT IP_emo THEN

Secondly, AND and OR are for comparison so you can't have them with an assingment operator. You can do something like

ELSE
   State :=OFF;
   IP_emo:=TRUE; 
   start_Btn:=TRUE; 
   start_Btn:=FALSE;
   State:= Monitor_Mode;
END_IF

or maybe

 ELSE
   State :=OFF;
      IF IP_emo=TRUE AND start_Btn=TRUE AND (start_Btn=TRUE OR start_Btn=FALSE) THEN
          State:= Monitor_Mode;
      END_IF
END_IF

not exactly sure what you are trying to do.

mrsargent
  • 2,267
  • 3
  • 19
  • 36
1

You don't mention what PLC or tool you are using, what the error 4024 means and which line it comes from. That makes it a little hard to answer your question. Some would probably say that the question qualifies for a down-wote on that account.

I'm a little confused by the formatting of your example. Please format as code (done automatically, if you use 4 spaces indent) and it will be easier to read and answer.

I made an attempt at formatting below, and have some comments to that.

  • Line 1: Normally you wouldn't use := but only = before THEN (might depend on the compiler, but I doubt it)
  • Line 4: There's too many :='s. Should this line and the following maybe have been split into some ELSIF's or another nested IF?

I hope that helps. :-)

IF IP_emo:=FALSE THEN
  State:= OFF_Mode;
ELSE
  State :=OFF AND IP_emo:=TRUE AND start_Btn:=TRUE OR start_Btn:=FALSE;
  State:= Monitor_Mode;
END_IF
pboedker
  • 523
  • 1
  • 3
  • 17