private void InitDriverChannel(AnalogInChannelsEnum ChannelName, out AgilentU254xAnalogInChannel channel)
        {
            lock (initDriverChannelLock)
            {
                switch (ChannelName)
                {
                case AnalogInChannelsEnum.AIn1:
                    channel = _driver.AnalogIn.Channels.get_Item(ChannelNamesEnum.AIN1);
                    break;

                case AnalogInChannelsEnum.AIn2:
                    channel = _driver.AnalogIn.Channels.get_Item(ChannelNamesEnum.AIN2);
                    break;

                case AnalogInChannelsEnum.AIn3:
                    channel = _driver.AnalogIn.Channels.get_Item(ChannelNamesEnum.AIN3);
                    break;

                case AnalogInChannelsEnum.AIn4:
                    channel = _driver.AnalogIn.Channels.get_Item(ChannelNamesEnum.AIN4);
                    break;

                default:
                    throw new ArgumentException();
                }
            }
        }
 public void Dispose()
 {
     if (_channel != null)
     {
         while (Marshal.ReleaseComObject(_channel) > 0)
         {
             ;
         }
         _channel = null;
     }
 }
Пример #3
0
        static void Main(string[] args)
        {
            Process currProcess = Process.GetCurrentProcess();

            // Printing initial memory, occupied by the process
            int memsizeInit = getMemoryUsage(ref currProcess);

            Console.WriteLine(string.Format("Initial memory occupied by the process is {0}\r\n", memsizeInit));

            #region Initializing COM objects

            driver = new AgilentU254x();
            driver.Initialize(ResourceID, false, true);

            driver.DriverOperation.QueryInstrumentStatus = false;
            driver.DriverOperation.Cache            = false;
            driver.DriverOperation.RecordCoercions  = false;
            driver.DriverOperation.InterchangeCheck = false;
            driver.System.TimeoutMilliseconds       = 5000;

            analogInChannel1 = driver.AnalogIn.Channels.get_Item("AIn1");
            analogInChannel2 = driver.AnalogIn.Channels.get_Item("AIn2");
            analogInChannel3 = driver.AnalogIn.Channels.get_Item("AIn3");
            analogInChannel4 = driver.AnalogIn.Channels.get_Item("AIn4");

            analogInChannel1.Configure(AgilentU254xAnalogPolarityEnum.AgilentU254xAnalogPolarityBipolar, 1.25, true);
            analogInChannel2.Configure(AgilentU254xAnalogPolarityEnum.AgilentU254xAnalogPolarityBipolar, 1.25, false);
            analogInChannel3.Configure(AgilentU254xAnalogPolarityEnum.AgilentU254xAnalogPolarityBipolar, 1.25, false);
            analogInChannel4.Configure(AgilentU254xAnalogPolarityEnum.AgilentU254xAnalogPolarityBipolar, 1.25, false);

            #endregion

            #region Test Acquisition

            int samplingFrequency = 500000;

            driver.AnalogIn.MultiScan.Configure(samplingFrequency, -1);

            driver.AnalogIn.Acquisition.BufferSize = samplingFrequency;

            bool acquisitionInProgress = true;

            driver.AnalogIn.Acquisition.Start();

            var acquisitionTask = Task.Factory.StartNew(new Action(() =>
            {
                int readingsCounter = 0;
                short[] buf         = { 0 };
                while (acquisitionInProgress)
                {
                    if (driver.AnalogIn.Acquisition.BufferStatus == AgilentU254xBufferStatusEnum.AgilentU254xBufferStatusDataReady)
                    {
                        driver.AnalogIn.Acquisition.Fetch(ref buf);
                        Console.WriteLine(string.Format("Number of readings with sampling frequency {0} is {1}.", samplingFrequency, readingsCounter + 1));
                        ++readingsCounter;
                    }
                }
            }));

            int numOfSeconds = 10;
            Thread.Sleep(numOfSeconds * 1000);

            driver.AnalogIn.Acquisition.Stop();
            acquisitionInProgress = false;

            while (!acquisitionTask.IsCompleted)
            {
                ;
            }

            #endregion

            #region Releasing COM objects

            if (analogInChannel4 != null)
            {
                while (Marshal.ReleaseComObject(analogInChannel4) > 0)
                {
                    ;
                }
                analogInChannel4 = null;
            }

            if (analogInChannel3 != null)
            {
                while (Marshal.ReleaseComObject(analogInChannel3) > 0)
                {
                    ;
                }
                analogInChannel3 = null;
            }

            if (analogInChannel2 != null)
            {
                while (Marshal.ReleaseComObject(analogInChannel2) > 0)
                {
                    ;
                }
                analogInChannel2 = null;
            }

            if (analogInChannel1 != null)
            {
                while (Marshal.ReleaseComObject(analogInChannel1) > 0)
                {
                    ;
                }
                analogInChannel1 = null;
            }

            if (driver != null)
            {
                while (Marshal.ReleaseComObject(driver) > 0)
                {
                    ;
                }
                driver = null;
            }

            #endregion

            // Printing memory, occupied by the process after data readings
            Console.WriteLine();

            int memsizeEnd = getMemoryUsage(ref currProcess);
            Console.WriteLine(string.Format("Memory occupied by the process after data readings is {0}\r\n", memsizeEnd));
            Console.ReadKey();
        }