public static void ChangeProperties(Project project, int index, string name, string author, string comment)    //change some properties of device head
        {
            Device     device = GetDevice(project, index);
            DeviceItem head   = null;

            if (device.Name.Contains("PLC"))
            {
                head = DeviceItemMethods.GetPlcHead(device);
            }

            else
            {
                head = DeviceItemMethods.GetHead(device);
            }

            if (name != null && name != "x")
            {
                Console.WriteLine(head.GetAttribute("Name"));
                head.SetAttribute("Name", name);
                Console.WriteLine(head.GetAttribute("Name"));
            }
            else
            {
                Console.WriteLine(head.GetAttribute("Name"));
            }

            if (author != null && author != "x")
            {
                Console.WriteLine(head.GetAttribute("Author"));
                head.SetAttribute("Author", author);
                Console.WriteLine(head.GetAttribute("Author"));
            }
            else
            {
                Console.WriteLine(head.GetAttribute("Author"));
            }

            if (comment != null && comment != "x")
            {
                Console.WriteLine(head.GetAttribute("Comment"));
                head.SetAttribute("Comment", comment);
                Console.WriteLine(head.GetAttribute("Comment"));
            }
            else
            {
                Console.WriteLine(head.GetAttribute("Comment"));
            }

            Console.WriteLine("Properties is changed!");
        }
        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);
        }
Beispiel #3
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"));
        }
Beispiel #4
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"));
        }
Beispiel #5
0
        public static void multiConnection(Project project, int sourceIndex, int targetIndex)
        {
            var allSubnets = project.Subnets;
            var allDevices = project.Devices;

            Device source = allDevices[sourceIndex];
            Device target = allDevices[targetIndex];

            DeviceItem sourceHead = null;
            DeviceItem targetHead = null;

            if (source.Name.Contains("PLC"))    //source head
            {
                sourceHead = DeviceItemMethods.GetPlcHead(source);
            }
            else
            {
                sourceHead = DeviceItemMethods.GetHead(source);
            }


            if (target.Name.Contains("PLC"))    //target head
            {
                targetHead = DeviceItemMethods.GetPlcHead(target);
            }
            else
            {
                targetHead = DeviceItemMethods.GetHead(target);
            }

            DeviceItem sourceInterface =
                (from DeviceItem di in sourceHead.DeviceItems
                 where di.Name.Contains("interface") || di.Name.Contains("MPI") || di.Name.Contains("DP") || di.Name.Contains("ASI")
                 select di).First();

            Console.WriteLine("-sourceInterface Name: " + sourceInterface.Name);

            NetworkInterface sourceNetworkInterface = sourceInterface.GetService <NetworkInterface>();
            Node             sourceNode             = sourceNetworkInterface.Nodes.First();

            Console.WriteLine("--sourceNode Name: " + sourceNode.Name);

            DeviceItem targetInterface =
                (from DeviceItem di in targetHead.DeviceItems
                 where di.Name.Contains("DP") || di.Name.Contains("MPI") || di.Name.Contains("interface") || di.Name.Contains("ASI")
                 select di).First();

            //multiple connection is impossible on same device, such as simatic2
            //because the function always gets just first node of the interface

            Console.WriteLine("-targetInterface Name: " + targetInterface.Name);

            NetworkInterface targetNetworkInterface = targetInterface.GetService <NetworkInterface>();
            Node             targetNode             = targetNetworkInterface.Nodes.First();

            Console.WriteLine("--targetNode Name: " + targetNode.Name);

            Console.WriteLine("SUBNET NAMEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE::::::::::::::::::::::::::::.");
            Console.WriteLine(targetNode.ConnectedSubnet.GetAttribute("Name"));

            sourceNode.ConnectToSubnet(targetNode.ConnectedSubnet);
        }