private void radioButtonLocalFolder_CheckedChanged(object sender, EventArgs e)
 {
     panelCamera.Enabled = false;
     panelCamerapanelLocalFile.Enabled = false;
     panelLocalFolder.Enabled          = true;
     mode = AcquisitionMode.FromFolder;
 }
Exemple #2
0
        private void ShowAcqMode()
        {
            AcquisitionMode Mode = Newport.GetAcquisitionMode();

            switch (Mode)
            {
            case AcquisitionMode.Continuous:
                cmbAcqMode.SelectedIndex = 0;
                break;

            case AcquisitionMode.Single:
                cmbAcqMode.SelectedIndex = 1;
                break;

            case AcquisitionMode.ContinuousPeakToPeak:
                cmbAcqMode.SelectedIndex = 2;
                break;

            case AcquisitionMode.SinglePeakToPeak:
                cmbAcqMode.SelectedIndex = 3;
                break;

            case AcquisitionMode.RMS:
                cmbAcqMode.SelectedIndex = 4;
                break;

            default:
                cmbAcqMode.SelectedIndex = -1;
                break;
            }
        }
        protected override void ChangeAcquisitionMode(AcquisitionMode mode)
        {
            if (Mode == AcquisitionMode.Ohmeter)
            {
                _ohmeterTimer.Change(Timeout.Infinite, -1);
            }

            base.ChangeAcquisitionMode(mode);
        }
Exemple #4
0
        /// <summary>
        /// Configures the HDC1000 Click for temperature, humidity acquisition.
        /// </summary>
        /// <param name="acquisitionMode">The <see cref="AcquisitionMode"/> for measurement.</param>
        /// <param name="temperatureResolution">The <see cref="TemperatureResolution"/> for reading temperature data.</param>
        /// <param name="humidityResolution">The <see cref="HumidityResolution"/> for reading humidity data.</param>
        /// <param name="heatMode">The <see cref="HeaterMode"/> for enabling or disabling the on-board heater.</param>
        /// <example>Example usage:
        /// <code language = "C#">
        /// _tempHumidity.Configure(Hdc1000Click.AcquisitionMode.Sequential, Hdc1000Click.TemperatureResolution.FourteenBit, Hdc1000Click.HumidityResolution.FourteenBit, Hdc1000Click.HeaterMode.Disabled);
        /// </code>
        /// </example>
        public void Configure(AcquisitionMode acquisitionMode, TemperatureResolution temperatureResolution, HumidityResolution humidityResolution, HeaterMode heatMode)
        {
            _acquisitionMode = acquisitionMode;

            Byte value = (Byte)((Byte)acquisitionMode | (Byte)temperatureResolution | (Byte)humidityResolution | (Byte)heatMode);

            WriteRegister(ConfigRegister, value);

            Thread.Sleep(15);
        }
Exemple #5
0
        /// <summary>
        /// Sets the acquisition mode.
        /// </summary>
        /// <param name="mode">The new required acquisition mode.</param>
        /// <remarks>
        /// Derived classes may override this function to customize how/when acquisition mode
        /// is changed, features emulation should be done with <see cref="Feature"/> specific syntax methods.
        /// When this method is called <see cref="AcquisitionDevice.Mode"/> still contains <em>old</em> mode.
        /// </remarks>
        protected virtual void ChangeAcquisitionMode(AcquisitionMode mode)
        {
            switch (mode)
            {
            case AcquisitionMode.Idle:
                // Even if hardware does not support this we will "emulate" Idle disabling outputting, this
                // is default behavior: derived classes may override this function if hardware support this.
                break;

            case AcquisitionMode.Data:
                // To (re)enable data acquisition we disable previously enabled "special" acquisition mode.
                if (Mode == AcquisitionMode.Ohmeter)
                {
                    Features.Perform(AcquisitionDeviceFeatures.Ohmeter);
                }
                else if (Mode == AcquisitionMode.Calibration)
                {
                    Features.Perform(AcquisitionDeviceFeatures.Calibration);
                }

                // We do nothing here: it means that current mode is Idle and it's supported by hardware,
                // it's derived classes task to enter/exit from idle mode (see case AcquisitionMode.Idle).
                break;

            case AcquisitionMode.Ohmeter:
                if (!Features.IsAvailable(AcquisitionDeviceFeatures.Ohmeter))
                {
                    throw new NotSupportedFeatureException(HardwareErrorCodes.Unsupported.AcquisitionMode, "Inputs impedance check (ohmeter) is not supported.");
                }

                Features.Perform(AcquisitionDeviceFeatures.Ohmeter);
                break;

            case AcquisitionMode.Calibration:
                if (!Features.IsAvailable(AcquisitionDeviceFeatures.Calibration))
                {
                    throw new NotSupportedFeatureException(HardwareErrorCodes.Unsupported.AcquisitionMode, "Inputs calibration signal is not supported.");
                }

                Features.Perform(AcquisitionDeviceFeatures.Calibration);
                break;

            default:
                throw new NotSupportedFeatureException(HardwareErrorCodes.Unsupported.AcquisitionMode, String.Format("Acquisition mode {0} is unknown.", mode));
            }
        }
Exemple #6
0
            private static Box AcquireBoxPointerPotentiallyWaitForever <TVault>([NotNull] TVault owner, AcquisitionMode mode)
                where TVault : ReadWriteVault <T>
            {
                // ReSharper disable once ConstantConditionalAccessQualifier
                Debug.Assert(owner?._lockedResource != null && owner._locker != null);
                Debug.Assert(mode == AcquisitionMode.UpgradableReadOnly || mode == AcquisitionMode.ReadWrite ||
                             mode == AcquisitionMode.ReadOnly);

                var locker = owner._locker;

                switch (mode)
                {
                default:
                case AcquisitionMode.ReadOnly:
                    locker.EnterReadLock();
                    break;

                case AcquisitionMode.UpgradableReadOnly:
                    locker.EnterUpgradeableReadLock();
                    break;

                case AcquisitionMode.ReadWrite:
                    locker.EnterWriteLock();
                    break;
                }

                return(owner._lockedResource);
            }
Exemple #7
0
 private RwVaultInternalLockedResource([NotNull] ReadWriteVault <T> owner, [NotNull] Box b, [CanBeNull] Action <TimeSpan?, CancellationToken> upgradeAction, [CanBeNull] Action upgradeForeverAction, AcquisitionMode mode)
 {
     _mode                 = mode.ValueOrThrowIfNDef();
     _b                    = b ?? throw new ArgumentNullException(nameof(b));
     _upgradeAction        = upgradeAction;
     _upgradeForeverAction = upgradeForeverAction;
     _owner                = owner ?? throw new ArgumentNullException(nameof(owner));
     _releaseFlag          = default;
     _isGood               = true;
     Debug.Assert((_upgradeAction == null) == (_upgradeForeverAction == null),
                  "Both ok, neither ok.  Exactly one not ok.");
 }
Exemple #8
0
        /// <summary>
        /// Release the resource
        /// </summary>
        /// <param name="v">the vault to which the resource should be returned</param>
        /// <param name="b">the box of the resource to be returned</param>
        /// <param name="mode">the mode in which the lock was obtained</param>
        /// <typeparam name="TAv">The type of ReadWriteVault</typeparam>
        /// <returns>null</returns>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="mode"/> was not a defined value of
        /// the <see cref="AcquisitionMode"/> <see langword="enum"/></exception>
        protected internal static Box ReleaseResourceMethod <TAv>([NotNull] TAv v, Box b, AcquisitionMode mode) where TAv : ReadWriteVault <T>
        {
            // ReSharper disable once ConstantConditionalAccessQualifier
            Debug.Assert(b != null && v?._locker != null &&
                         ReferenceEquals(v._lockedResource, b));
            var locker = v._locker;

            switch (mode)
            {
            case AcquisitionMode.ReadOnly:
                locker.ExitReadLock();
                break;

            case AcquisitionMode.UpgradableReadOnly:
                locker.ExitUpgradeableReadLock();
                break;

            case AcquisitionMode.ReadWrite:
                locker.ExitWriteLock();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(mode),
                                                      mode, null);
            }
            return(null);
        }
Exemple #9
0
            CreateInternalLockedResource <TV>([NotNull] TV owner, TimeSpan?timeout,
                                              CancellationToken token, AcquisitionMode mode, bool vaultDisposing = false) where TV : ReadWriteVault <T>
            {
                if (owner == null)
                {
                    throw new ArgumentNullException(nameof(owner));
                }
                if (timeout == null && token == CancellationToken.None)
                {
                    throw new ArgumentException("Cancellation token may not be none if no timeout is specified.");
                }
                if (vaultDisposing && !owner.DisposeInProgress)
                {
                    throw new InvalidOperationException($"The {nameof(vaultDisposing)} parameter indicates this call is part of a vault disposal routine." +
                                                        "  The vault, however, is not performing such a routine.");
                }
                if (!vaultDisposing && owner.IsDisposed)
                {
                    throw new ArgumentException(@"The vault is disposed.", nameof(owner));
                }
                mode = mode.ValueOrThrowIfNDef();
                (Box AcquiredBox, bool Cancelled, bool TimedOut)boxRes = default;
                try
                {
                    boxRes = AcquireBoxPointer(owner, timeout, mode, token);
                    if (boxRes.Cancelled)
                    {
                        throw new OperationCanceledException(token);
                    }
                    if (boxRes.TimedOut)
                    {
                        throw new TimeoutException(
                                  "Unable to acquire resource within " +
                                  $"[{(timeout ?? owner.DefaultTimeout).TotalMilliseconds:F3}] milliseconds.");
                    }
                    (Action <TimeSpan?, CancellationToken> upgradeAction, Action upgradeForeverAction) =
                        GetUpgradeActions(mode);
                    Debug.Assert((upgradeForeverAction == null) == (upgradeAction == null));

                    return(new RwVaultInternalLockedResource(owner, boxRes.AcquiredBox, upgradeAction, upgradeForeverAction, mode));
                }
                catch (LockRecursionException ex)
                {
                    Debug.Assert(boxRes.AcquiredBox == null);
                    throw new RwLockAlreadyHeldThreadException(Thread.CurrentThread.ManagedThreadId, ex);
                }
                catch (Exception)
                {
                    if (boxRes.AcquiredBox != null)
                    {
                        ReleaseLock(owner._locker, mode);
                    }
                    throw;
                }

                (Action <TimeSpan?, CancellationToken> UpgradeAction, Action UpgradeForeverAction) GetUpgradeActions(AcquisitionMode m)
                {
                    return(m == AcquisitionMode.UpgradableReadOnly
                        ? (
                               (TimeSpan? ts, CancellationToken tkn) =>
                               Upgrade(ts, tkn), () => UpgradeForever()) : (NullUpgradeAction, NullUpgradeForeverAction));
                }

                void Upgrade(TimeSpan?ts, CancellationToken tkn) =>
                CreateInternalLockedResource(owner, ts, tkn, AcquisitionMode.ReadWrite);

                void UpgradeForever() => CreateInternalLockedResourceBlockForever(owner, AcquisitionMode.ReadWrite);
            }
Exemple #10
0
            internal static RwVaultInternalLockedResource CreateInternalLockedResourceBlockForever <TV>([NotNull] TV owner, AcquisitionMode mode, bool vaultDisposing = false) where TV : ReadWriteVault <T>
            {
                if (owner == null)
                {
                    throw new ArgumentNullException(nameof(owner));
                }
                if (vaultDisposing && !owner.DisposeInProgress)
                {
                    throw new InvalidOperationException($"The {nameof(vaultDisposing)} parameter indicates this call is part of a vault disposal routine." +
                                                        "  The vault, however, is not performing such a routine.");
                }
                if (!vaultDisposing && owner.IsDisposed)
                {
                    throw new ArgumentException(@"The vault is disposed.", nameof(owner));
                }

                Box boxRes = null;

                try
                {
                    boxRes = AcquireBoxPointerPotentiallyWaitForever(owner, mode);
                    Debug.Assert(boxRes != null);
                    (Action <TimeSpan?, CancellationToken> upgradeAction, Action upgradeForeverAction) =
                        GetUpgradeActions(mode);
                    Debug.Assert((upgradeForeverAction == null) == (upgradeAction == null));
                    return(new RwVaultInternalLockedResource(owner, boxRes, upgradeAction, upgradeForeverAction, mode));
                }
                catch (LockRecursionException ex)
                {
                    Debug.Assert(boxRes == null);
                    throw new RwLockAlreadyHeldThreadException(Thread.CurrentThread.ManagedThreadId, ex);
                }
                catch (Exception)
                {
                    if (boxRes != null)
                    {
                        ReleaseLock(owner._locker, mode);
                    }
                    throw;
                }

                (Action <TimeSpan?, CancellationToken> UpgradeAction, Action UpgradeForeverAction) GetUpgradeActions(AcquisitionMode m)
                {
                    return(m == AcquisitionMode.UpgradableReadOnly
                        ? (
                               (TimeSpan? ts, CancellationToken tkn) =>
                               Upgrade(ts, tkn), () => UpgradeForever()) : (NullUpgradeAction, NullUpgradeForeverAction));
                }

                void Upgrade(TimeSpan?ts, CancellationToken tkn) =>
                CreateInternalLockedResource(owner, ts, tkn, AcquisitionMode.ReadWrite);

                void UpgradeForever() => CreateInternalLockedResourceBlockForever(owner, AcquisitionMode.ReadWrite);
            }
Exemple #11
0
 /// <summary>
 /// Try to get the resource until earliest of following happens
 ///     1- get it successfully,
 ///     2- cancellation requested via <paramref name="token"/>
 ///     3- time specified by <paramref name="timeout"/> exceeded
 /// </summary>
 /// <param name="timeout">how long should we wait?  Null indicates potential infinite wait .</param>
 /// <param name="token">token by which another thread can cancel the attempt to obtain resource</param>
 /// <param name="mode">acquisition mode</param>
 /// <returns>the resource</returns>
 /// <exception cref="ArgumentOutOfRangeException">non-null, non-positive <paramref name="timeout"/> argument; OR mode not
 /// a defined value of the <see cref="AcquisitionMode"/> <see langword="enum"/></exception>
 /// <exception cref="TimeoutException">didn't obtain it within time specified by <paramref name="timeout"/></exception>
 /// <exception cref="OperationCanceledException">operation was cancelled</exception>
 /// <exception cref="ObjectDisposedException">the object was disposed</exception>
 /// <exception cref="LockAlreadyHeldThreadException">the thread attempting to obtain the lock already holds the lock.</exception>
 /// <remarks>After method returns value, you are responsible for disposal until passing to ultimate user behind a method whose return
 /// value is annotated by the <see cref="UsingMandatoryAttribute"/>.  This means you must dispose of it yourself in all failure/exceptional
 /// cases after this method returns a value but before ultimately passed to user.</remarks>
 protected RwVaultInternalLockedResource ExecuteGetInternalLockedResource(TimeSpan?timeout, CancellationToken token, AcquisitionMode mode)
 {
     ThrowIfDisposingOrDisposed();
     if (timeout.HasValue && timeout.Value <= TimeSpan.Zero)
     {
         throw new ArgumentOutOfRangeException(nameof(timeout), timeout, @"Must be positive.");
     }
     return(RwVaultInternalLockedResource.CreateInternalLockedResource(this, timeout, token, mode.ValueOrThrowIfNDef()));
 }
Exemple #12
0
 /// <summary>
 /// Try to get the locked resource.  This thread will block (potentially forever)
 /// until the resource is obtained or an exception is thrown.
 /// </summary>
 /// <returns>The locked resource</returns>
 /// <exception cref="ObjectDisposedException">object was disposed</exception>
 /// <exception cref="LockAlreadyHeldThreadException">the thread attempting to obtain the lock,
 /// already holds the lock.</exception>
 protected RwVaultInternalLockedResource ExecuteGetInternalLockedResourceBlockForever(AcquisitionMode mode)
 {
     ThrowIfDisposingOrDisposed();
     return(RwVaultInternalLockedResource.CreateInternalLockedResourceBlockForever(this, mode.ValueOrThrowIfNDef()));
 }
 /// <summary>
 /// Set the acquisition mode to use
 /// </summary>
 /// <param name="mode">Mode to start using</param>
 public void SetAcquisitionMode(AcquisitionMode mode)
 {
     SendCommandWithErrorOnlyResponse("PM:MODE " + ((int)mode).ToString());
 }
Exemple #14
0
 private static void RunLittleBit(AcquisitionDevice device, AcquisitionMode mode, int seconds = 2)
 {
     device.Mode = mode;
     Thread.Sleep(seconds * 1000);
 }