/// <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; } } }
/// <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; }