Мой код:
Код: Выделить всё
import clr
clr.AddReference('C:\\Program Files\\Siemens\\Automation\\Portal V15_1\\PublicAPI\\V15.1\\Siemens.Engineering.dll')
import Siemens.Engineering as tia
import Siemens.Engineering.Hmi as tia_hmi
def connect_to_tia_portal():
processes = list(tia.TiaPortal.GetProcesses())
if processes:
print("Attaching to an existing TIA Portal instance...")
return processes[0].Attach()
print("No running TIA Portal instance found. Starting a new instance...")
return tia.TiaPortal(tia.TiaPortalMode.WithUserInterface)
print('Trying to connect to an open TIA Portal instance...')
try:
mytia = connect_to_tia_portal()
print('Connected to an open TIA Portal instance.')
except Exception as e:
print(f"Failed to connect: {e}")
quit()
if mytia.Projects.Count == 0:
print("No open projects found in TIA Portal.")
quit()
myproject = mytia.Projects[0]
print(f"Connected to project: {myproject.Name}")
screens = []
for device in myproject.Devices:
print(f"Searching in device: {device.Name}")
for item in device.DeviceItems:
if isinstance(item, tia_hmi.HmiTarget):
hmi_target = item.GetService(tia_hmi.HmiTagService)
for screen in hmi_target.HmiScreens:
screens.append(screen.Name)
print(f"Screen found: {screen.Name}")
if screens:
print(f"\nTotal screens found: {len(screens)}")
else:
print("No screens found in the project.")
print("Press any key to quit")
input()
quit()
Код: Выделить всё
Trying to connect to an open TIA Portal instance...
Attaching to an existing TIA Portal instance...
Connected to an open TIA Portal instance.
Connected to project: uspk_81_04_07_06_V2
Searching in device: ARMKTU
Searching in device: ARMBUR
Searching in device: S71500/ET200MP station_1
No screens found in the project.
Press any key to quit
Код: Выделить всё
Searching in device: ARMBUR
Error retrieving HMI Software in SIMATIC PC station: SoftwareContainer
Error retrieving HMI Software in HMI_RT_2: SoftwareContainer
Error retrieving HMI Software in IE general_1: SoftwareContainer