Esempio n. 1
0
        public static async Task <NetworkDeviceItem> Create(DeviceItem di, NetworkDeviceItemLevel ndil,  //ndil will be unnecessary now when ndi references levels
                                                            NetworkDeviceItemWorkMode workMode, SubnetLevel subnetLevel, IoSystemLevel ioSystemLevel)
        {
            NetworkInterface ni = ((IEngineeringServiceProvider)di).GetService <NetworkInterface>();

            if (ni == null)
            {
                return(null);
            }

            Node node = ni.Nodes[0];

            // This hack is for distinguishing between HMI and Ethernet Commissioning device.
            // The proper way would be to find some attribute that differentiates them but I could not find any
            // You could check for existence of any profinet attribute but GetAttributeInfos is **HEAVY**
            if (ni.IoConnectors.Count == 0 && ni.IoControllers.Count == 0)
            {
                try
                {
                    node.GetAttribute("PnDeviceNameAutoGeneration");
                }
                catch
                {
                    return(null);
                }
            }

            string nodeType = node.GetAttribute("NodeType").ToString();

            if (!nodeType.Equals("Ethernet"))
            {
                return(null);
            }

            var ndi = new NetworkDeviceItem(di, node, ndil, workMode, subnetLevel, ioSystemLevel);
            await ndi.UpdateAllParameters().ConfigureAwait(false);

            return(ndi);
        }
Esempio n. 2
0
 private NetworkDeviceItem(DeviceItem di, Node node, NetworkDeviceItemLevel ndil, NetworkDeviceItemWorkMode workMode,
                           SubnetLevel subnetLevel, IoSystemLevel ioSystemLevel)
 {
     this.itemLevel     = ndil;
     this.deviceItem    = di;
     this.node          = node;
     this.IoSystemLevel = ioSystemLevel;
     this.SubnetLevel   = subnetLevel;
     this.workMode      = workMode;
 }