C#使用Siemens.Simatic.Simulation.Runtime需添加什么引用?
S7-PLCSIM Advanced C#开发所需引用配置
你代码中使用的Siemens.Simatic.Simulation.Runtime命名空间对应程序集是S7-PLCSIM Advanced安装时自带的本地DLL,不需要从NuGet下载,添加步骤如下:
- 确认本地安装版本为S7-PLCSIM Advanced V3.0及以上,低版本不开放公开API接口,无法用代码控制实例创建。
- 打开Visual Studio的项目,右键「依赖项」选择「添加引用」,在浏览窗口定位到PLCSIM Advanced的默认安装目录:
C:\Program Files\Siemens\Automation\S7-PLCSIM Advanced\API - 选中目录下的
Siemens.Simatic.Simulation.Runtime.dll确认添加,添加完成后编译器就能正常识别IInstance、SimulationRuntimeManager等类型。
额外注意事项:
- 项目生成的目标平台必须设置为x64,否则调用API时会抛出兼容性异常。
- 运行代码前确保S7-PLCSIM Advanced的后台服务处于启动状态,否则实例注册方法会执行失败。
- 你贴的代码中按钮点击方法的命名存在语法问题,C#窗体事件方法名格式为
控件名_事件名,你写的button1.click()是事件绑定的写法,实际方法定义需要修正,完整可运行代码如下:
using Siemens.Simatic.Simulation.Runtime; using System; private void button1_Click(object sender, EventArgs e) { IInstance myInstance = SimulationRuntimeManager.RegisterInstance("nameOfYourInstance"); myInstance.PowerOn(); }
内容的提问来源于stack exchange,提问作者Paul Maubray
相关产品推荐
相关产品推荐

