Ejemplo n.º 1
0
        public static IList <Device> GetG120DevicesInGroup(DeviceUserGroup aDeviceUserGroup)
        {
            List <Device>  returnG120Devices = new List <Device>();
            IList <Device> addG120Devices;

            if (aDeviceUserGroup != null)
            {
                foreach (Device device in aDeviceUserGroup.Devices)
                {
                    foreach (DeviceItem deviceItem in device.DeviceItems)
                    {
                        DeviceItem           deviceItemToGetService = deviceItem as DeviceItem;
                        DriveObjectContainer container = deviceItemToGetService.GetService <DriveObjectContainer>();//DriveObject
                        if (container != null)
                        {
                            if (container.DriveObjects[0] is DriveObject G120)
                            {
                                returnG120Devices.Add(device);
                                break;
                            }
                        }
                    }
                }
                //get PLCs in sub folders - recursive
                foreach (DeviceUserGroup group in aDeviceUserGroup.Groups)
                {
                    addG120Devices = GetPlcDevicesInGroup(group);
                    returnG120Devices.AddRange(addG120Devices);
                }
            }


            return(returnG120Devices);
        }
Ejemplo n.º 2
0
        public static IList <Device> GetHmiDevicesInGroup(DeviceUserGroup aDeviceUserGroup)
        {
            List <Device>  returnHmiDevices = new List <Device>();
            IList <Device> addHmiDevices;

            if (aDeviceUserGroup != null)
            {
                foreach (Device device in aDeviceUserGroup.Devices)
                {
                    foreach (DeviceItem deviceItem in device.DeviceItems)
                    {
                        DeviceItem        deviceItemToGetService = deviceItem as DeviceItem;
                        SoftwareContainer container = deviceItemToGetService.GetService <SoftwareContainer>();
                        if (container != null)
                        {
                            if (container.Software is HmiTarget hmi)
                            {
                                returnHmiDevices.Add(device);
                                break;
                            }
                        }
                    }
                }
                //get PLCs in sub folders - recursive
                foreach (DeviceUserGroup group in aDeviceUserGroup.Groups)
                {
                    addHmiDevices = GetPlcDevicesInGroup(group);
                    returnHmiDevices.AddRange(addHmiDevices);
                }
            }


            return(returnHmiDevices);
        }
Ejemplo n.º 3
0
        public static DeviceItem GetCpu1Interface1DeviceItem(DeviceUserGroup aDeviceUserGroup)
        {
            if (aDeviceUserGroup != null)
            {
                IEnumerable <DeviceItem> deviceItemsPLC = null;

                foreach (Device currentDevice in aDeviceUserGroup.Devices)
                {
                    deviceItemsPLC = currentDevice.DeviceItems.Where(d => d.Classification.ToString() == "CPU");

                    //In diesem Fall gehen wir davon aus, dass in dem TIA-Projekt nur eine CPU existiert.
                    if (deviceItemsPLC != null)
                    {
                        break;
                    }
                }

                if (deviceItemsPLC != null)
                {
                    for (int i = 0; i < deviceItemsPLC.Count(); i++)
                    {
                        IList <object> attributeList = null;


                        //DeviceItems der CPU durchsuchen
                        foreach (DeviceItem devItem in deviceItemsPLC.ElementAt(i).DeviceItems)
                        {
                            bool breakLoop = false;

                            try
                            {
                                attributeList = devItem.GetAttributes(new string[] { "InterfaceType" });
                            }
                            catch (EngineeringNotSupportedException)
                            {
                            }
                            catch (Exception ex)
                            {
                                Program.FaultMessage("Could not get Attribute", ex, "Service.GetCpu1Interface1DeviceItem");
                            }

                            if (attributeList != null)
                            {
                                if (devItem.GetAttribute("InterfaceType").ToString() == "Ethernet")
                                {
                                    return(devItem);
                                }
                            }
                            //Breche die äußere foreach-Schleife ab die durch die DeviceItems der CPU iteriert
                            if (breakLoop)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
        private static IEnumerable <DeviceUserGroup> EnumerateDeviceUserGroup(DeviceUserGroup deviceUserGroup)
        {
            yield return(deviceUserGroup);

            foreach (DeviceUserGroup subDeviceUserGroup in deviceUserGroup.Groups)
            {
                foreach (DeviceUserGroup Group in EnumerateDeviceUserGroup(subDeviceUserGroup))
                {
                    yield return(Group);
                }
            }
        }
Ejemplo n.º 5
0
        private List <Device> GetAllGroupedDevices(DeviceUserGroup group)
        {
            List <Device> devices = new List <Device>();

            devices.AddRange(group.Devices);

            foreach (DeviceUserGroup subgroup in group.Groups)
            {
                List <Device> subGroupDevices = GetAllGroupedDevices(subgroup);
                devices.AddRange(subGroupDevices);
            }
            return(devices);
        }
Ejemplo n.º 6
0
 private void FindDevices(DeviceUserGroup devices)
 {
     worker.ReportProgress(50, new NodeEnter(NodeDest.To, devices.Name, true));
     foreach (Device device in devices.Devices)
     {
         FindDeviceItems(device.Items);
     }
     foreach (DeviceUserGroup group in devices.Groups)
     {
         FindDevices(group);
     }
     worker.ReportProgress(50, new NodeExit(NodeDest.To));
 }
Ejemplo n.º 7
0
        private static void HandleDeviceFolder(NodeHandler handler, DeviceUserGroup folder)
        {
            TreeNode node = new TreeNode(folder.Name);

            node.Tag = folder;
            NodeHandler child_handler = handler.Enter(folder, folder.Name);

            if (child_handler != null)
            {
                IterDeviceFolder(child_handler, folder.Groups);
                IterDevice(child_handler, folder.Devices);
            }
            handler.Exit(folder);
        }
Ejemplo n.º 8
0
        public static IList <Device> GetPlcDevicesInGroup(DeviceUserGroup aDeviceUserGroup)
        {
            List <Device>  returnPlcDevices = new List <Device>();
            IList <Device> addPlcDevices;

            if (aDeviceUserGroup != null)
            {
                returnPlcDevices = aDeviceUserGroup.Devices.Where(d => d.DeviceItems.Where(di => di.Classification.ToString() == "CPU").Count() > 0).ToList();
            }
            //get PLCs in sub folders - recursive
            foreach (DeviceUserGroup group in aDeviceUserGroup.Groups)
            {
                addPlcDevices = GetPlcDevicesInGroup(group);
                returnPlcDevices.AddRange(addPlcDevices);
            }

            return(returnPlcDevices);
        }
Ejemplo n.º 9
0
        public static IList <Device> GetAllDevicesInGroup(DeviceUserGroup aDeviceUserGroup)
        {
            List <Device>  returnDevices = new List <Device>();
            IList <Device> addDevices;

            if (aDeviceUserGroup != null)
            {
                returnDevices = aDeviceUserGroup.Devices.ToList();
            }
            //get PLCs in sub folders - recursive
            foreach (DeviceUserGroup group in aDeviceUserGroup.Groups)
            {
                addDevices = GetAllDevicesInGroup(group);
                returnDevices.AddRange(addDevices);
            }

            return(returnDevices);
        }
Ejemplo n.º 10
0
 public static void ChangeDeviceNames(DeviceUserGroup aDeviceUserGroup, string aPrefix)
 {
     if (aDeviceUserGroup != null)
     {
         //get PLCs in sub folders - recursive
         foreach (Device device in aDeviceUserGroup.Devices)
         {
             try
             {
                 //change device name
                 device.DeviceItems[1].Name = aPrefix + device.DeviceItems[1].Name;
             }
             catch
             {
             }
         }
         //get PLCs in sub folders - recursive
         foreach (DeviceUserGroup deviceUserGroup in aDeviceUserGroup.Groups)
         {
             ChangeDeviceNames(deviceUserGroup, aPrefix);
         }
     }
 }
Ejemplo n.º 11
0
 public static void HandleDeviceFolder(IList <HmiTarget> hmi, DeviceUserGroup folder)
 {
     IterDeviceFolder(hmi, folder.Groups);
     IterDevice(hmi, folder.Devices);
 }
Ejemplo n.º 12
0
        //=================================================================================================
        private static void RunTiaPortal()
        {
            #region tia and project
            Progress("Check running TIA Portal");
            bool tiaStartedWithoutInterface = false;

            Service.OpenProject(Parameters.ProjectPath, ref tiaPortal, ref project);

            if ((tiaPortal == null) || (project == null))
            {
                CancelGeneration("Could not open project.");
                return;
            }

            Progress(String.Format("Project {0} is open", project.Path.FullName));
            #endregion

            #region test models

            /*
             * Console.WriteLine("!!! TESTING !!!");
             * DeviceUserGroup testGroup = project.DeviceGroups.Find(Parameters.TemplateGroupName);
             * ManagePlc testPlcs = new ManagePlc(testGroup);
             *
             *
             * NetworkPort testPlcPort = testPlcs.AllDevices[0].DeviceItems[1].DeviceItems[6].DeviceItems[0].GetService<NetworkPort>();
             * NetworkPort patnerPort =  testPlcPort.ConnectedPorts[0];
             *
             * AttributeValue thisname = Service.GetAttribute(patnerPort, "Name");
             *
             * testPlcPort.DisconnectFromPort(patnerPort);
             * testPlcPort.ConnectToPort(patnerPort);
             */

            #endregion

            #region master copy
            Progress("Creating master copy.");

            DeviceUserGroup templateGroup = project.DeviceGroups.Find(Parameters.TemplateGroupName);
            if (templateGroup == null)
            {
                CancelGeneration("Group not found.");
                return;
            }

            //=======copy to master copy========
            //MasterCopyComposition masterCopies = project.ProjectLibrary.MasterCopyFolder.MasterCopies;
            MasterCopy templateCopy = null;
            try
            {
                templateCopy = project.ProjectLibrary.MasterCopyFolder.MasterCopies.Create(templateGroup);
            }
            catch (Exception ex)
            {
                CancelGeneration("Could not create master copy.", ex);
                return;
            }

            if (templateCopy == null)
            {
                CancelGeneration("Could not create master copy.");
                return;
            }

            MasterCopy deleteMasterCopy = project.ProjectLibrary.MasterCopyFolder.MasterCopies.Find(templateCopy.Name);
            #endregion

            #region get basic info from template group
            IList <Device> templatePlcDevices = Service.GetPlcDevicesInGroup(templateGroup);
            ManagePlc      templatePlcs       = new ManagePlc(templatePlcDevices);


            templatePlcs.GetAll_iDeviceParnerIoAdresses();


            if (templatePlcs.AllDevices.Count != 1)
            {
                CancelGeneration("No PLC or more than 1 PLC in group.");
                return;
            }

            #endregion

            #region change name and IP of first group (template Group)
            string indexformat  = "D2";
            uint   groupCounter = 1;

            Progress("Adjusting template group.");
            string currentPrefix = Parameters.Prefix + groupCounter.ToString(indexformat);
            //templateGroup.Name = templateGroup.Name + groupCounter.ToString(indexformat);
            templateGroup.Name = Parameters.NewGroupNamePrefix + groupCounter.ToString(indexformat);
            //templateNetworkInterface.IoControllers[0].IoSystem.Name = currentPrefix + temlateIoSystemName;

            Service.ChangeDeviceNames(templateGroup, currentPrefix);
            templatePlcs.ChangeIoSystemName(currentPrefix);

            #endregion

            #region copy group loop
            DeviceUserGroupComposition userGroups = project.DeviceGroups;

            while (++groupCounter <= Parameters.NumOfGroups)
            {
                #region copy group
                Progress("Creating Group " + groupCounter);
                currentPrefix = Parameters.Prefix + groupCounter.ToString(indexformat);

                DeviceUserGroup newGroup;
                try
                {
                    newGroup = userGroups.CreateFrom(templateCopy);
                }
                catch (Exception e)
                {
                    CancelGeneration("Could not create new Group", e);
                    return;
                }

                #endregion

                #region read in devices
                //newGroup.Name = newGroup.Name + groupCounter.ToString(indexformat); ;
                newGroup.Name = Parameters.NewGroupNamePrefix + groupCounter.ToString(indexformat);;
                Service.ChangeDeviceNames(newGroup, currentPrefix);

                IList <Device> plcDevices = Service.GetPlcDevicesInGroup(newGroup);
                ManagePlc      plcs       = new ManagePlc(plcDevices);

                IList <Device> hmiDevices = Service.GetHmiDevicesInGroup(newGroup);
                ManageHmi      hmis       = new ManageHmi(hmiDevices);

                IList <Device> driveDevices = Service.GetG120DevicesInGroup(newGroup);
                ManageDrive    drives       = new ManageDrive(driveDevices);

                IList <Device> allDevices    = Service.GetAllDevicesInGroup(newGroup);
                IList <Device> tempIoDevices = allDevices.Except(hmis.AllDevices).Except(drives.AllDevices).ToList();
                tempIoDevices.Remove(plcs.AllDevices[0]);
                ManageIo ioDevices = new ManageIo(tempIoDevices);

                #endregion

                #region change settigns
                plcs.ChangeIpAddresses(groupCounter - 1);
                plcs.CreateNewIoSystem(templatePlcs.originalSubnet, currentPrefix);
                plcs.ConnectToMasterIoSystem(templatePlcs.originalIoSystem);
                plcs.GetAll_iDeviceParnerIoAdresses();
                plcs.CopyFromTemplate(templatePlcs);
                plcs.AdjustFSettings(Parameters.FBaseAddrOffset * (groupCounter - 1), Parameters.FDestAddrOffset * (groupCounter - 1));
                plcs.AdjustPnDeviceNumberWithOffset((groupCounter - 1));
                plcs.AdjustPartnerIoAddresses(Parameters.IDeviceIoAddressOffset * (groupCounter - 1));
                plcs.Restore();
                plcs.ChangePnDeviceNames(currentPrefix);
                //plcs.SetAllIDeviceParnerAdresses();

                ioDevices.ChangeIpAddresses(groupCounter - 1);
                ioDevices.SwitchIoSystem(templatePlcs.originalSubnet, plcs.newIoSystem);
                if (templatePlcs.LowerBoundForFDestinationAddresses_attribues?.Value != null)
                {
                    ioDevices.AdjustFDestinationAddress(Parameters.FDestAddrOffset * (groupCounter - 1), (ulong)templatePlcs.LowerBoundForFDestinationAddresses_attribues.Value, (ulong)templatePlcs.UpperBoundForFDestinationAddresses_attribues.Value);
                }
                ioDevices.Restore();
                ioDevices.ChangePnDeviceNames(currentPrefix);

                hmis.ChangeIpAddresses(groupCounter - 1);
                hmis.DisconnectFromSubnet();
                hmis.ConnectToSubnet(templatePlcs.originalSubnet);
                hmis.Restore();
                hmis.ChangePnDeviceNames(currentPrefix);

                drives.ChangeIpAddresses(groupCounter - 1);
                drives.SwitchIoSystem(templatePlcs.originalSubnet, plcs.newIoSystem);
                if (templatePlcs.LowerBoundForFDestinationAddresses_attribues?.Value != null)
                {
                    drives.AdjustFDestinationAddress(Parameters.FDestAddrOffset * (groupCounter - 1), (ulong)templatePlcs.LowerBoundForFDestinationAddresses_attribues.Value, (ulong)templatePlcs.UpperBoundForFDestinationAddresses_attribues.Value);
                }
                drives.Restore();
                drives.ChangePnDeviceNames(currentPrefix);

                plcs.SetAllToConnections();


                plcs.RestoreAllPartnerPorts();
                hmis.RestoreAllPartnerPorts();
                drives.RestoreAllPartnerPorts();
                ioDevices.RestoreAllPartnerPorts();

                #endregion

                plcs.DelecteOldSubnet();
                //deleteNetworkSubnet.Delete();
            }

            #endregion

            try
            {
                deleteMasterCopy.Delete();
            }
            catch (Exception ex)
            {
                Program.FaultMessage("Could not delete Mastercopy.", ex);
            }

            Progress("");

            Console.WriteLine("Copy complete.");
            if (tiaStartedWithoutInterface == true)
            {
                Console.WriteLine("Saving project.");
                project.Save();
                project.Close();
            }
            else
            {
                Console.WriteLine("Please save project within TIAP.");
            }

            try
            {
                tiaPortal.Dispose();
            }
            catch
            {
            }
        }
Ejemplo n.º 13
0
 public UDeviceGroup(DeviceUserGroup deviceUserGroup)
 {
     _deviceUserGroup = deviceUserGroup;
     Inititalise();
 }