示例#1
0
        static void Main()
        {
            Console.WriteLine("Set firewall...");
            Assembly assembly = Assembly.GetExecutingAssembly();

            Starter.SetTiaPortalFirewall(assembly);
            TiaPortal tiaPortal = null;

            try
            {
                Console.WriteLine("Get instance...");
                tiaPortal = Starter.GetInstance(TiaPortalMode.WithUserInterface);

                Console.WriteLine("Create project...");
                string  projectFullPath = Path.Combine(DataPath, "debug", "MyProject", "MyProject.ap15_1");
                Project project         = ProjectHelper.CreateProjectIfNotExists(tiaPortal, projectFullPath);

                Console.WriteLine("Insert devices...");
                List <Device> devices = InsertDevices(project);

                Console.WriteLine("Get network interfaces...");
                List <Node> nodes = GetNetworkInterfaces(devices);

                Console.WriteLine("Create Subnet...");
                NetworkHelper.ConnectNodesToNetwork(project, "System:Subnet.Ethernet", "MySubnet", nodes);

                Console.WriteLine("Get software...");
                List <Software> softwareList = GetSoftwareList(devices);

                Console.WriteLine("Insert blocks from SCL source...");
                List <PlcSoftware> plcSoftwareList = softwareList.OfType <PlcSoftware>().ToList();
                InsertBlocksFromSclSource(plcSoftwareList);

                Console.WriteLine("Compile...");
                CompileHelper.Compile(softwareList);

                Console.WriteLine("Save project...");
                project.Save();

                Console.WriteLine("Show block in editor...");
                var block = plcSoftwareList.FirstOrDefault()?.BlockGroup.Blocks
                            .OfType <OB>()
                            .FirstOrDefault(obj => obj.Number.Equals(1));
                block?.ShowInEditor();
            }
            finally
            {
                tiaPortal?.Dispose();
            }
        }