While you are programming an automation application, it is sometimes useful to do some coding without the real hardware in the field, for example with a cup of fresh coffee at the warm office.
Sure, you can disassemble the machine and put the hardware on your desk. But to help you avoid doing so, TIA Portal offers two simulation possibilities.
In today's article I give you an overview of using PLCsim, and tomorrow I'll focus on PLCsim Advanced.
In both articles I cover using them to simulate either the S7-1200 and 1500. While they also simulate the S7-300 and 400, that's beyond the scope of these articles.
I should note that PLCsim is available for use to anyone who has a license for TIA Portal, while PLCsim Advanced needs it's own license which is purchased separately.
Additionally, PLCsim and PLCsim Advanced can be run simultaneously side by side on one machine, however older versions cannot be installed on the same machine at the same a time.
Before we can simulate a PLC we have to create our PLC program. Therefore I have created a TIA project with a PLC (S7-1515-2 PN). The program just uses the OB1 (main cycle OB) with a very simple program which sets (by Input I0.0) and reset (by Input I0.1) the output Q0.0 (Running_LED).
Installation and supported devices
S7-PLCSIM is a separate installation you can obtain from the SIOS (Siemens Industry Online Support) pages here. If you install it, it will automatically install the latest Version of PLCSIM V5.x for simulation of the classic PLCs (300/400).
In combination with a TIA Basic installation, it will support only the 1200 PLCs. If installed with TIA Professional it will additionally support the 1500 PLCs.
PLCSIM uses a “soft bus” to establish communication to the simulated PLC. All other online interfaces will be disabled. So it is guaranteed that no code is accidental loaded to a real plc attached on an interface of the engineering station.
The compact view offers a minimum of necessary information and buttons to interact whit it. It is ideal to use it along with the online functions of the TIA portal. In default the PLCSIM starts in the compact view if it is started via TIA Portal by clicking in tool bar or context menu.
The project view offers a more comprehensive view for testing and simulation with the PLCSIM direct. Here we can modify PLCSIM specific settings and save the project for later reuse. To offer more comfort for testing we can create “Sim Tables”, “Sequences” and “Event Tables” to test specific behavior of our PLC program.
Load PLC program into PLCSIM
After click on start PLCSIM in the toolbar, the “download to device” dialogue appears. Here you have to select the PG/PC interface “PLCSIM” and click on search device. After a while it shows the requested PLC in the list of available devices. Select the entry of interface you want to connect to. While connecting, maybe a Dialogue appears informing you about the fact that PLCSIM will disconnect all interfaces to the outside word. This means the PLCSIM will create a “softbus” connecting the TIA Portal with PLCSIM. The TIA portal will not be able to connect to another PLC over a real interface until “softbus” is terminated.
HINT: The toolbar button is enabled context sensitive. So if it is greyed out you have to select the plc within the navigation. So it will be enabled.
TIA-Portal (usage of watch tables and code editors in TIA portal)
After the PLC program is loaded we are able to test our PLC program with the TIA-Portal e.g. with the watch tables or within the editor in observe mode. Therefore we can create a new watch table and add all needed symbols in it or open the blocks to analyze.
By activating the observe mode in the editor we can see the actual values of the symbols. The watch table offers also the possibility to modify the symbols. But keep in mind that inputs are overwritten at each cycle of the PLC by the reading of the process image of the inputs. This will make it hard to trigger program code by inputs.
At the SIM Table we add symbols from our PLC program by adding them manually, reading from the TIA project or by importing exported PLC “Tag Tables”. After we have adding the two inputs “Start_SW”, “Stop_SW” and the output “Running_LED”. We can do our first test.
If we select a Tag in the SIM Table we get depending of the type of the Tag a control element to easy manipulate the value. In case of our Boolean be get a button. In case of “Real” data type it will show a slide bar.
HINT: If the control is greyed out it is necessary to activate modify non-Inputs
If we now select the “Start_SW” and click on the button once, our program in the plc switches the output to “true”. By selecting the “Stop_SW” and clicking the button it will turn off our output again. Tada we have tested our fist plc program with PLCSIM.
To do it now more advanced, we can create a sequence to test our plc program, so we don’t have to click all buttons manually. Therefore we create a sequence like in the following picture (TIA and PLCSIM side by side).
In the sequence editor we can define at which time a value has to be set. After we have created our sequence we can start the sequence by clicking “Start Sequence”. It will run the sequence once. By selecting “Repeat” before clicking “Start Sequence” it will repeat the sequence until we click “Stop Sequence”. A green arrow is shown to indicate at which step the sequence is.
HINT: If you have created a trace measurement in your PLC. You can save it in the TIA project and export it in a “*.ttrec” file. In the sequence editor you are able to import this type of file.
This will start a Dialog, where you can select the variables of the recording you want to import. After you did your selection it will import the variables and configure the set of the values at the recorded time. So you are able to measure in the field a behavior and retrace it with PLCSIM in a safe environment.
With the event table we are able to trigger PLC events like “Pull or Plug Modul”, “Hardware Interrupt”, “Rack or Station Failure” or “Diagnostic Error Interrupt”. So we can test our program behavior by these types of event. But to go into deep this will go beyond of the scope of this article.
PLCSIM and PLCSIM advance are different tools optimized for different purposes. They offer some of the same functionality, but as we'll see in tomorrow's article they are also very different.
On the other hand, as we'll see in tomorrow's article, PLCsim advanced is focused on testing the PLC program interacting with external elements such as storage cards (e.g. writing log files) and external communication partner like OPC-UA Clients and Server.
Written by Michael Elting
Mechatronics & Automation Engineer and Freelance Writer
Sponsor and Advertise: Get your product or service in front of our 70K followers while also supporting independent automation journalism by sponsoring or advertising with us! Learn more in our Media Guide here, or contact us using this form or by calling our office at 413-749-4300.