internal void OpenViaOpennessDlls()
        {
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    if (tiaPortal != null)
                    {
                        tiaPortal.Dispose();
                        tiaPortal = null;
                    }

                    tiaPortal   = new Siemens.Engineering.TiaPortal(Siemens.Engineering.TiaPortalMode.WithoutUserInterface);
                    tiapProject = tiaPortal.Projects.Open(new FileInfo(ProjectFile));
                }
                catch (Siemens.Engineering.EngineeringSecurityException ex)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    if (i == 9)
                    {
                        throw;
                    }
                }

                if (tiapProject != null)
                {
                    break;
                }
            }

            LoadViaOpennessDlls();
        }
Ejemplo n.º 2
0
        private void AksForInstance()
        {
            tiaPortal = new Siemens.Engineering.TiaPortal(Siemens.Engineering.TiaPortalMode.WithoutUserInterface);

            var       processes           = TiaPortal.GetProcesses().ToArray();
            var       sLst                = processes.Select(x => "Projekt : " + (x.ProjectPath != null ? x.ProjectPath.ToString() : "-")).ToArray();
            AppDomain domain              = AppDomain.CreateDomain("another domain");
            CrossAppDomainDelegate action = () =>
            {
                var app = new Application();
                var ask = new SelectPortalInstance();
                var p   = AppDomain.CurrentDomain.GetData("processes") as string[];
                ask.lstInstances.ItemsSource = p;
                app.Run(ask);
                AppDomain.CurrentDomain.SetData("idx", ask.lstInstances.SelectedIndex);
            };

            domain.SetData("processes", sLst);
            domain.DoCallBack(action);
            var idx = (int)domain.GetData("idx");

            tiaPortal        = processes[idx].Attach();
            tiapProject      = tiaPortal.Projects[0];
            this.ProjectFile = processes[idx].ProjectPath.ToString();
        }
Ejemplo n.º 3
0
        private void AksForInstanceWithFilename(string file)
        {
            tiaPortal = new Siemens.Engineering.TiaPortal(Siemens.Engineering.TiaPortalMode.WithoutUserInterface);

            var processes = TiaPortal.GetProcesses().ToArray();
            var process   = processes.First(x => x.ProjectPath != null && x.ProjectPath.FullName == file);

            tiaPortal        = process.Attach();
            tiapProject      = tiaPortal.Projects[0];
            this.ProjectFile = process.ProjectPath.ToString();
        }
        internal void OpenViaOpennessDlls(Credentials credentials)
        {
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    if (tiaPortal != null)
                    {
                        tiaPortal.Dispose();
                        tiaPortal = null;
                    }

                    tiaPortal = new Siemens.Engineering.TiaPortal(
                        Siemens.Engineering.TiaPortalMode.WithoutUserInterface);
                    if (credentials != null)
                    {
                        tiapProject = tiaPortal.Projects.Open(new FileInfo(ProjectFile), c =>
                        {
                            c.Type = UmacUserType.Project;
                            c.Name = credentials.Username;
                            c.SetPassword(credentials.Password);
                        });
                    }
                    else
                    {
                        tiapProject = tiaPortal.Projects.Open(new FileInfo(ProjectFile));
                    }
                }
                catch (Siemens.Engineering.EngineeringSecurityException ex)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    if (i == 9)
                    {
                        throw;
                    }
                }

                if (tiapProject != null)
                {
                    break;
                }
            }

            LoadViaOpennessDlls();
        }
Ejemplo n.º 5
0
        internal void LoadViaOpennessDlls()
        {
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    if (tiaPortal != null)
                    {
                        tiaPortal.Dispose();
                        tiaPortal = null;
                    }
                    tiaPortal   = new Siemens.Engineering.TiaPortal(Siemens.Engineering.TiaPortalMode.WithoutUserInterface);
                    tiapProject = tiaPortal.Projects.Open(new FileInfo(ProjectFile));
                }
                catch (Siemens.Engineering.EngineeringSecurityException ex)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    if (i == 9)
                    {
                        throw;
                    }
                }
                if (tiapProject != null)
                {
                    break;
                }
            }


            var main = new TIAOpennessProjectFolder(this)
            {
                Name = "Main"
            };

            ProjectStructure = main;

            //var frm = new sliver.Windows.Forms.StateBrowserForm();
            //frm.ObjectToBrowse = tiapProject;
            //frm.Show();

            foreach (var d in tiapProject.Devices)
            {
                if (d.TypeIdentifier != null && d.TypeIdentifier.EndsWith(".S71500"))
                {
                    foreach (DeviceItem deviceItem in d.DeviceItems)
                    {
                        var target = ((IEngineeringServiceProvider)deviceItem).GetService <SoftwareContainer>();
                        if (target != null && target.Software is PlcSoftware)
                        {
                            var software = (PlcSoftware)target.Software;
                            var fld      = new TIAOpennessControllerFolder(this, software)
                            {
                                Name = software.Name,
                                //TiaPortalItem = software,
                                //Comment = d.Comment != null ? d.Comment.GetText(CultureInfo.CurrentCulture) : null
                            };
                            main.SubItems.Add(fld);

                            LoadControlerFolderViaOpennessDlls(fld, software);
                        }
                    }

                    //var controller = d.DeviceItems.OfType<Siemens.Engineering.HW.ControllerTarget>().FirstOrDefault();
                    //if (controller == null)
                    //{
                    //    var fld = new TIAOpennessProjectFolder(this)
                    //    {
                    //        Name = d.Name,
                    //        TiaPortalItem = d,
                    //        Comment = d.Comment != null ? d.Comment.GetText(CultureInfo.CurrentCulture) : null
                    //    };
                    //    main.SubItems.Add(fld);

                    //    //LoadSubDevicesViaOpennessDlls(fld, d);
                    //}
                    //else
                    //{
                    //    var fld = new TIAOpennessControllerFolder(this)
                    //    {
                    //        Name = d.Name,
                    //        TiaPortalItem = d,
                    //        Comment = d.Comment != null ? d.Comment.GetText(CultureInfo.CurrentCulture) : null
                    //    };
                    //    main.SubItems.Add(fld);

                    //    //LoadControlerFolderViaOpennessDlls(fld, controller);
                    //}
                }
            }
        }