Вы находитесь на странице: 1из 6

A PC-BASED OBJECT SIMULATOR FOR SUPPORTING PLC SOFTWARE

DEVELOPMENT
Jozef Kulisz.* Robert Czerwinski.** Jan Mocha.*** Miroslaw Chmiel.****

Silesian University of Technology, Institute of Electronics, Gliwice, Poland


* (e-mail: jozef.kulisz@polsl.pl)
** (e-mail: robert.czerwinski@polsl.pl)
*** (e-mail:jan.mocha@polsl.pl)
**** (e-mail: miroslaw.chmiel@polsl.pl)

Abstract: The paper discusses hardware and software tools used to support Programmable Logic
Controller (PLC) program testing and verification. An idea of a PC-based object simulator is presented.
The simulator consists of a PC equipped with an appropriate I/O card, and a simulator program running
on the PC. The simulator is capable of emulating behavior of real industrial objects. Thus a significant
part of software tests can be performed with the use of the simulator, instead of a physical object. This
can significantly facilitate, and accelerate development of an application.
Keywords: Industrial control, Programmable logic controllers, Program diagnostics, Debugging,
Simulation, Process simulators, Software engineering, Software productivity

1. INTRODUCTION
Testing and verification of complex applications constitutes a Using switchboards can be useful, if the number of PLC
serious problem for PLC (Programmable Logic Controller) inputs to emulate is not big. In some cases, where separate
programmers. In today’s highly competitive world, where devices or small groups of actuators work independently
design and construction companies compete both by reducing from one another, it is also possible to separately test portions
costs, and time to market, control and PLC engineers often of software controlling separate devices.
have work under pressure. Working to tight deadlines Unfortunately it often happens, that the installation has to be
enforces the management to shrink time schedules. Many operated by complex algorithms (e. g. sequences), imposing
parts of the design, construction and commissioning work many interlockings between various parts of the control
have to be done concurrently. Work on the program has to be system, including SCADA (Supervisory Control And Data
started and conducted, while essential parts of the Acquisition) for remote control, visualisation, reporting etc.
installation, that is supposed to be operated by the Under such circumstances testing separate devices is not
application, aren’t yet assembled. Even during the actual sufficient, and using switchboards to test the program as a
commissioning it often happens, that time slots, during which whole is practically unmanageable. It would require
the controlled equipment is freely available for testing, are following the algorithms, tracking the interactions, and
limited. For those reasons a substantial part of a PLC operating tens of switches in real time to provide adequate
application development process has to be conducted at simulation of real hardware.
office, while the equipment that is to be operated by the
program is not accessible to the programmer. So far the task of PLC program testing is hardly supported by
specialised software and hardware tools. The main purpose of
Furthermore, performing some test on real hardware can be the paper is to propose a new approach to PLC application
either difficult, or even impossible for technological, or, what testing and verification – an object simulator, which is an
is even more important, for safety reasons. independent device. The concept is presented after an
It’s a common practice, that at the beginning stages PLC overview of the methods of PLC program testing used so far.
programs are tested using switchboards wired up to PLC
input modules. By operating switches in the proper manner 2. TOOLS SUPPORTING PLC APPLCATION TESTING
one can emulate operation of real hardware, which will later
be connected to the PLC. By observing the indicator LED-s 2.1 PLC simulators
mounted on output modules, the programmer is able to check
whether the program generates the desired logic levels at A PLC simulator is a PC program, capable of simulating
PLC outputs. This method can also be used with analog behaviour of an actual PLC. The simulation is based on a
signals, it demands just applying a little more complex program code, written in the language characteristic for the
hardware, capable of producing analog values, e. g. voltages. simulated PLC, which is interpreted by the simulator
program. States of inputs of the simulated PLC can be forced of them simulates behaviour of the actual PLC, and the other
using an appropriate GUI (Graphical User Interface), and in one – the controlled objects. The simulators exchange
the same manner states of outputs and internal variables can information about the states of PLC inputs and outputs using
be observed (Fig. 1). tags, i. e. variables available at the level of the operating
system.
Dedicated object simulator modules are contained, apart from
PLC simulators, in the TrySim (TrySim, 2010) and PC_Simu
(PC_Simu, 2000) programs. Both programs feature simple
graphical editors, and the simulated objects can be assembled
by the user from a number of primitive elements.
In all of the concepts presented above the object is simulated
in the same PC, together with the PLC executing the tested
control program. This approach can thus be schematically
Fig. 1. The concept of a PLC simulator. depicted in Fig. 2.

Simulation tools are contained in some systems supporting


PLC program development, e. g. PLCSim, (2007), Unity
(2007), RSLogix (2004), RSLogix (2005). Apart from PLC
manufacturers, PLC simulators can also be supplied by third
party vendors, e. g. CoDeSys, (2003), ISAGraph, (2009),
IBHSoftec, (2010), TrySim, (2010), S7_200, (2000).
Using PLC simulation software allows the designer to avoid
inconvenient switchboards, as the states of simulated inputs
can be forced with a mouse, or a keyboard. Anyway
operating a PLC simulator for a greater number of I/O-s is Fig. 2. A PLC simulator, and a software object simulator
even more inconvenient, than using switchboards. PLC running in the same PC.
simulators can be effectively used, if the number of inputs
The TrySim (TrySim, 2010) and PC_Simu (PC_Simu, 2000)
and outputs to be simulated is not big. For applications, for
programs, in one of their modes of operation, can use an
which tens or hundreds of inputs have to be simultaneously
actual PLC instead of the PLC simulator program. In such a
operated, thorough testing with a PLC simulator is practically
case only the object is simulated in the program running on
unmanageable.
the PC, and information about states of inputs and outputs is
Another important problem, that has to be concerned by transmitted to and from the PLC through a communication
using simulation software, is, how realistic the simulation interface. This concept is schematically presented in Fig. 3.
actually is. The simulated inputs and outputs exist only
virtually in the software, and they have no physical
representation. It is thus not possible to reliably test certain
time-critical functions, like interrupts, high-speed counters,
and pulse train outputs. It may also happen that for various
reasons (e. g. bugs in the software) the simulator doesn’t
model operation of the PLC correctly.

2.2 Software object simulators in a PC Fig. 3. An object simulator running on a PC communicating


with a PLC through a communication interface.
A PLC simulator is a substitute of the PLC itself, not the
devices operated by the PLC. For testing more complex 2.3 Software object simulators in the PLC
applications some kind of test automation would be desirable.
Another kind of tool is thus needed – an object simulator, i. e.
A smart and low-cost solution of simulating a controlled
a simulator of the object to be controlled by the PLC.
object was proposed by Kulisz (2004). The author proposes
Tools of this kind are quite rear. Rockwell Automation to use the PLC itself as an object simulator. The idea consists
supplies PLC simulators, which support also the functionality in adding a special simulator subroutine to the actual PLC
of emulating feedback signals, which are normally generated program. The subroutine is invoked at the beginning of the
by objects controlled by the PLC. In the RSLogix Emulate main program scan. Its purpose is to simulate behaviour of
program (RSLogix, 2004), functions of the emulated feedback signals, which are normally generated by the
feedback signals can be described by the user in ladder controlled devices. The subroutine reads output states,
format, by using the so called “Debug Files”. In RSLogix produced by the actual control program, from the PIQ
Emulate 5000 this functionality is achieved by launching two (Process Output Image) memory, and, basing on this
instances of the PLC simulator program simultaneously – one information, it evaluates states of feedback signals, which are
then written directly to the PII (Process Input Image) memory 2. The simulator should provide visualisation of the state of
(Fig. 4). The simulation subroutine overrides this way logic simulated objects.
states sampled at physical inputs, and provides a kind of a
“dynamic force”. As the simulator subroutine is invoked at 3. Apart from simulating normal device operation, the
the beginning of the main system loop, its operation should software should feature also possibility of simulating
be transparent to the actual control program. device faults.
4. The tool should be universal, in particular it should
support creating models of new objects, and adding them
Simulator
to the library.
routine
5. The software should be user friendly.
PII PIQ
(inputs) (outputs) The first condition cannot be satisfactorily met for any of the
concepts discussed above. For all of the methods PLC inputs
Actual and outputs have no physical representation. Information
control about their states is exchanged between the PLC and the
program
object simulator using internal variables in the system, on
which the simulator is run. PLC I/O modules are bypassed,
Fig. 4. Object simulator as a subroutine inside the PLC. and functions and properties characteristic for them cannot be
simulated. In particular this means, that for any of the
The solution proposed by Kulisz is cost-efficient, it doesn’t concepts presented in p. 2.2, 2.3, it is not possible to
require any extra software or hardware, and can be realistically simulate time-critical functions, like interrupts,
immediately used for almost all PLC-s available on the high speed counters, pulse outputs. This is valid also for the
market. The programmer just needs to model operation of the concept presented in Fig. 3, where the PLC is not simulated,
devices controlled by the PLC using the same tools, and the but information about PLC I/O-s is transmitted through a
same language, that are used to write the actual control communication interface.
program. The approach has however also some drawbacks.
The simulator output is synchronised to the same system The condition of indistinguishability can be satisfied only if
loop, as the actual control program. It is thus not possible to physical I/O modules are not bypassed, and information
simulate at PLC inputs pulses shorter than the scan time. about states of PLC inputs and outputs is sent through PLC
Time-critical functions, e. g. interrupts, high-speed counters, I/O-s. This leads us to the concept depicted in Fig. 5.
and pulse outputs, cannot be simulated this way. Because of
those limitations, the author recommends to use the method
only for testing control algorithms at a higher level of
hierarchy, e.g. sequences, interactions with SCADA,
networks, etc.
For some PLC-s writing any data from the control program to
the PII memory is inhibited. In such a case the method cannot
be used, either.
A similar idea was presented in Mikoś et al. (2009). The
authors use the ISaGRAF environment to develop their
applications. They add to the actual control program a Fig. 5. Object simulator as a separate device communicating
simulator block, which can be enabled or bypassed, with PLC I/O modules.
depending on the state of an internal variable. Although it is
possible to generate from ISaGRAF a binary code, download An object simulator has to be a separate device (e.g. a
it to a PLC, and execute, in the proposed approach the object separate PC), equipped with an appropriate interface to the
simulator is used only for simulation in ISaGRAF. This PLC. It should sample PLC outputs at regular intervals,
means, that the presented method is similar to those discussed simulate operation of the controlled devices, and send
in p. 2.2. appropriate feedback signals back to the PLC. The sample
period, at which the object simulator samples data, should be
much shorter, than the PLC scan time.
2.4 The concept of a PC-based object simulator
Such functionality can be handled by another PLC, or, what
An object simulator, to be a reliable and convenient is more convenient, by the so-called soft PLC. A soft PLC is
verification tool, should satisfy the following requirements: a PC computer equipped with appropriate I/O cards, and
running a software capable of performing control in real time.
1. Emulation of physical objects should be as realistic, as
possible. In the ideal case the actual object, and the The software, that is normally used for developing control
simulator should be indistinguishable to the PLC. applications on a soft PLC, can as well be used for writing
object models. This software should be accompanied by
visualisation tools, to provide user friendly visualisation of members of the TIOMod class. The most important functions
simulated devices. are PortRead() and PortWrite(), which enable reading and
writing an USB port. Input and output data are stored in the
Using such an approach is however not very convenient for m_DII and m_DOI variables.
creating object models, and can be time consuming. An
object model has to be built simultaneously in two distinct The main (engine) routine of the simulator operates in a
environments. It would thus be desirable to develop a new cyclic manner. It is constructed using the TTimer class of the
kind of software, dedicated specifically for constructing Borland C++ Builder. The routine is thus executed every time
object models for simulation. The software should integrate the timer counts down a predefined interval. The interval is
tools, that enable describing operation of the simulated set to 1 ms. Listing of the simulator engine routine is
device, and tools that facilitate visualisation. The software presented in List. 1.
should also contain a library of ready-made objects, e. g. a
drive, a valve, a tank, etc., that can be easily accessed,
possibly parametrized, and used to assemble a simulation void Timer1(void)
model for the whole installation. {
Ctrl->ObjIMG();
IOMod->m_DII = IOMod->PortRead();
3. THE PROPOSED SOLUTION OF A PC-BASED
IOMod->m_DOI = Ctrl->Proc(
SIMULATOR
IOMod->m_Dii);
IOMod->PortWrite();
3.1 Software description }

A PC-based object simulator has been programmed in C/C++ Listing 1. The Timer1 routine – main data processing.
using the Borland C++ Builder environment, and the At the beginning the object image (ObjIMG()) function is
OpenGL library. A screenshot of the main window of the executed. The function refreshes the variables connected with
developed object simulator is presented in Fig. 6. To object buttons. Then the inputs to the object are read from the
practically test the proposed concept, at first a simulator of a I/O card (PortRead()). Next the most important part of the
belt conveyor was prepared. This enabled carrying out simulator engine is executed - the Proc() function. The
experiments, and testing different configurations and Proc() function processes all variables, and evaluates output
algorithms. In future a library of classes modeling various states of the object (e.g. signals form the simulated
industrial objects can be developed. photocells).
There are two important tasks of the Proc() function. First of
all, the simulator must correctly model physical aspects of the
industrial object. For example, in the belt conveyor there
might be a situation, in which both drives (left and right) are
simultaneously activated by the PLC program under test.
This could possibly damage the belt, or the drives. Such
errors are monitored in the developed simulator. The belt
conveyor doesn’t work, if both drives are active. Moreover –
the simulator indicates such a situation by making the
conveyor blink. The second important task of the Proc()
method is to refresh, and reevaluate states of variables used
for visualization of the controlled process.
The last function in the simulator engine routine is
PortWrite(), which enables transmitting outputs of the object
(evaluated in Proc()) to the I/O card.
Reliable simulation of industrial objects controlled by a PLC
Fig. 6. Main window of the object simulator. is possible, if the simulator sample time is at least an order of
magnitude shorter, than shortest time periods that can be
The engine of the simulator is based on two main classes detected or generated by the PLC. The Windows system is
named TCtrl and TIOMod. The TCtrl class includes variables not well adapted to programming real-time applications. It is
bound up with controlling the belt conveyor drives, indicator thus difficult to guarantee a predefined response time for the
lights, photocells and buttons. The class contains two main simulator. Practical experiments prove, that the I/O card used
methods: ObjIMG() which enables refreshing button with the proposed solution can work reliably for sample rates
variables, and Proc() – the main function processing data. of 1 ms. As we can estimate a PLC scan time to several tens
of milliseconds, the simulator speed obtained is well
Elements facilitating data exchange with the I/O card (see p. sufficient for testing all the functions that are programmed
3.1), like driver handles, USB port opening and closing using the normal serially-cyclic paradigm of PLC operation.
functions, port reading and port writing functions, etc., are Reliability of testing time-critical functions, i.e. interrupts,
high speed counters, and pulse outputs, is a distinct question.
It is a realistic assumption that during a normal PLC
operation an external interrupt is not triggered several times a
millisecond. This means that also interrupt sources can be
reliably simulated using the proposed solution. PLC high
speed counters, and pulse outputs can however work at
frequencies of up to several tens of kilohertz. This means that
their functionality cannot be well tested with the proposed
simulator. Testing at so high frequencies requires in fact a
hardware-software solution. A special I/O card is necessary,
containing hardware counters, and pulse generators.
Fig. 7. A simplified diagram of a digital I/O terminal of the
Visualization of the belt conveyor was developed in 3D USB-4750 card.
graphics using the OpenGL library (OpenGL, 2010).
OpenGL is a low-level, procedural API, requiring from the 4. CONCLUSIONS
programmer to specify the exact steps necessary to render a
scene. This task is accomplished by using a set of base The paper presents an overview of hardware and software
primitives. The scene is rendered cyclically using the TTimer tools used to support PLC program testing and verification. A
class of the Borland C++ Builder. Variables modified in the concept of a PC-based object simulator is proposed. The
Proc() function of the TCtrl class are used to provide simulator consists of a hardware, and a software part. The
animation (List. 2). hardware part is a PC equipped with an I/O card, providing
the interface to PLC inputs and outputs. Operation of the
void Timer2(void) equipment and devices, which shall be controlled by the PLC,
{ is simulated by a program running on the PC. The program
OpenGL->Scene(Ctrl); reads the states of control signals, generated by the PLC,
} evaluates appropriate feedback signals, and sends them back
to PLC inputs through the I/O card.
Listing 2. The Timer2 routine – visualisation.
As scanning of signals generated by the PLC can be
performed at a sample rate of 1 ms, the simulator response
3.1 I/O card time is much shorter, than a typical PLC scan time. The
simulator should thus behave to the PLC in the same manner,
The USB-4750 data acquisition device from Advantech was as a real industrial object (provided that the object is correctly
used as the I/O card (Advantech, 2009). USB-4750 is a modelled in the simulation software).
32-channel isolated digital I/O module for the USB bus. The
main advantages of the module are: As the simulator is a separate device communicating with the
PLC through physical I/O-s, most of PLC, and control
• each I/O channel corresponds to a bit in an I/O port, (it is software functionality can be tested, including interrupts. The
very easy to program this module), simulation is however too slow, to reliably test operation of
high speed counters, and pulse outputs. This requires special
• supports dry and wet contacts,
hardware solutions, which are planned as future
• galvanic isolation provides protection of up to 2,500 developments of the basic concept.
VDC,
Quality and reliability of the tests depend mainly on quality
• features a counter, or timer, of object modelling. It seems thus to be good practice to
appoint the tasks of developing the model of the object, and
• features digital input interrupt lines to a PC, the actual PLC software, to different programmer teams.

• is compatible with the USB Plug & Play specification, The paper presents the concept using an example of a simple
and thus is easy to use, belt conveyor. The authors intend to develop in future a
library of universal industrial objects, e.g. a one-direction
• internal logic is powered from the USB port (no external drive, a motor-operated valve, for the simulator. By
power connection is required, except for an object power combining models of simple elements, the user will be able
supply). to quickly build a simulator model for his specific
installation.
The USB module used is equipped only with isolated digital
inputs and outputs, as presented in Fig. 7. Modules equipped It shall be stressed, that the concept of simulation presented
with analog input/output channels or thermocouple- here is not meant to be a full replacement for test procedures
compatible input channels are however available, too. on real objects. Ensuring reliable and fault-free operation of a
control system is never possible without tests on site,
employing all components of the system fully operational. In
the authors’ opinion the simulator can however handle all
stages of an application development process, except final
verification. It seems to be reliable enough to detect most of
errors in the software, and in particular verify correctness of
algorithms at a higher level of hierarchy, networks, data
exchange with SCADA, etc. Because using the simulator is
safe, and much more convenient, than testing with real
hardware, it can significantly shorten commissioning time.
The proposed idea of an object simulator seams to be also an
attractive option for training purposes. A set of various object
models can be prepared for a PLC programming course. The
models can be easily launched and exchanged, and the
students will have the possibility to solve various problems,
that can be faced by developing commercial applications.
Using a simulator is cheaper, safer, and much more
convenient, than using real machines and objects.

REFERENCES
Advantech (2009), USB-4750 32-channel Isolated Digital I/O
USB Module, User Manual,
http://www.advantech.com/products/USB-4750/mod_1-
2MLJMR.aspx
CoDeSys (2003), User Manual for PLC Programming with
CoDeSys 2.3, 3S - Smart Software Solutions GmbH
ICS Triplex ISaGRAF (2009), ISaGRAF
http://www.isagraf.com
IBHSoftec (2010a), S7 Simulation PLC,
http://www.ibhsoftec-sps.de/english/Selection_Sim.htm
IBHSoftec (2010b), Extended Simulation S5,
http://www.ibhsoftec-sps.de/english/Selection_Sim.htm
Kulisz J. (2004), PLC Software Development supported by
utilising a Simulator Program Block, Proc. of the
International Conference on Programmable Devices and
Systems, PDS’2004, Cracow, Poland, November 18th -
19th, 2004, pp. 121-125
Mikoś Z., Wróbel G., Hayduk G., Kwasnowski P., Jachimski
M., Zygmunt H. (2009), Środowisko ISaGRAF do
tworzenia rozproszonych aplikacji sterowania i regulacji,
in Systemy czasu rzeczywistego. Postępy badań i
zastosowania, WKiŁ, Warszawa, pp. 43-62 (in Polish)
OpenGL (2010), The Industry's Foundation for High
Performance Graphics, http://www.opengl.org/
PC_Simu (2000), http://personales.ya.com/canalPLC
PLCSim (2007), S7-PLCSim V5.4 – User Manual,
A5E00992424-01, Siemens AG
RSLogix (2004), RSLogix Emulate. Getting Results Guide
Doc ID EMULAT-GR002A-EN-P, Rockwell
Automation, www.software.rockwell.com
RSLogix (2005), RSLogix Emulate 5000. Getting Results
Guide, Publication LGEM5K-GR015A-EN-P, Rockwell
Automation, www.software.rockwell.com
S7_200 (2000), http://personales.ya.com/canalPLC
TrySim (2010), Cephalos Gesellschaft für Automatisierung
mbH, http://www.trysim.de/en/
Unity (2007), Modicon M340 PLC Automation Platform
Unity Software, DIA6ED2061001EN-US, Schneider
Electric, www.us.telemecanique.com

Вам также может понравиться