User's Manual

PMAC User Manual
234 Writing a PLC Program
Opening the Buffer
For each PLC program, the next step is to open the buffer for entry with the OPEN PLC n statement,
where n is the buffer number. Next, if there is anything currently in the buffer that should not be kept, it
should be emptied with the CLEAR statement (PLC buffers may not be edited on the PMAC itself; they
must be cleared and re-entered). If the buffer is not cleared, new statements will be added onto the end of
the buffer.
Downloading the Program
Typically, in program development, the editing will be done in a host-based text editor, and the old buffer
is cleared every time the new version is downloaded to the card. When finished, close the buffer with the
CLOSE command. Opening a PLC program buffer disables that program automatically. After it is
closed, it remains disabled, but it can be re-enabled again with the ENABLE PLC n command, where n
is the buffer number (0—31). I5 must also be set properly for a PLC program to operate.
The general form for this technique is:
CLOSE
DELETE GATHER
DELETE TRACE
OPEN PLC n
CLEAR
{PLC statements}
CLOSE
ENABLE PLC n
Note:
Because all PLC programs in the PMAC memory are enabled at power-on/reset it
is good practice to have I5 saved as 0 in the PMAC memory when developing PLC
programs. This will allow PMAC to be reset without PLCs running (an enabled
PLC only runs if I5 is set properly) and more easily recover from a PLC
programming error.
Closing the Buffer
At the closing, PMAC checks to make sure all IF branches and While loops have been terminated
properly. If not, it reports an error, and the buffer is inoperable. Correct the PLC program in the host and
re-enter it (clearing the erroneous block in the process, of course). This process is repeated for all of the
PLC buffers in use.
Erasing the Program
To erase an uncompiled PLC program, open the buffer, clear the contents, then close the buffer again.
This can be done with three commands on one line, as in:
OPEN PLC 5 CLEAR CLOSE
Example
A quick example of a PLC block entry is shown below:
OPEN PLC 2
CLEAR
IF (M11=1)
I130=10000
ELSE
I130=8000
ENDIF
CLOSE
ENABLE PLC 2