Ejemplo n.º 1
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"));
        }
Ejemplo n.º 2
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"));
        }