/// <summary>
        ///     Initializes this object's state and sets up BetaInnovations SDK objects
        ///     to monitor the BetaInnoviations device instance that this object
        ///     is responsible for.
        ///     During preparation, the _preparing flag is raised.  Subsequent concurrent calls to
        ///     Prepare() will simply wait until the _preparing flag is lowered.
        /// </summary>
        protected override void Prepare()
        {
            var       elapsed = 0;
            const int timeout = 500;

            while (_preparing && elapsed <= timeout)
            {
                Thread.Sleep(20);
                elapsed += 20;
            }
            if (!_preparing)
            {
                try
                {
                    _manager = BIDeviceManager.GetInstance();
                    try
                    {
                        _preparing = true;
                        //check if device is attached
                        var connected = _manager.IsDeviceAttached(Device.Key.ToString(), false);
                        if (!connected)
                        {
                            _preparing = false;
                            _prepared  = false;
                            return;
                        }
                    }
                    catch (BIException e)
                    {
                        _log.Error(e.Message, e);
                        _preparing = false;
                        _prepared  = false;
                        return;
                    }

                    _prepared = true;
                }
                catch (BIException ex)
                {
                    _log.Error(ex.Message, ex);
                    _prepared = false;
                    throw;
                }
                finally
                {
                    _preparing = false;
                }
            }
        }
Example #2
0
        /// <summary>
        ///     Discovers the physical controls that appear on this device,
        ///     as reported by the BetaInnovations SDK, and stores them as an array
        ///     of PhysicalControlInfo objects at the instance level.
        ///     NOT guaranteed to be successful -- if the calls to
        ///     the BetaInnovations SDK fail or if the device
        ///     is not currently registered, then the controls list will remain
        ///     unpopulated.
        /// </summary>
        protected override void LoadControls()
        {
            if (_controlsLoaded)
            {
                return;
            }
            var manager = BIDeviceManager.GetInstance();

            if (!manager.IsDeviceAttached(_key.ToString(), false))
            {
                return;
            }
            _controls       = manager.GetControlsOnDevice(this, false);
            _controlsLoaded = true;
        }
Example #3
0
 /// <summary>
 ///     Private implementation of Dispose()
 /// </summary>
 /// <param name="disposing">
 ///     flag to indicate if we should actually perform disposal.  Distinguishes the private method
 ///     signature from the public signature.
 /// </param>
 private void Dispose(bool disposing)
 {
     if (!_isDisposed)
     {
         if (disposing)
         {
             _instance = null;
         }
     }
     // Code to dispose the un-managed resources of the class
     if (_devicesOpen)
     {
         CloseDevices(false);
     }
     _isDisposed = true;
 }
Example #4
0
 public static BIDeviceManager GetInstance()
 {
     return(_instance ?? (_instance = new BIDeviceManager()));
 }