Esempio 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"));
        }
Esempio n. 2
0
        public static void ConnectToSubnet(Project project)
        {
            var allDevices = project.Devices;

            //creating subnet to not connected
            SubnetComposition subnets   = project.Subnets;
            Subnet            newSubnet = subnets.Create("System:Subnet.Ethernet", "MyPnSubnet");
            //subnet typeIdentifiers can be .Profibus, .Mpi, .Asi

            Device     device1 = allDevices.First();
            DeviceItem head1   = getHead(device1);

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

            NetworkInterface interfacePN1          = simocodeInterface1.GetService <NetworkInterface>();
            NodeComposition  simocodeNetworkNodes1 = interfacePN1.Nodes;
            //simocodeNetworkNodes1.First().ConnectToSubnet(newSubnet);



            Device     device2 = allDevices[1];
            DeviceItem head2   = getHead(device2);

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

            NetworkInterface interfacePN2          = simocodeInterface2.GetService <NetworkInterface>();
            NodeComposition  simocodeNetworkNodes2 = interfacePN2.Nodes;

            //simocodeNetworkNodes2.First().ConnectToSubnet(newSubnet);


            Console.WriteLine(simocodeNetworkNodes1.Count()); //just a counter
        }
Esempio n. 3
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"));
        }