Exemplo n.º 1
0
        public static string Compile(Project project, int index) //to compile all project
        {
            var    allDevices = project.Devices;
            Device device     = DeviceMethods.GetDevice(project, index);

            string      message     = null;
            PlcSoftware plcSoftware = DeviceItemMethods.GetPlcSoftware(device); //software

            message  = CompileMethods.CompilePlcSoftware(plcSoftware);
            message += CompileMethods.CompileCodeBlock(plcSoftware);

            //HmiTarget hmiTarget = DeviceItemMethods.GetHmiTarget(device); //hardware
            //message += CompileMethods.CompileHmiTarget(hmiTarget);
            return(message);
        }
Exemplo n.º 2
0
        public static void connectToMPI(Project project, int sourceDevice, int targetDevice)
        {
            DeviceComposition allDevices = project.Devices;

            //creating subnet to not connected
            SubnetComposition subnets = project.Subnets;

            Subnet newSubnet = subnets.Create("System:Subnet.Mpi", "MPI Subnet" + Guid.NewGuid().ToString());

            //subnet typeIdentifiers can be .Profibus, .Mpi, .Asi

            //source device
            Device device2 = DeviceMethods.GetDevice(project, targetDevice);
            Device device1 = DeviceMethods.GetDevice(project, sourceDevice);

            DeviceItem head1 = DeviceItemMethods.GetPlcHead(device1);


            DeviceItem interface1 =
                (from DeviceItem di in head1.DeviceItems
                 where di.Name.Contains("MPI")
                 select di).First();

            NetworkInterface interfacePN1  = interface1.GetService <NetworkInterface>();
            NodeComposition  networkNodes1 = interfacePN1.Nodes;

            networkNodes1.First().ConnectToSubnet(newSubnet);   //connection to the subnet

            //target device
            DeviceItem head2 = DeviceItemMethods.GetPlcHead(device2);

            DeviceItem interface2 =
                (from DeviceItem di in head2.DeviceItems
                 where di.Name.Contains("MPI")
                 select di).First();

            NetworkInterface interfacePN2  = interface2.GetService <NetworkInterface>();
            NodeComposition  networkNodes2 = interfacePN2.Nodes;

            networkNodes2.First().ConnectToSubnet(newSubnet);   //second device connection


            Console.WriteLine("Connected to " + newSubnet.GetAttribute("Name"));
        }
Exemplo n.º 3
0
        //public static object DeviceMethods { get; private set; }
        //public static int Counter = 0;
        // static string projectVersion = "15_1";
        static void Main(string[] args)
        {
            Console.WriteLine("Starting TIA Portal...");
            //using (TiaPortal tiaPortal = new TiaPortal(TiaPortalMode.WithoutUserInterface))
            using (TiaPortal tiaPortal = new TiaPortal(TiaPortalMode.WithUserInterface))
            {
                Console.WriteLine("TIA Portal has started");
                ProjectComposition projects = tiaPortal.Projects;

                Console.WriteLine("Opening Project...");

                string   path        = @"C:\Users\CT-EVO\Desktop\Project2\Project2.ap16";
                FileInfo projectPath = new FileInfo(path);

                Project myProject = null;

                try
                {
                    myProject = projects.Open(projectPath);
                }
                catch (Exception)
                {
                    Console.WriteLine(String.Format("Could not open project {0}", projectPath.FullName));
                    Console.WriteLine("Demo complete hit enter to exit");
                }

                MainMethods.DisplayNetwork(myProject);

                Server.RunServer(myProject);      //server is running

                MainMethods.DisplayNetwork(myProject);

                DeviceMethods.DisplayDeviceNames(myProject);

                MainMethods.DisplayNetwork(myProject); // necessary for withUserInterface mode


                //Console.WriteLine("Creating Project...");
                //Project MyProject = tiaPortal.Projects.Create(new DirectoryInfo(Path.GetDirectoryName(Application.ExecutablePath)), Guid.NewGuid().ToString());
            }
        }
Exemplo n.º 4
0
        public static string FunctionSelector(Project project, string [] tokens)
        {
            string command = tokens[0];

            switch (command)
            {
            case "add":
            case "ADD":

                string type = tokens[1];
                DeviceMethods.AddSpecificDevice(project, type);
                MainMethods.DisplayNetwork(project);
                break;

            case "CON":
            case "con":

                int    sourceDevice   = int.Parse(tokens[1]);
                int    targetDevice   = int.Parse(tokens[2]);
                string typeIdentifier = tokens[3];

                Network.selectConnection(project, sourceDevice, targetDevice, typeIdentifier, command);
                MainMethods.DisplayNetwork(project);

                break;

            case "multiCON":
            case "multiCon":

                sourceDevice   = int.Parse(tokens[1]);
                targetDevice   = int.Parse(tokens[2]);
                typeIdentifier = tokens[3];

                Network.selectConnection(project, sourceDevice, targetDevice, typeIdentifier, command);
                MainMethods.DisplayNetwork(project);

                break;

            case "COMPILE":
            case "compile":

                int    index   = int.Parse(tokens[1]);
                string message = MainMethods.Compile(project, index);
                return(message);


            //case "isCon":
            //    int deviceIndex = int.Parse(tokens[1]);
            //    subnet = Network.multiConnection(project, deviceIndex);
            //    Console.WriteLine(project.Devices[deviceIndex].Name + " is connected to " + subnet.Name);
            //    break;

            case "SAVE":
            case "save":
                MainMethods.Save(project);
                break;

            case "CLOSE":
            case "close":
                MainMethods.Close(project);
                break;

            case "show":
                MainMethods.DisplayNetwork(project);
                break;

            case "change":
            case "CHANGE":
                index = int.Parse(tokens[1]);
                string name    = tokens[2];
                string author  = tokens[3];
                string comment = tokens[4];

                DeviceMethods.ChangeProperties(project, index, name, author, comment);

                break;

            default:
                Console.WriteLine("DEFAULT CASE!");
                break;
            }
            return(null);
        }
Exemplo n.º 5
0
        public static void connectToPB(Project project, int sourceDevice, int targetDevice)
        {
            var allDevices = project.Devices;

            //creating subnet to not connected
            SubnetComposition subnets = project.Subnets;

            Subnet newSubnet = subnets.Create("System:Subnet.Profibus", "Profibus Subnet_" + Guid.NewGuid().ToString());

            //subnet typeIdentifiers can be .Profibus, .Mpi, .Asi

            //source device
            Device device2 = DeviceMethods.GetDevice(project, targetDevice);
            Device device1 = DeviceMethods.GetDevice(project, sourceDevice);

            DeviceItem head1 = null;
            DeviceItem head2 = null;

            DeviceItem interface1 = null;

            if (device1.Name.Contains("PLC"))
            {
                head1 = DeviceItemMethods.GetPlcHead(device1);

                interface1 =
                    (from DeviceItem di in head1.DeviceItems
                     where di.Name.Contains("DP")
                     select di).First();
            }

            else
            {
                head1 = DeviceItemMethods.GetHead(device1);

                interface1 =
                    (from DeviceItem di in head1.DeviceItems
                     where di.Name.Equals(head1.Name)
                     select di).First();
            }

            NetworkInterface interfacePN1  = interface1.GetService <NetworkInterface>();
            NodeComposition  networkNodes1 = interfacePN1.Nodes;

            //IoController plcIoController = interfacePN1.IoControllers.First();
            //IoSystem plcIoSystem = plcIoController?.CreateIoSystem("myIoSystem" + Guid.NewGuid().ToString());
            //IoConnector ioConnector = null; //IoController feature is in construction

            networkNodes1.First().ConnectToSubnet(newSubnet);

            DeviceItem interface2 = null;

            if (device2.Name.Contains("PLC"))
            {
                head2 = DeviceItemMethods.GetPlcHead(device2);

                interface2 =
                    (from DeviceItem di in head2.DeviceItems
                     where di.Name.Contains("DP")
                     select di).First();
            }

            else
            {
                head2 = DeviceItemMethods.GetHead(device2);
                foreach (DeviceItem di in head2.DeviceItems)
                {
                    Console.WriteLine("------------------" + di.Name);
                }


                interface2 =
                    (from DeviceItem di in head2.DeviceItems
                     where di.Name.Equals(head2.Name)
                     select di).First();
            }


            NetworkInterface interfacePN2  = interface2.GetService <NetworkInterface>();
            NodeComposition  networkNodes2 = interfacePN2.Nodes;

            networkNodes2.First().ConnectToSubnet(newSubnet);   //second device connection


            Console.WriteLine("Connected to " + newSubnet.GetAttribute("Name"));
        }