예제 #1
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);
        }
예제 #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.RequestOpState(this.Context), nameof(EcHL.RequestOpState));

            #endregion

            if (_watchdogTask == null)
            {
                _watchdogTask = Task.Run(() => this.WatchdogRoutine(), _cts.Token);
            }
        }