勇哥注:
PLCSIM Advanced高级应用主题:通过API进行协同模拟。
整篇文章围绕官方提供的一个示例程序进行讲解。不是单纯介绍运行时API的手册。
目录:
保证和责任.......................................................................................................................... 2
1介绍.................................................................................................................................... 4
1.1概述.................................................................................................................................. 4
1.2操作方式..........................................................................................................................5
1.2.1概述............................................................................................................................... 5
1.2.2功能范围...................................................................................................................... 8
1.3使用的组件..................................................................................................................... 9
2工程................................................................................................................................ 10
2.1TIA博图中的配置........................................................................................................10
2.2在Visual Studio中进行编程.................................................................................11
2.2.1集成了API库.............................................................................................................11
2.2.2概述用户界面...........................................................................................................12
2.2.3编程的PLC实例...................................................................................................... 13
2.2.4编程的协同仿真...................................................................................................... 19
2.3操作应用程序示例........................................................................................................ 21
2.3.1正在切换到虚拟控制器上.....................................................................................21
2.3.2正在加载TIA门户项目到虚拟控制器中.............................................................23
2.3.3启动WinCC运行时................................................................................................. 26
2.3.4开始协同模拟...........................................................................................................27
2.3.5重新启动输送机系统............................................................................................. 28
2.3.6模拟错误.................................................................................................................... 29
2.3.7正在删除和确认错误.............................................................................................30
2.3.8停止协同模拟...........................................................................................................31
2.3.9正在关闭虚拟控制器..............................................................................................32
2.3.10关闭应用程序.........................................................................................................32
2.3.11错误处理..................................................................................................................33
3宝贵的信息.....................................................................................................................33
3.1S7-PLCSIM高级软件的基础知识..........................................................................33
3.1.1安装.............................................................................................................................33
3.1.2S7-PLCSIM V 14和PLCSIM高级软件之间的区别 V1.0.....................................34
3.1.3用户界面.....................................................................................................................35
3.1.4一般属性....................................................................................................................37
3.1.5模拟.............................................................................................................................38
3.1.6用户界面(API)..................................................................................................... 41
3.2关于功能的细节..........................................................................................................43
3.2.1 TIA门户程序............................................................................................................ 43
3.2.2协同模拟程序...........................................................................................................45
4附录.................................................................................................................................46
4.1服务和支持.................................................................................................................. 46
4.2链接和文献...................................................................................................................47
4.3变更文档...................................................................................................................... 47
With the SIMATIC S7-PLCSIM Advanced virtual controllers for the simulation of a
S7-1500 or ET 200SP CPU are created and used for the comprehensive simulation
of functions. Therefore no real controllers are required to test a STEP 7 program.
The virtual controllers can also be tested and validated in the context of a system
or machine. The user interface (API) is used to connect the virtual controller to a
plant/system or machine simulation (co-simulation)
SIMATIC S7-PLCSIM Advanced 虚拟控制器用于创建和使用 S7-1500 或 ET 200SP CPU 的全面功能仿真。
因此,测试 STEP 7 程序时不需要实际的控制器。
这些虚拟控制器也可以在系统或机器的上下文中进行测试和验证。
用户界面(API)用于将虚拟控制器连接到工厂/系统或机器仿真(共仿真)。
在 STEP 7 V14 中创建的 STEP 7 程序用于控制运输系统。
为进行综合功能测试,可通过 S7-PLCSIM Advanced 将 STEP7 程序加载到虚拟 S7-1500 控制器。
该控制器可通过 API 与联合仿真(工厂仿真)进行交互,以在工厂环境中验证 STEP 7 程序。
Advantages of the application example
Introduction to the use of API.
C# example code on which you can establish your own applications.
Topics not covered by this application
This application example does not contain a description of the following topics:
Basics of object-oriented programming
Basics of programming environment, for example, Microsoft Visual Studio
Basics of TIA Portal configuration Sufficient knowledge of these topics is assumed.
应用示例优势
引入 API 的使用
提供 C# 示例代码,您可借此编写您自己的应用程序
本应用未涉及的主题
本应用示例不包含下列主题的相关内容:
面向对象编程的基础知识
编程环境的基础知识,例如 Microsoft Visual Studio
TIA Portal 组态的基础知识
1.2操作方式
1.2.1概述
下图概述了应用程序示例的功能原理。
图1-2:系统的概述
PLCSIM Advanced With S7-PLCSIM Advanced as independent simulation system,
the created user program can be simulated and tested on a virtual controller.
The Runtime API of S7-PLCSIM Advanced (details see chapter 3.1.6) provides user interfaces for access to the simulation runtime.
These user interfaces offer the following options via a program (for example, C# program):
Creation of a runtime instance of a virtual controller.
Changing the mode of the virtual controller.
Exchanging I/O data with a co-simulation.
In this application example a local communication via the PLCSIM Softbus is used.
However, with S7-PLCSIM Advanced a distributed communication via a virtual Ethernet adapter is also possible.
S7-PLCSIM Advanced 作为独立的仿真系统,允许在虚拟控制器上模拟和测试创建的用户程序。
S7-PLCSIM Advanced 的运行时 API 提供了访问仿真运行时的用户界面。这些用户界面通过程序(如示例的C# 程序)提供了以下选项:
创建虚拟控制器的运行时实例。
更改虚拟控制器的模式。
与协同仿真交换 I/O 数据。
在本应用示例中,使用了通过 PLCSIM Softbus 的本地通信。
然而,S7-PLCSIM Advanced 也支持通过虚拟以太网适配器进行分布式通信。
1.2 Mode of Operation
STEP 7 (TIA Portal) program
A STEP 7 program created in STEP 7 V14 (details see chapter 3.2.1) controls a conveyor system. For a comprehensive function test,
the STEP 7 program is loaded via S7-PLCSIM Advanced into a virtual S7-1500 controller.
This controller interacts via the API with a co-simulation (system simulation),
in order to validate the STEP 7 program in the context of the system.
The material handling system to be controlled consists of two transport belts and two robot arms.
The following input and output tags are defined so that the controller communicates with the material handling system:
在STEP 7 (TIA Portal) 程序中,创建了一个控制输送系统的程序。
为了全面的功能测试,该程序通过S7-PLCSIM Advanced加载到一个虚拟的S7-1500控制器中。
这个控制器通过API与一个系统模拟(co-simulation)交互,以在系统上下文中验证STEP 7程序。
要控制的物料搬运系统由两个输送带和两个机器人臂组成。
为了使控制器能够与物料搬运系统通信,定义了以下输入和输出标签:
Table 1-1: Input and output tags
标签 | 数据类型 | 类型 | 描述 |
---|---|---|---|
sensorStartPos | BOOL | 输入 | 传感器信号:起始位置 |
sensorBeltStartPos | BOOL | 输入 | 传感器信号:输送带1的起始位置 |
sensorBeltDest | BOOL | 输入 | 传感器信号:输送带1的目标位置 |
sensorEndPos | BOOL | 输入 | 传感器信号:结束位置 |
setOnBeltActive | BOOL | 输出 | 控制信号:启用机器人臂1 |
moveBeltActive | BOOL | 输出 | 控制信号:启用输送带1 |
setOffBeltActive | BOOL | 输出 | 控制信号:启用机器人臂2 |
releaseActive | BOOL | 输出 | 控制信号:启用输送带2 |
acknowledgeActive | BOOL | 输出 | 控制信号:确认错误 |
restartActive | BOOL | 输出 | 控制信号:重启系统 |
The according control signal is activated based on the active sensor signals.
For transport belt 1 (moveBeltActive) a monitoring time of 5 s is configured.
If the package does not reach the target position within this time, an error for a fallen down package is shown (“Package down”).
You can then restart the system or acknowledge the error when you put the package back on the transport belt 1.
当传感器信号表明运输带1上的包裹没有在设定的监控时间内(5秒)到达目标位置时,系统会显示一个错误信号,
表明包裹已经掉落(“Package down”)。
在这种情况下,用户可以选择重启系统或者在将包裹重新放置到运输带1上后,确认错误信号。
以下是相关操作的表格描述:
操作 | 描述 |
---|---|
监控时间 | 运输带1的监控时间设置为5秒 |
错误显示 | 如果包裹未在5秒内到达目标位置,则显示“Package down”错误信号 |
重启系统 | 用户可以点击“Restart”按钮重启系统 |
确认错误 | 用户可以将包裹放回运输带1上,并在HMI屏幕上点击“acknowledgeActive”按钮确认错误 |
1.2 Mode of Operation
The visualization of the system is simulated with WinCC Runtime.
The system can be monitored and controlled in WinCC Runtime via an HMI screen:
Restart (restartActive)
Acknowledge error (acknowledgeActive)
C# program
In the external application (C# program) the following is programmed:
Functions of the user interface (Runtime API) in order to interact with the virtual controller of S7-PLCSIM Advanced.
System simulation of the conveyor system (co-simulation).
The co-simulation reacts to the control signals (outputs) of the virtual controller and simulates all required sensor signals (inputs) for the simulation of the sequential control (details chapter 3.2.2).
For the exchange of the I/O data the Runtime API writes and reads from the memory area that is synchronized on the cycle control point with the internal process image of the virtual S7-1500 controller.
1.2 操作模式
如何使用WinCC Runtime来模拟系统可视化。
通过HMI屏幕,用户可以监控和控制系统:
重启(restartActive)
确认错误(acknowledgeActive)
在外部应用程序(C#程序)中,编程实现了以下功能:
与S7-PLCSIM Advanced的虚拟控制器交互的用户界面(Runtime API)功能。
输送系统的系统仿真(co-simulation)。
co-simulation对虚拟控制器的控制信号(输出)做出反应,并模拟所有必需的传感器信号(输入),用于顺序控制的仿真(详细信息见第3.2.2节)。
为了交换I/O数据,Runtime API在与虚拟S7-1500控制器的内部过程映像同步的周期控制点上写入和读取内存区域。
功能 | 描述 | 参考章节 |
---|---|---|
重启(restartActive) | 通过HMI屏幕重启系统 | 3.2.2 |
确认错误(acknowledgeActive) | 在控制器中确认错误,继续运输 | 3.2.2 |
与虚拟控制器交互的用户界面功能 | 通过Runtime API与S7-PLCSIM Advanced的虚拟控制器进行交互 | 3.1.6 |
输送系统的系统仿真 | 模拟输送系统,响应控制信号并生成传感器信号 | 3.2.2 |
Table 1-2: Data exchange
表格 1-2: 数据交换
虚拟控制器 | 数据交换 | 协同仿真 |
---|---|---|
setOnBeltActive | 交换 | setOnBeltActive |
moveBeltActive | 交换 | moveBeltActive |
setOffBeltActive | 交换 | setOffBeltActive |
releaseActive | 交换 | releaseActive |
acknowledgeActive | 交换 | acknowledgeActive |
restartActive | 交换 | restartActive |
sensorStartPos | 交换 | sensorStartPos |
sensorBeltStart | 交换 | sensorBeltStart |
sensorBeltDest | 交换 | sensorBeltDest |
sensorEndPos | 交换 | sensorEndPos |
With the co-simulation you can simulate or remove errors,
for example, drop a package or place a dropped package back on transport belt 1.
通过使用共仿真(co-simulation),您可以模拟或移除错误。
例如,您可以模拟一个包裹从输送带1上掉落,或者将掉落的包裹重新放回输送带1上。
文档中提到,共仿真程序会响应虚拟控制器的控制信号,并模拟所有必要的传感器信号,以模拟顺序控制。 具体来说,共仿真程序会根据虚拟控制器的输出信号来模拟传感器信号和机器操作, 并且可以通过设置特定的标签来模拟错误,例如模拟一个包裹掉落。 当包裹被放回输送带1上,并且在控制器中确认错误(acknowledgeActive)或系统被重启(restartActive)
NOTE:
The machines of the conveyor system are simulated in a non-realistic way in the co-simulation.
The movements are only simulated by a time constant.
输送系统的机器是通过时间常数来模拟运动的,这意味着它们的运动并不是以现实世界中的物理运动来模拟的。
这表明在共仿真中,机器的运动是通过预设的时间间隔来模拟的,而不是通过模拟真实的物理运动过程。7页
这种模拟方式可能适用于测试和验证控制逻辑,但不适用于对物理运动精度有严格要求的场合。
在共仿真中,时间常数的使用可以简化模型,加快仿真速度,但可能无法完全反映实际物理运动的复杂性。
1.2.2 Range of functions
In this application example the following functions are used and shown in Runtime API.
在这个应用程序示例中,使用了运行时API,并在其中显示了以下函数。
Table 1-3: API functions
Function | Description | See |
---|---|---|
RegisterInstance() | 注册一个新的虚拟控制器实例到运行时管理器。 | P.13 |
UnregisterInstance() | 从运行时管理器中注销一个实例。 | P.13 |
PowerOn() | 创建模拟运行时实例的过程并启动虚拟控制器的固件。 | P.14 |
PowerOff() | 关闭模拟运行时实例并关闭其进程。 | P.15 |
Run() | 请求虚拟控制器进入运行状态。 | P.15 |
Stop() | 请求虚拟控制器进入停止状态。 | P.16 |
SetIPSuite() | 设置虚拟控制器网络接口的IP套件。 | P.14 |
UpdateTagList() | 从虚拟控制器读取标签并写入共享存储。 | P.18 |
ReadBool() | 符号性读取PLC标签的值。 | P.18 |
WriteBool() | 符号性写入PLC标签的值。 | P.18 |
IsAlwaysSendOnEndOfCycleEnabled{get; set;} | 获取或设置模式AlwaysSendOnEndOfCycle。当模式设置时,每个主循环结束后都会触发OnEndOfCycle事件。 | P.13 |
CommunicationInterface{get; set;} | 设置虚拟控制器的通信接口或返回它:本地通信(软总线)或TCP/IP。 | P.13 |
OnConfigurationChanged | 当虚拟控制器的配置发生变化时触发此事件。 | P.13 |
OnEndOfCycle | 当虚拟控制器达到主循环结束时触发此事件。 | P.13 |
1.3 Components used
HardwareNote
No real hardware is used in this application example. All hardware components configured are simulated.
Table 1-4: Hardware components
Software
Table 1-5: Software components
Downloads
Table 1-6: Downloads F
硬件组件的配置是通过模拟实现的,没有使用真实的硬件。
所有配置的硬件组件都是通过模拟创建的。具体到文档中提到的硬件组件,包括了以下内容:
组件 | 数量 | 文章编号 | 备注 |
---|---|---|---|
CPU 1516-3 PN/DP | 1 | 6ES7516-3AN01-0AB0 | 版本 2.0 |
TP900 Comfort | 1 | 6AV2124-0JC01-0AX0 | 版本 14.0.0.0 |
这些硬件组件的配置和使用是在虚拟环境中进行的,用于模拟和测试S7-PLCSIM Advanced的虚拟控制器功能。
此外,文档中还提到了软件组件,包括:
组件 | 数量 | 文章编号 |
---|---|---|
STEP 7 Professional V14 | 1 | 6ES7822-1AE04-0YA5 |
WinCC Advanced V14 | 1 | 6AV2102-0AA04-0AH5 |
S7-PLCSIM Advanced V1.0 | 1 | 6ES7823-1FE00-0YA5 |
Microsoft Visual Studio Ultimate 2013 | 1 | - |
这些软件组件用于创建和测试虚拟控制器以及与之相关的系统模拟。
而在Downloads表格中,提到了这个示例可以下载到的文档、博图程序、C#程序三个下载资源。

