自动化编程?带你实际体验西门子 TIA Openness自动创建和编译博图项目(附源代码免费分享)
Siemens TIA Openness是西门子TIAPortal软件平台的一个重要组成部分,它为用户提供了一种通过编程语言如C#与TIAPortal进行交互的方式。这种开放性接口,也被称为API(应用程序编程接口),使得开发人员能够在不直接访问软件源代码的情况下,通过一组预定义的函数或方法来控制和自动化TIAPortal的功能。
TIA Openness的主要优势在于它能够提高工程组态的自动化程度,从而提升工作效率和减少人为错误。通过使用TIAOpenness,用户可以在外部开发应用程序,实现对TIAPortal的控制,如自动创建和管理项目、编译设备配置、生成HMI画面和PLC程序等。
TIA Openness支持的操作非常广泛,包括但不限于项目管理、硬件配置、代码生成等。例如,用户可以通过TIAOpenness将TIA SELECTION TOOL的选型配置导出,导入到TIA Portal的项目中,体验TIAOpenness功能的魅力。TIA Openness还允许用户通过编写脚本来自动执行各种任务,而无需任何编程技能,这通过TIAPortal OpennessScripter实现,它提供了简单的脚本命令来简化编程过程。
TIAOpenness是西门子为自动化工程师提供的一个强大的工具,它通过开放的API接口,使得用户能够更加高效地完成自动化工程任务,无论是通过编程语言还是通过简化的脚本命令。随着工业4.0和智能制造的推进,TIAOpenness将在未来的工业自动化领域发挥越来越重要的作用。
系统环境:Windows10
编程语言:Python 3.7(由于C#的编程工具Visual Studio太大,懒得装,用python)
编程工具:Visual Studio Code
import clrclr.AddReference('System.IO')from System.IO import DirectoryInfo, FileInfoclr.AddReference('C:\\Program Files\\Siemens\\Automation\\Portal V16\\PublicAPI\\V16\\Siemens.Engineering')import Siemens.Engineering as tiaimport Siemens.Engineering.HW.Features as hwfimport Siemens.Engineering.Compiler as compimport os# # # Starting TIA and creating project# print('************************************')print(' ')print('欢迎关注公众号:"工业控制系统baike"')print(' ')print('************************************')#Starting TIA with UI, also possible to start without uiprint ('Starting TIA with UI')mytia = tia.TiaPortal(tia.TiaPortalMode.WithoutUserInterface)# Alternative code to connect to an allready running instance (uncomment to use)processes = tia.TiaPortal.GetProcesses() # Making a list of all running processesprint (processes)#process = processes[0] # Just taking the first process as an example#mytia = process.Attach()#myproject = mytia.Projects[0]# Creating a new project. Using try/except in case project allready existsproject_path = DirectoryInfo ('C:\\Users\\DGES2\\Desktop\\TIA Openness')project_name = 'TIA Openness Test By python'try: myproject = mytia.Projects.Create(project_path, project_name)except Exception as e: print (e)## # Adding HW to the project##Adding the main componentsprint ('Creating PLC1')PLC1_mlfb = 'OrderNumber:6ES7 513-1AL02-0AB0/V2.6'PLC1 = myproject.Devices.CreateWithItem(PLC1_mlfb, 'PLC1', 'PLC1')print ('Creating IOnode1')IOnode1_mlfb = 'OrderNumber:6ES7 155-6AU01-0BN0/V4.1'IOnode1 = myproject.Devices.CreateWithItem(IOnode1_mlfb, 'IOnode1', 'IOnode1')print ('Creating HMI1')HMI1_mlfb = 'OrderNumber:6AV2 124-0GC01-0AX0/15.1.0.0'HMI1 = myproject.Devices.CreateWithItem(HMI1_mlfb, 'HM1', None)#print ('项目创建完成')