首页 > 其他分享 >openness的应用

openness的应用

时间:2024-05-09 13:56:43浏览次数:11  
标签:string void proj 应用 Device openness my public

1. 添加用户组用户

2. 导入openness.dll文件

  • .dll文件位置C:\Program Files\Siemens\Automation\Portal V19\PublicAPI\V19

  • 添加项目引用

  • 引用的命名空间
using Siemens.Engineering;

2. TIA Portal Openness的对象模型

  • 可以通过索引号像数组一样对列表中的对象进行寻址
  • 可以使用Find类函数,比如Screen screen = screens.Find("myScreen")
  • 直接使用符号名称找到对象

3. 找到SofterwareContainer

  • 和FB,FC,OB,Variant等等相关的API接口

4. 打开博图

      //INIT
        TiaPortal my_Ti;
        Project my_proj = null;
        List<Device> my_devicelist = new List<Device>();


        //RUN TIAPORTAL
        public int runTiaportal(bool tiaMode)
        {
            if (tiaMode)
            {
                my_Ti = new TiaPortal(TiaPortalMode.WithUserInterface);
            }
            else
            {
                my_Ti = new TiaPortal(TiaPortalMode.WithoutUserInterface);
            }
            return my_Ti.GetCurrentProcess().Id;
        }

5. 关闭博图

        //STOP TIAPORTAL
        public void stopTiaportal()
        {
            Process[] my_process = Process.GetProcesses();
            foreach (Process item in my_process)
            {
                if (item.Id == my_Ti.GetCurrentProcess().Id)
                {
                    item.Kill();
                    break;
                }
            }
        }

6. 新建项目

        //NEW PROJECT
        public void newProject(string my_projectname)
        {
            ProjectComposition proCom = my_Ti.Projects;
            FolderBrowserDialog my_browserDialog = new FolderBrowserDialog();
            string my_path = string.Empty;
            if (my_browserDialog.ShowDialog() == DialogResult.OK)
            {
                my_path = my_browserDialog.SelectedPath;
                DirectoryInfo my_targetDir = new DirectoryInfo(my_path);
                my_proj = proCom.Create(my_targetDir, my_projectname);
            }
        }

7. 运行项目

        //RUN PROJECT
        public void runProject()
        {
            ProjectComposition proCom = my_Ti.Projects;
            OpenFileDialog my_opendialog = new OpenFileDialog();
            my_opendialog.Multiselect = false;
            my_opendialog.Title = "choic Tia Project";
            my_opendialog.Filter = "All files(*.*)|*.*";
            my_opendialog.InitialDirectory = @"D:\";
            if (my_opendialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string my_projectfile = my_opendialog.FileName;
                FileInfo my_path = new FileInfo(my_projectfile);
                my_proj = proCom.Open(my_path);
            }
        }

8. 设备和网络视图

        //DEVICES & NETWORKS
        public void openHWView(int choic_params)
        {
            switch (choic_params)
            {
                case 0:
                    my_proj.ShowHwEditor(Siemens.Engineering.HW.View.Network);
                    break;
                case 1:
                    my_proj.ShowHwEditor(Siemens.Engineering.HW.View.Topology);
                    break;
                case 2:
                    my_proj.ShowHwEditor(Siemens.Engineering.HW.View.Device);
                    break;
                default:
                    break;
            }
        }

9. 创建设备

        //CREATE DEVICE
        public void createDevice(string deviceitemtypeid, string deviceitemname, string devicename)
        {
            DeviceComposition my_devicecompos = my_proj.Devices;
            Device my_device = my_devicecompos.CreateWithItem(deviceitemtypeid, deviceitemname, devicename);
        }
        public void createDevice(string devicetypeid, string devicename)
        {
            //example-->my_devicetypeid:"System:Device.S7300"
            //example-->my_devicename:"S7300Device"
            DeviceComposition my_devicecompos = my_proj.Devices;
            Device my_device = my_devicecompos.Create(devicetypeid, devicename);
        }

10. 枚举设备

        //ENUM ROOT DEVICE
        public List<Device> enumDevice()
        {
            DeviceComposition my_devicecompos = my_proj.Devices;
            foreach (Device dev in my_devicecompos)
            {
                my_devicelist.Add(dev);
            }
            return my_devicelist;
        }

11. 删除设备

        //DELETE DEVICE
        public void deleteDevice(string deletedevicename)
        {
            Device my_deleteDevice = my_proj.UngroupedDevicesGroup.Devices.Find(deletedevicename);
            my_deleteDevice.Delete();
        }

12. 找到设备

        //FIND DEVICES
        public Device findDevice(string devicename)
        {
            //devicename:"S7-1500/ET200MP station_1"
            Device my_device = my_proj.Devices.Find("devicename");
            return my_device;
        }

13. 插入新设备

        //PLUG NEW DEVICE
        public void plugNewdevice(string typeidentifier, string name, int positionnumber)
        {
            HardwareObject my_hwobject = my_proj.Devices[0].DeviceItems[1];
            if (my_hwobject.CanPlugNew(typeidentifier, name, positionnumber))
            {
                DeviceItem my_plugnewdeviceitem = my_hwobject.PlugNew(typeidentifier, name, positionnumber);
            }
        }

14. 关闭和保存项目

        //SAVE PROJECT
        public void saveProject()
        {
            my_proj.Save();
        }

        //CLOSE PROJECT
        public void closeProject()
        {
            my_proj.Close();
        }

15. 上载项目

//DEVICE UPLOAD
        public void UploadPLCprogram()
        {
            StationUploadProvider my_canbeuploadproj = my_proj.GetService<StationUploadProvider>();
            StationUploadProvider my_upload_proj = my_canbeuploadproj;
            ConnectionConfiguration my_conf = my_upload_proj.Configuration;
            ConfigurationMode my_confmode = my_conf.Modes.Find("PN/IE");
            ConfigurationPcInterface my_pcinterface = my_confmode.PcInterfaces.Find("Intel(R) I210 Gigabit Network Connection <2>", 1);
            ConfigurationAddress my_uploadaddress = my_pcinterface.Addresses.Create("192.168.0.1");
            Device my_uploadedobj = null;
            UploadConfigurationDelegate my_uploaddelegate = PreConfigureUpload;
            UploadResult my_uploadresult = my_upload_proj.StationUpload(my_uploadaddress, PreConfigureUpload);
            my_uploadedobj = my_uploadresult.UploadedStation;
            void PreConfigureUpload(UploadConfiguration my_uploadconf)
            {
                ModuleReadAccessPassword my_module_readpsw = my_uploadconf as ModuleReadAccessPassword;
                if (my_module_readpsw != null)
                {
                    Console.WriteLine("psw error!");
                    return;
                }
                ModuleWriteAccessPassword my_module_writepsw = my_uploadconf as ModuleWriteAccessPassword;
                if (my_module_writepsw != null)
                {
                    Console.WriteLine("psw error!");
                    return;
                }
                throw new NotSupportedException();
            }
        }

16. 代码整理如下

using Siemens.Engineering;
using Siemens.Engineering.Connection;
using Siemens.Engineering.HW;
using Siemens.Engineering.Upload;
using Siemens.Engineering.Upload.Configurations;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace openness_tt
{
    internal class openess_func
    {
        //INIT
        TiaPortal my_Ti;
        Project my_proj = null;
        List<Device> my_devicelist = new List<Device>();


        //RUN TIAPORTAL
        public int runTiaportal(bool tiaMode)
        {
            if (tiaMode)
            {
                my_Ti = new TiaPortal(TiaPortalMode.WithUserInterface);
            }
            else
            {
                my_Ti = new TiaPortal(TiaPortalMode.WithoutUserInterface);
            }
            return my_Ti.GetCurrentProcess().Id;
        }

        //STOP TIAPORTAL
        public void stopTiaportal()
        {
            Process[] my_process = Process.GetProcesses();
            foreach (Process item in my_process)
            {
                if (item.Id == my_Ti.GetCurrentProcess().Id)
                {
                    item.Kill();
                    break;
                }
            }
        }

        //NEW PROJECT
        public void newProject(string my_projectname)
        {
            ProjectComposition proCom = my_Ti.Projects;
            FolderBrowserDialog my_browserDialog = new FolderBrowserDialog();
            string my_path = string.Empty;
            if (my_browserDialog.ShowDialog() == DialogResult.OK)
            {
                my_path = my_browserDialog.SelectedPath;
                DirectoryInfo my_targetDir = new DirectoryInfo(my_path);
                my_proj = proCom.Create(my_targetDir, my_projectname);
            }
        }

        //RUN PROJECT
        public void runProject()
        {
            ProjectComposition proCom = my_Ti.Projects;
            OpenFileDialog my_opendialog = new OpenFileDialog();
            my_opendialog.Multiselect = false;
            my_opendialog.Title = "choic Tia Project";
            my_opendialog.Filter = "All files(*.*)|*.*";
            my_opendialog.InitialDirectory = @"D:\";
            if (my_opendialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string my_projectfile = my_opendialog.FileName;
                FileInfo my_path = new FileInfo(my_projectfile);
                my_proj = proCom.Open(my_path);
            }
        }

        //DEVICES & NETWORKS
        public void openHWView(int choic_params)
        {
            switch (choic_params)
            {
                case 0:
                    my_proj.ShowHwEditor(Siemens.Engineering.HW.View.Network);
                    break;
                case 1:
                    my_proj.ShowHwEditor(Siemens.Engineering.HW.View.Topology);
                    break;
                case 2:
                    my_proj.ShowHwEditor(Siemens.Engineering.HW.View.Device);
                    break;
                default:
                    break;
            }
        }

        //CREATE DEVICE
        public void createDevice(string deviceitemtypeid, string deviceitemname, string devicename)
        {
            DeviceComposition my_devicecompos = my_proj.Devices;
            Device my_device = my_devicecompos.CreateWithItem(deviceitemtypeid, deviceitemname, devicename);
        }
        public void createDevice(string devicetypeid, string devicename)
        {
            //example-->my_devicetypeid:"System:Device.S7300"
            //example-->my_devicename:"S7300Device"
            DeviceComposition my_devicecompos = my_proj.Devices;
            Device my_device = my_devicecompos.Create(devicetypeid, devicename);
        }

        //ENUM ROOT DEVICE
        public List<Device> enumDevice()
        {
            DeviceComposition my_devicecompos = my_proj.Devices;
            foreach (Device dev in my_devicecompos)
            {
                my_devicelist.Add(dev);
            }
            return my_devicelist;
        }

        //DELETE DEVICE
        public void deleteDevice(string deletedevicename)
        {
            Device my_deleteDevice = my_proj.UngroupedDevicesGroup.Devices.Find(deletedevicename);
            my_deleteDevice.Delete();
        }

        //FIND DEVICES
        public Device findDevice(string devicename)
        {
            //devicename:"S7-1500/ET200MP station_1"
            Device my_device = my_proj.Devices.Find("devicename");
            return my_device;
        }


        //PLUG NEW DEVICE
        public void plugNewdevice(string typeidentifier, string name, int positionnumber)
        {
            HardwareObject my_hwobject = my_proj.Devices[0].DeviceItems[1];
            if (my_hwobject.CanPlugNew(typeidentifier, name, positionnumber))
            {
                DeviceItem my_plugnewdeviceitem = my_hwobject.PlugNew(typeidentifier, name, positionnumber);
            }
        }

        //SAVE PROJECT
        public void saveProject()
        {
            my_proj.Save();
        }

        //CLOSE PROJECT
        public void closeProject()
        {
            my_proj.Close();
        }

        //DEVICE UPLOAD
        public void UploadPLCprogram()
        {
            StationUploadProvider my_canbeuploadproj = my_proj.GetService<StationUploadProvider>();
            StationUploadProvider my_upload_proj = my_canbeuploadproj;
            ConnectionConfiguration my_conf = my_upload_proj.Configuration;
            ConfigurationMode my_confmode = my_conf.Modes.Find("PN/IE");
            ConfigurationPcInterface my_pcinterface = my_confmode.PcInterfaces.Find("Intel(R) I210 Gigabit Network Connection <2>", 1);
            ConfigurationAddress my_uploadaddress = my_pcinterface.Addresses.Create("192.168.0.1");
            Device my_uploadedobj = null;
            UploadConfigurationDelegate my_uploaddelegate = PreConfigureUpload;
            UploadResult my_uploadresult = my_upload_proj.StationUpload(my_uploadaddress, PreConfigureUpload);
            my_uploadedobj = my_uploadresult.UploadedStation;
            void PreConfigureUpload(UploadConfiguration my_uploadconf)
            {
                ModuleReadAccessPassword my_module_readpsw = my_uploadconf as ModuleReadAccessPassword;
                if (my_module_readpsw != null)
                {
                    Console.WriteLine("psw error!");
                    return;
                }
                ModuleWriteAccessPassword my_module_writepsw = my_uploadconf as ModuleWriteAccessPassword;
                if (my_module_writepsw != null)
                {
                    Console.WriteLine("psw error!");
                    return;
                }
                throw new NotSupportedException();
            }
        }
    }
}

17. Openness参考资料及对象模型工具资料
openness Demo参考
openness 对象模型工具下载
openness 文档下载

标签:string,void,proj,应用,Device,openness,my,public
From: https://www.cnblogs.com/xiacuncun/p/18159242

相关文章

  • 小米红米手机应用APP字体太小
    小米红米手机应用APP字体太小 调整了手机显示大小,只能解决一点点,还是有点小,比如B站、微博。调整了系统字体大小,B站、微博又不受系统字体大小控制。 只能通过修改最小宽度来解决。1.打开开发者选项:设置→我的设备→全部参数与信息→连续点击"OS版本”,直到显示已进入开发者......
  • 日志 配置文件 依赖注入 系统自动日志 控制台应用
    日志级别学习//Trace:0,包含最详细的消息。这些消息可能包含敏感的应用数据。//Debug:1,用于调试和开发。//Information:2,一般用于跟踪系统的日志。//Warning:3,一般用于记录异常事件或意外事件。//Error:4,一般用于记录无法处理的异常。//Critical:5,需要马上处理的失败,比如数......
  • 使用Django创建一个基础应用
    职位管理系统-建模职位名称类别工作地点职位职责职位要求发布人发布日期修改日期安装djangopipinstalldjango==5.0查看django版本python-mdjango--version创建项目django-adminstartprojectrecruitment启动服务pythonmanage.pyrunserver0.0.0.0:......
  • MediatR是一个在.NET应用程序中实现“中介者模式”的开源库
    MediatR是一个在.NET应用程序中实现“中介者模式”的开源库。该库通过一种进程内消息传递机制(无其他外部依赖),进行请求/响应、命令、查询、通知和事件的消息传递,并通过泛型来支持消息的智能调度。中介者模式是一种行为设计模式,它允许对象之间通过一个中介者对象进行交互,而不是直接......
  • 基于边缘智能网关的工业燃气管网监测应用
    随着城市化和工业化的飞速发展,燃气的使用量和应用范围持续增加,燃气管网作为承载燃气输送的设施,安全问题至关重要。一旦燃气管网发生泄漏事故,极易引发起火、爆炸等,从而酿成人员伤亡及财产损失的恶性事故。 得益于物联网技术的发展和普及,传统的工业设施不断与先进信息技术加深结......
  • UIOTOS前端零代码应用 蓝图连线+嵌套封装 实现MQTT输入0、1切换门禁开和关
    目标通过连线+嵌套封装,实现MQTT数据推送前端控制门禁开关最终效果实现过程步骤1:新建一个页面,在工具函数input输入两个门禁的开关图标地址,再通过连线和解析实现输0、1切换图标。 步骤2:再插入图片按钮,通过连线和解析,把工具函数的输出传递给图片按钮组件的path属性。 步骤......
  • 【触想智能】工业级平板电脑五大特征与应用领域分析
    工业级平板电脑是专供工业环境使用的工业控制计算机,也被称为工控一体机。工业级平板电脑基本性能及兼容性与商用平板电脑几乎相同,但是工业级平板电脑更注重在不同环境下的稳定性能,因此,工业级平板电脑与普通的商用平板电脑存在一定的区别。一、工业级平板电脑的五大特征......
  • 进阶 Redis 技术与应用
    目录1.Redis高级数据结构1.1.HyperLogLog1.2.Bitmaps1.3.Geospatial数据1.4.Pub/Sub(发布/订阅)2.Redis事务与持久化2.1.Redis事务简介2.2.持久化方式:RDB和AOF2.3.配置和管理持久化3.Redis高级功能3.1.分布式锁3.2.Lua脚本3.3.客户端连接和连接池3.4.......
  • BOSHIDA AC/DC电源模块在医疗设备领域的应用探讨
    BOSHIDAAC/DC电源模块在医疗设备领域的应用探讨AC/DC电源模块是一种将交流电转换为直流电的设备,广泛应用于各种电子设备中。在医疗设备领域,AC/DC电源模块的应用具有重要意义。本文将探讨AC/DC电源模块在医疗设备中的应用,并分析其优势和挑战。 首先,AC/DC电源模块在医疗设备中......
  • 【视频监控】视频汇聚平台EasyCVR能力分析及应用分析
    一、方案背景安防视频监控技术是通过各种监控设备捕捉实时画面,并将其传输到监控中心或数据存储设备的技术。随着科技的发展,监控视频技术已经得到了不断的改进与创新,并在各种领域得到了广泛的应用。但是当前视频监控的发展也面临着以下问题:1)不同单位在视频平台建设中以所属领域......