示例#1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (_ioMapPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(_ioMapPtr);
                }

                _cts?.Cancel();

                try
                {
                    _watchdogTask?.Wait();
                }
                catch (Exception ex) when(ex.InnerException.GetType() == typeof(TaskCanceledException))
                {
                    //
                }

                if (this.Context != IntPtr.Zero)
                {
                    EcHL.FreeContext(this.Context);
                    this.Context = IntPtr.Zero;
                }

                disposedValue = true;
            }
        }
示例#2
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);
        }
示例#3
0
        public static SlaveInfo ScanDevices(string interfaceName, SlaveInfo referenceSlaveInfo = null)
        {
            IntPtr    context;
            SlaveInfo slaveInfo;

            context   = EcHL.CreateContext();
            slaveInfo = EcUtilities.ScanDevices(context, interfaceName, referenceSlaveInfo);
            EcHL.FreeContext(context);

            return(slaveInfo);
        }
示例#4
0
        public static SlaveInfo ScanDevices(string interfaceName, SlaveInfo referenceRootSlave = null)
        {
            if (NetworkInterface.GetAllNetworkInterfaces().Where(x => x.Name == interfaceName).FirstOrDefault()?.OperationalStatus != OperationalStatus.Up)
            {
                throw new Exception($"The network interface '{interfaceName}' is not linked. Aborting action.");
            }

            var context   = EcHL.CreateContext();
            var rootSlave = EcUtilities.ScanDevices(context, interfaceName, referenceRootSlave);

            EcHL.FreeContext(context);

            return(rootSlave);
        }
示例#5
0
        public void CanAccessNativeLib()
        {
            // Arrange
            Directory.EnumerateFiles("./runtimes/", "*soem_wrapper.*", SearchOption.AllDirectories).ToList().ForEach(filePath =>
            {
                if (filePath.Contains(RuntimeEnvironment.RuntimeArchitecture))
                {
                    File.Copy(filePath, Path.GetFileName(filePath), true);
                }
            });

            // Act
            var context = EcHL.CreateContext();

            // Assert
            Assert.True(context != IntPtr.Zero);
            EcHL.FreeContext(context);
        }
示例#6
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (_ioMapPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(_ioMapPtr);
                }

                _cts?.Cancel();
                _watchdogTask?.Wait();

                if (this.Context != IntPtr.Zero)
                {
                    EcHL.FreeContext(this.Context);
                    this.Context = IntPtr.Zero;
                }

                disposedValue = true;
            }
        }