unger
I am trying to learn how to write programs in PLC. Specifically, structured text. I have written a program for an elevator process but have been getting the following error upon runtime. Is anyone able to help me with this?  Also, the following are underlined in red like there is some syntax error: "PROGRAM elevatorProcess", "VAR", "BEGIN", "WAIT_SEC", "END_PROGRAM"

The error: 

In section: PROGRAM elevatorProcess
0153: END_PROGRAM;
In section: END_PROGRAM
0154: END_PROGRAM
1 error(s) found. Bailing out!


Here is my program: 

PROGRAM elevatorProcess

VAR
floor : INT;
destination : INT;
buttonPressed : BOOL;
doorOpen : BOOL;

BEGIN

(* Set the current floor to 1*)
floor := 1;

(* Set the door open flag to false*)
doorOpen := false;

(* Start the main loop*)
WHILE TRUE DO

(* Check if a button has been pressed*)
IF buttonPressed THEN
(* Set the destination floor*)
destination := floor;
END_IF

(*Check if the elevator is at the destination floor*)
IF floor = destination THEN
(* Open the door*)
doorOpen := true;

(* Wait for 5 seconds*)
WAIT_SEC(5);

(* Close the door*)
doorOpen := false;
END_IF

(* Check if the elevator is below the destination floor*)
IF floor < destination THEN
(* Go up one floor*)
floor := floor + 1;
END_IF

(* Check if the elevator is above the destination floor*)
IF floor > destination THEN
(* Go down one floor*)
floor := floor - 1;
END_IF

END_WHILE
END_PROGRAM;

Reply 0 0
thiagoralves
You should only place the body of your Structured Text program in the editor. Variable and program declarations are done in the editor graphically. Additionally, WAIT_SEC is not a valid IEC function. You should define it first before using.
Reply 0 0
thiagoralves
I just read your program more carefully. I don't know if you copied this program from somewhere else, but this is all wrong. Using an infinite WHILE loop like this will lock your PLC and you won't see any action happening. PLCs are cyclic machines. Inputs and outputs states are calculated at the beginning/end of a cycle. If you lock the cycle with an infinite loop, the PLC will never calculate inputs and outputs, and so your program will stay stuck in there forever. You cannot program a PLC like you program a microcontroller.
Reply 0 0
unger
Thank you for your feedback. This is the first program I have written. I usually code in Python, C, and C++ so I am trying to learn PLC on my free time. I have just changed my program to a cyclic structure. But am not sure what the syntax is like for structured text. I keep getting the following errors: 
Errors: 
exited with status 1 (pid 6444)
C:\Users\Desktop\PLC_Projects\Elevator Process\build\plc.st:115-4..115-6: error: ';' missing at the end of statement in ST statement.
In section: PROGRAM elevatorProcess
0115: IF floor = destination THEN;
C:\Users\Desktop\PLC_Projects\Elevator Process\build\plc.st:115-32..116-15: error: invalid variable before ':=' in ST assignment statement.
In section: PROGRAM elevatorProcess
0115: IF floor = destination THEN;
0116: doorOpen := true;
C:\Users\Desktop\PLC_Projects\Elevator Process\build\plc.st:121-4..121-6: error: ';' missing at the end of statement in ST statement.
In section: PROGRAM elevatorProcess
0121: IF doorOpen AND elapsedTime >= 5000 THEN
C:\Users\Desktop\PLC_Projects\Elevator Process\build\plc.st:125-4..125-6: error: ';' missing at the end of statement in ST statement.
In section: PROGRAM elevatorProcess
0125: elapsedTime := elapsedTime + T#1S;
C:\User\Desktop\PLC_Projects\Elevator Process\build\plc.st:131-4..131-6: error: ';' missing at the end of statement in ST statement.
In section: PROGRAM elevatorProcess
0131: IF floor > destination THEN
C:\Users\Desktop\PLC_Projects\Elevator Process\build\plc.st:135-2..135-4: error: ';' missing at the end of statement in ST statement.
In section: PROGRAM elevatorProcess
0135: UNTIL false;
C:\Users\Desktop\PLC_Projects\Elevator Process\build\plc.st:111-5..111-4: error: unclosed 'REPEAT' statement in ST.
In section: PROGRAM elevatorProcess
0111: IF buttonPressed THEN
C:\Users\Desktop\PLC_Projects\Elevator Process\build\plc.st:146--1..146-1: error: ';' missing at the end of statement in ST statement.
C:\Users\Desktop\PLC_Projects\Elevator Process\build\plc.st:95-2..95-23: error: unclosed program declaration.
In section: PROGRAM elevatorProcess
0095: PROGRAM elevatorProcess

9 error(s) found. Bailing out!

Here is my revised program: 

floor := 1;

doorOpen := false;

REPEAT

IF buttonPressed THEN
destination := floor;
END_IF

IF floor = destination THEN
doorOpen := true;

elapsedTime := 0;
END_IF

IF doorOpen AND elapsedTime >= 5000 THEN
doorOpen := false;
END_IF

elapsedTime := elapsedTime + T#1S;

IF floor < destination THEN
floor := floor + 1;
END_IF

IF floor > destination THEN
floor := floor - 1;
END_IF

UNTIL false;
Reply 0 0
thiagoralves
I suggest you start with something simpler if you want to learn. Your code is missing semicolons ( ; ) on every END_IF call, not to mention you haven't fixed the infinite loop, you just replaced it with a different construct (REPEAT instead of WHILE) 😂 . You can't program a PLC the same way you program on your sequential languages. PLCs are programmed with "State machines" in mind.
Reply 0 0
Reply