public AI_Channels(ref AgilentU254x Driver)
        {
            _pulseBit    = new DigitalBit(new DigitalChannel(DigitalChannelsEnum.DIOD, ref Driver), 0);
            _setResetBit = new DigitalBit(new DigitalChannel(DigitalChannelsEnum.DIOD, ref Driver), 1);

            _selector_A0 = new DigitalBit(new DigitalChannel(DigitalChannelsEnum.DIOB, ref Driver), 0);
            _selector_A1 = new DigitalBit(new DigitalChannel(DigitalChannelsEnum.DIOB, ref Driver), 1);

            _channelModeSwitch = new ChannelModeSwitch(_pulseBit, _setResetBit, _selector_A0, _selector_A1);
            _filter            = new Filter(new DigitalChannel(DigitalChannelsEnum.DIOA, ref Driver));

            HOLD_CS = new DigitalBit(new DigitalChannel(DigitalChannelsEnum.DIOC, ref Driver), 2);
            HOLD_CS.Reset();

            _gainAmplifier = new ProgrammableGainAmplifier(new DigitalChannel(DigitalChannelsEnum.DIOC, ref Driver));

            _latch = new AnalogInLatch(
                _selector_A0,
                _selector_A1,
                new DigitalBit(new DigitalChannel(DigitalChannelsEnum.DIOD, ref Driver), 2));

            _channels = new AI_Channel[4]
            {
                new AI_Channel(AnalogInChannelsEnum.AIn1, ref Driver, _channelModeSwitch, _filter, _gainAmplifier, _latch),
                new AI_Channel(AnalogInChannelsEnum.AIn2, ref Driver, _channelModeSwitch, _filter, _gainAmplifier, _latch),
                new AI_Channel(AnalogInChannelsEnum.AIn3, ref Driver, _channelModeSwitch, _filter, _gainAmplifier, _latch),
                new AI_Channel(AnalogInChannelsEnum.AIn4, ref Driver, _channelModeSwitch, _filter, _gainAmplifier, _latch)
            };
        }
Пример #2
0
        /// <summary>
        /// Initializes the Agilent instrument
        /// </summary>
        /// <param name="resourceName"></param>
        /// <returns></returns>
        public bool Init(string resourceName)
        {
            lock (initLock)
            {
                _ResourceName = resourceName;

                if (IsInistialized)
                {
                    return(true);
                }

                try
                {
                    if (_Driver == null)
                    {
                        _Driver = new AgilentU254x();
                    }
                    else
                    {
                        Close();
                        Marshal.ReleaseComObject(_Driver);
                        _Driver = new AgilentU254x();
                    }

                    _Driver.Initialize(resourceName, false, true, Options);
                    _Driver.DriverOperation.QueryInstrumentStatus = false;
                    _Driver.DriverOperation.Cache            = false;
                    _Driver.DriverOperation.RecordCoercions  = false;
                    _Driver.DriverOperation.InterchangeCheck = false;
                    _Driver.System.TimeoutMilliseconds       = 5000;

                    _ChannelArray = new AgilentU254xDigitalChannel[] {
                        _Driver.Digital.Channels.get_Item("DIOA"),
                        _Driver.Digital.Channels.get_Item("DIOB"),
                        _Driver.Digital.Channels.get_Item("DIOC"),
                        _Driver.Digital.Channels.get_Item("DIOD")
                    };

                    for (int i = 0; i < _ChannelArray.Length; i++)
                    {
                        if (_ChannelArray[i].Direction != AgilentU254xDigitalChannelDirectionEnum.AgilentU254xDigitalChannelDirectionOut)
                        {
                            _ChannelArray[i].Direction = AgilentU254xDigitalChannelDirectionEnum.AgilentU254xDigitalChannelDirectionOut;
                        }
                    }

                    Reset_Digital();

                    _AI_ChannelCollection = new AI_Channels(ref _Driver);
                    _AO_ChannelCollection = new AO_Channels(ref _Driver);

                    _IsInitialized = true;

                    return(true);
                }
                catch { return(false); }
            }
        }
Пример #3
0
        public AO_Channels(ref AgilentU254x Driver)
        {
            LatchEnable = new DigitalBit(new DigitalChannel(DigitalChannelsEnum.DIOD, ref Driver), 3);

            _channels = new AO_Channel[2]
            {
                new AO_Channel(AnalogOutChannelsEnum.AOut1, ref Driver),
                new AO_Channel(AnalogOutChannelsEnum.AOut2, ref Driver)
            };
        }
 public DigitalChannels(ref AgilentU254x Driver)
 {
     _channels = new DigitalChannel[4]
     {
         new DigitalChannel(DigitalChannelsEnum.DIOA, ref Driver),
         new DigitalChannel(DigitalChannelsEnum.DIOB, ref Driver),
         new DigitalChannel(DigitalChannelsEnum.DIOC, ref Driver),
         new DigitalChannel(DigitalChannelsEnum.DIOD, ref Driver),
     };
 }
        public AI_Channel(AnalogInChannelsEnum channelName, ref AgilentU254x Driver, ChannelModeSwitch ModeSwitch, Filter ChannelFilter, ProgrammableGainAmplifier ChannelPGA, AnalogInLatch CommonLatch)
        {
            _channelName = channelName;
            _driver      = Driver;
            _modeSwitch  = ModeSwitch;

            Parameters = new ChannelParams(_channelName, ChannelFilter, ChannelPGA, CommonLatch);
            InitDriverChannel(_channelName, out _channel);

            ChannelData = new ConcurrentQueue <Point[]>();
        }
Пример #6
0
        public void Dispose()
        {
            if (IsInistialized)
            {
                if (AcquisitionInProgress)
                {
                    StopAnalogAcquisition();
                }

                AO_ChannelCollection.DisableAllVoltages();

                Reset_Digital();

                _DisableAllChannelsForContiniousAcquisition();

                _Driver.Status.Clear();
                _Driver.Utility.ResetWithDefaults();

                Close();

                _AI_ChannelCollection.Dispose();
            }

            if (_ChannelArray != null)
            {
                int i = _ChannelArray.Length - 1;

                for (; i >= 0;)
                {
                    if (_ChannelArray[i] != null)
                    {
                        while (Marshal.ReleaseComObject(_ChannelArray[i]) > 0)
                        {
                            ;
                        }
                        _ChannelArray[i] = null;
                    }

                    --i;
                }
            }

            if (_Driver != null)
            {
                while (Marshal.ReleaseComObject(_Driver) > 0)
                {
                    ;
                }
                _Driver = null;
            }
        }
        public DigitalChannel(DigitalChannelsEnum Channel, ref AgilentU254x Driver)
        {
            int width = 0;

            switch (Channel)
            {
            case DigitalChannelsEnum.DIOA:
            {
                _channelName = ChannelNamesEnum.DIOA;
                width        = 8;
            } break;

            case DigitalChannelsEnum.DIOB:
            {
                _channelName = ChannelNamesEnum.DIOB;
                width        = 8;
            } break;

            case DigitalChannelsEnum.DIOC:
            {
                _channelName = ChannelNamesEnum.DIOC;
                width        = 4;
            } break;

            case DigitalChannelsEnum.DIOD:
            {
                _channelName = ChannelNamesEnum.DIOD;
                width        = 4;
            } break;

            default:
                throw new ArgumentException();
            }

            _driver = Driver;

            var initDirection = AgilentU254xDigitalChannelDirectionEnum.AgilentU254xDigitalChannelDirectionOut;

            _digitalChannel           = Driver.Digital.Channels.get_Item(_channelName);
            _digitalChannel.Direction = initDirection;

            //Marshal.ReleaseComObject(initDirection);

            _bitArray = new DigitalBit[width];
            for (int i = 0; i < width; i++)
            {
                _bitArray[i] = new DigitalBit(this, i);
            }
        }
        public AO_Channel(AnalogOutChannelsEnum Channel, ref AgilentU254x Driver)
        {
            switch (Channel)
            {
            case AnalogOutChannelsEnum.AOut1: _channelName = ChannelNamesEnum.AOUT1; break;

            case AnalogOutChannelsEnum.AOut2: _channelName = ChannelNamesEnum.AOUT2; break;

            default:
                throw new ArgumentException();
            }

            _driver          = Driver;
            _DigitalChannels = new DigitalChannels(ref _driver);

            switch (Channel)
            {
            case AnalogOutChannelsEnum.AOut1:
            {
                _Selector_A0 = new DigitalBit(_DigitalChannels[DigitalChannelsEnum.DIOA], 4);
                _Selector_A1 = new DigitalBit(_DigitalChannels[DigitalChannelsEnum.DIOA], 5);
                _Selector_A2 = new DigitalBit(_DigitalChannels[DigitalChannelsEnum.DIOA], 6);

                _Enable = new DigitalBit(_DigitalChannels[DigitalChannelsEnum.DIOA], 7);
            } break;

            case AnalogOutChannelsEnum.AOut2:
            {
                _Selector_A0 = new DigitalBit(_DigitalChannels[DigitalChannelsEnum.DIOA], 0);
                _Selector_A1 = new DigitalBit(_DigitalChannels[DigitalChannelsEnum.DIOA], 1);
                _Selector_A2 = new DigitalBit(_DigitalChannels[DigitalChannelsEnum.DIOA], 2);

                _Enable = new DigitalBit(_DigitalChannels[DigitalChannelsEnum.DIOA], 3);
            } break;

            default:
                break;
            }

            _driver.AnalogOut.set_Polarity(_channelName, AgilentU254xAnalogPolarityEnum.AgilentU254xAnalogPolarityBipolar);
        }
Пример #9
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();
        }