示例#1
0
        public void Configure(SlaveInfo rootSlaveInfo = null)
        {
            SlaveInfo         actualSlaveInfo;
            IList <SlaveInfo> slaveInfoSet;
            IList <SlaveInfo> actualSlaveInfoSet;
            NetworkInterface  networkInterface;

            networkInterface = NetworkInterface.GetAllNetworkInterfaces().Where(nic => nic.Name == _settings.InterfaceName).FirstOrDefault();

            if (networkInterface?.OperationalStatus != OperationalStatus.Up)
            {
                throw new Exception($"Network interface '{_settings.InterfaceName}' is not linked. Aborting action.");
            }

            #region "PreOp"

            actualSlaveInfo = EcUtilities.ScanDevices(this.Context, _settings.InterfaceName, null);

            if (rootSlaveInfo == null)
            {
                rootSlaveInfo = actualSlaveInfo;

                rootSlaveInfo.Descendants().ToList().ForEach(current =>
                {
                    ExtensibilityHelper.CreateDynamicData(_settings.EsiDirectoryPath, _extensionFactory, current);
                });
            }

            slaveInfoSet       = rootSlaveInfo.Descendants().ToList();
            actualSlaveInfoSet = actualSlaveInfo.Descendants().ToList();

            this.ValidateSlaves(slaveInfoSet, actualSlaveInfoSet);
            this.ConfigureSlaves(slaveInfoSet);
            this.ConfigureIoMap(slaveInfoSet);
            this.ConfigureDc();
            this.ConfigureSync01(slaveInfoSet);

            #endregion

            #region "SafeOp"

            EcUtilities.CheckErrorCode(this.Context, EcHL.CheckSafeOpState(this.Context), nameof(EcHL.CheckSafeOpState));

            #endregion

            #region "Op"

            EcUtilities.CheckErrorCode(this.Context, EcHL.RequestOpState(this.Context), nameof(EcHL.RequestOpState));

            #endregion

            if (_watchdogTask == null)
            {
                _watchdogTask = Task.Run(() => this.WatchdogRoutine(), _cts.Token);
            }
        }
示例#2
0
        public void Configure(SlaveInfo rootSlave = null)
        {
            var networkInterface = NetworkInterface
                                   .GetAllNetworkInterfaces()
                                   .Where(nic => nic.Name == _settings.InterfaceName)
                                   .FirstOrDefault();

            if (networkInterface?.OperationalStatus != OperationalStatus.Up)
            {
                throw new Exception($"Network interface '{_settings.InterfaceName}' is not linked. Aborting action.");
            }

            #region "PreOp"

            var actualSlave = EcUtilities.ScanDevices(this.Context, _settings.InterfaceName, null);

            if (rootSlave == null)
            {
                rootSlave = actualSlave;

                rootSlave.Descendants().ToList().ForEach(current =>
                {
                    EcUtilities.CreateDynamicData(_settings.EsiDirectoryPath, current);
                });
            }

            var slaves       = rootSlave.Descendants().ToList();
            var actualSlaves = actualSlave.Descendants().ToList();

            this.ValidateSlaves(slaves, actualSlaves);
            this.ConfigureSlaves(slaves);
            this.ConfigureIoMap(slaves);
            this.ConfigureDc();
            this.ConfigureSync01(slaves);

            #endregion

            #region "SafeOp"

            EcUtilities.CheckErrorCode(this.Context, EcHL.CheckSafeOpState(this.Context), nameof(EcHL.CheckSafeOpState));

            #endregion

            #region "Op"

            EcUtilities.CheckErrorCode(this.Context, EcHL.RequestCommonState(this.Context, (UInt16)SlaveState.Operational), nameof(EcHL.RequestCommonState));

            #endregion

            if (_watchdogTask == null)
            {
                _watchdogTask = Task.Run(() => this.WatchdogRoutine(), _cts.Token);
            }
        }
示例#3
0
        public static SlaveInfo ReloadHardware(string esiDirectoryPath, IExtensionFactory extensionFactory, string interfaceName, SlaveInfo referenceRootSlaveInfo)
        {
            IntPtr    context;
            SlaveInfo newRootSlaveInfo;
            SlaveInfo referenceSlaveInfo;
            IEnumerable <SlaveInfo> referenceSlaveInfoSet;

            referenceSlaveInfo    = null;
            referenceSlaveInfoSet = null;

            if (NetworkInterface.GetAllNetworkInterfaces().Where(x => x.GetPhysicalAddress().ToString() == interfaceName).FirstOrDefault()?.OperationalStatus != OperationalStatus.Up)
            {
                throw new Exception($"The network interface '{interfaceName}' is not linked. Aborting action.");
            }

            context          = EcHL.CreateContext();
            newRootSlaveInfo = EcUtilities.ScanDevices(context, interfaceName, referenceRootSlaveInfo);
            EcHL.FreeContext(context);

            if (referenceRootSlaveInfo != null)
            {
                referenceSlaveInfoSet = referenceRootSlaveInfo.Descendants().ToList();
            }

            newRootSlaveInfo.Descendants().ToList().ForEach(slaveInfo =>
            {
                referenceSlaveInfo = slaveInfo.Csa == slaveInfo.OldCsa ? referenceSlaveInfoSet?.FirstOrDefault(x => x.Csa == slaveInfo.Csa) : null;
                ExtensibilityHelper.GetDynamicSlaveInfoData(esiDirectoryPath, extensionFactory, slaveInfo);
                ExtensibilityHelper.UpdateSlaveExtensions(extensionFactory, slaveInfo, referenceSlaveInfo);
            });

            return(newRootSlaveInfo);
        }
示例#4
0
        public static SlaveInfo RescanDevices(EcSettings settings, SlaveInfo referenceRootSlave)
        {
            var referenceSlaves = default(IEnumerable <SlaveInfo>);

            if (referenceRootSlave != null)
            {
                referenceSlaves = referenceRootSlave.Descendants().ToList();
            }

            var newRootSlave = EcUtilities.ScanDevices(settings.InterfaceName, referenceRootSlave);

            newRootSlave.Descendants().ToList().ForEach(slave =>
            {
                var referenceSlave = slave.Csa == slave.OldCsa
                    ? referenceSlaves?.FirstOrDefault(x => x.Csa == slave.Csa)
                    : null;

                if (referenceSlave != null)
                {
                    slave.Extensions = referenceSlave.Extensions;
                }

                EcUtilities.CreateDynamicData(settings.EsiDirectoryPath, slave);
            });

            return(newRootSlave);
        }
示例#5
0
        private static ec_slave_info_t[] ToSlaveIdentifications(SlaveInfo slave)
        {
            var slaveIdentifications = slave.Descendants().ToList().Select(x => new ec_slave_info_t(x)).ToList();

            slaveIdentifications.Insert(0, new ec_slave_info_t(slave));

            return(slaveIdentifications.ToArray());
        }
示例#6
0
        private static ec_slave_info_t[] ToSlaveIdentificationSet(SlaveInfo slaveInfo)
        {
            List <ec_slave_info_t> slaveIdentificationSet;

            slaveIdentificationSet = slaveInfo.Descendants().ToList().Select(x => new ec_slave_info_t(x)).ToList();
            slaveIdentificationSet.Insert(0, new ec_slave_info_t(slaveInfo));

            return(slaveIdentificationSet.ToArray());
        }