public void Dispose() { //lock (_lock) //{ Close(); if (_Device == null) { return; } if (BluetoothRadio != null) { BluetoothRadio.StateChanged -= _BluetoothRadio_StateChanged; BluetoothRadio = null; } if (_Characteristics != null) { if (_ReadChar != null && _NotifyChar != null) { _ReadChar.ValueChanged -= _Read; _NotifyChar.ValueChanged -= _Read; } _Characteristics = null; } if (_Service != null) { _Service.Dispose(); _Service = null; } if (_Device != null) { _Device.ConnectionStatusChanged -= _Device_ConnectionStatusChanged; _Device.GattServicesChanged -= _Device_GattServicesChanged; _Device.Dispose(); _Device = null; } //} GC.Collect(); Monitor.Enter(_ReadLock); Monitor.Pulse(_ReadLock); Monitor.Exit(_ReadLock); }
public override void Stop() { if (Running) { #if DEBUG logger.Debug("Stopping HRP"); #endif Running = false; #if DEBUG logger.Debug("Stopping timeout timer"); #endif timeoutTimer.Stop(); if (characteristic != null) { #if DEBUG logger.Debug("Clearing GattCharacteristic"); #endif characteristic.ValueChanged -= Characteristic_ValueChanged; characteristic = null; } if (watcher != null) { #if DEBUG logger.Debug("Clearing device changed watcher"); #endif watcher.Stop(); watcher = null; } if (service != null) { #if DEBUG logger.Debug("Clearing GattDeviceService"); #endif service.Dispose(); service = null; } #if DEBUG logger.Debug("Resetting counters"); #endif DoReset(); } }
private void Stop() { Log("Stopping HRP"); if (characteristic != null) { Log("Clearing GattCharacteristic"); characteristic.ValueChanged -= characteristic_ValueChanged; characteristic = null; } if (watcher != null) { Log("Clearing device changed watcher"); watcher.Stop(); watcher = null; } if (service != null) { Log("Clearing GattDeviceService"); service.Dispose(); service = null; } running = false; }
public void Disconnect() { Previous_State = State; State = BLEServices.ConnectionState.Disconnected; ResetSensor(); try { if (BleWatcher != null) { if (BleWatcher.Status == BluetoothLEAdvertisementWatcherStatus.Started) { BleWatcher.Stop(); } } } catch { } _allGatt.Clear(); try { _gattDataSensorService.Dispose(); if (Device != null) { Device.Dispose(); } Device = null; } catch { } }
public void Disconnect() { SetStatus(CsacServiceStatus.UnInitialized); if (service != null) { service.Dispose(); service = null; } if (characteristic != null) { characteristic = null; } if (connectionWatcher != null) { if (connectionWatcher.Status == DeviceWatcherStatus.Started) { connectionWatcher.Stop(); } connectionWatcher = null; } if (device != null) { device = null; } alreadyTriedRePairing = false; }
private void Disconnect_device() { if (connected == true) { if (dataCharacteristics != null) { dataCharacteristics.ValueChanged -= PrintPacket; dataCharacteristics = null; } foreach (var i in ListServices.Items) { GattDeviceService service = (GattDeviceService)i; service.Dispose(); service = null; } connectedDevice = null; connected = false; ListServices.Items.Clear(); ListCharacteristics.Items.Clear(); connectedDeviceCharacteristics.Clear(); //KnownDevices.Clear(); GC.Collect(); StartEnumeration(); StopEnumeration(); } ListDevice.SelectedItem = null; StartEnumeration(); }
public async Task Disconnect() { try { if (_uartService != null) { await _uartService.Stop(); } if (_gattDeviceService != null) { _gattDeviceService.Dispose(); } if (_bleDevice != null) { _bleDevice.Dispose(); } } catch (Exception ex) { Debug.WriteLine("BLE_Device::Disconnect EXCEPTION " + ex.ToString()); } finally { _uartService = null; _gattDeviceService = null; _bleDevice = null; _sbResponse.Clear(); } }
private void ClearBluetoothLEDevice() { GattService?.Dispose(); GattService = null; if (ControlPoint != null) { ControlPoint = null; } if (NotificationSource != null) { NotificationSource.ValueChanged -= NotificationSource_ValueChanged; NotificationSource = null; } if (DataSource != null) { DataSource.NotificationAttributesReceived -= DataSource_NotificationAttributesReceived; DataSource = null; } try { bluetoothLeDevice.ConnectionStatusChanged -= BluetoothLeDevice_ConnectionStatusChanged; } catch (Exception ex) { // Do nothing } bluetoothLeDevice?.Dispose(); bluetoothLeDevice = null; }
private void CleanupConnection() { if (mConnectionCancelTokenSource != null) { mConnectionCancelTokenSource.Dispose(); mConnectionCancelTokenSource = null; } mUploadCharacteristic = null; mDownloadCharacteristic = null; if (mService != null) { mService.Dispose(); mService = null; } if (mDevice != null) { mDevice.Dispose(); mDevice = null; } mSendBufferWriter.BaseStream.SetLength(0); mReceiveBufferReader.BaseStream.SetLength(0); mReceiveMessageSize = -1; mReceiveMessageAddress = -1; mValueWriting = false; }
// HeartRate 정지 public void StopMonitorHeartrate() { if (HMCCharacteristic != null) { if (continuousMode) { manager.Write(HMCCharacteristic, new byte[] { 0x15, 0x01, 0x00 }); } else { manager.Write(HMCCharacteristic, new byte[] { 0x15, 0x02, 0x00 }); } } HMCCharacteristic = null; if (pingThread != null) { pingThread.Join(); pingThread = null; } if (SNSCharacteristic != null) { SNSCharacteristic.Service.Dispose(); SNSCharacteristic = null; } if (HMSService != null) { HMSService.Dispose(); HMSService = null; } }
private void App_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) { IsServiceInitialized = false; // This is an appropriate place to save to persistent storage any datapoint the application cares about. // For the purpose of this sample we just discard any values. datapoints.Clear(); // Allow the GattDeviceService to get cleaned up by the Windows Runtime. // The Windows runtime will clean up resources used by the GattDeviceService object when the application is // suspended. The GattDeviceService object will be invalid once the app resumes, which is why it must be // marked as invalid, and reinitalized when the application resumes. if (service != null) { service.Dispose(); service = null; } if (characteristic != null) { characteristic = null; } if (watcher != null) { watcher.Stop(); watcher = null; } }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { // Free any other managed objects here. // if (firstHeartRateMonitorService != null) { firstHeartRateMonitorService.Dispose(); firstHeartRateMonitorService = null; } if (hrMonitorCharacteristics != null) { hrMonitorCharacteristics.Service.Dispose(); hrMonitorCharacteristics = null; } } // Free any unmanaged objects here. // disposed = true; }
/// <summary> /// Should clean the objects resources. Disposes the deviceservice if it's not null and removes possible event handler. /// </summary> private void Clean() { if (deviceService != null) { deviceService.Dispose(); } deviceService = null; }
private async void FinishCloseOffStream() { channels.Clear(); await LSLCloseStream(); deviceService.Dispose(); IsStreaming = false; }
public async Task <bool> Disconnect() { var result = await _data_characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.None); if (result == GattCommunicationStatus.Success) { _data_characteristic.ValueChanged -= _data_characteristic_ValueChanged; _data_characteristic = null; _config_characteristic = null; _period_characteristic = null; _service.Dispose(); UpdateStatue(TrackerStatus.Disconnected, "Disconnected"); return(true); } _service.Dispose(); UpdateStatue(TrackerStatus.Disconnected, "Disconnected"); return(false); }
void ExecuteDisconnectCommand() { _notifyCharacteristic = null; _writeCharacteristic = null; _communicationService.Dispose(); _communicationService = null; _device.Dispose(); _device = null; Connected = false; }
public void Dispose() { foreach (var item in characteristics) { item.ValueChanged -= localValueChanged; } service?.Dispose(); GC.SuppressFinalize(this); }
private void FormLCD_FormClosing(object sender, FormClosingEventArgs e) { try { dataProcess.Abort(); } catch (Exception ex) { } try { csvParseProcess.Abort(); } catch (Exception ex) { } try { BluetoothUARTService.Dispose(); } catch (Exception ex) { } }
private void Clean() { if (deviceService != null) { deviceService.Dispose(); } deviceService = null; if (dataCharacteristic != null) { dataCharacteristic.ValueChanged -= dataCharacteristic_ValueChanged; } }
/// <summary> /// Called when disconnecting. /// </summary> private void OnDisconnect() { commandCancellationTokenSource?.Cancel(); writeCharacteristic = null; if (readCharacteristic != null) { readCharacteristic.ValueChanged -= ReadCharacteristic_ValueChanged; } readCharacteristic = null; deviceService?.Dispose(); deviceService = null; }
private async void OHbtnConn_Click(object sender, RoutedEventArgs e) { OHbtnConn.IsEnabled = false; if (OHbtnConn.Content.ToString() == "Connect") { if (lstDevices.SelectedItem != null) { device = lstDevices.SelectedItem as DeviceInformation; OHtxtStat.Text = "Initializing device..."; //HeartRateService.Instance.DeviceConnectionUpdated += OnDeviceConnectionUpdated; //await HeartRateService.Instance.InitializeServiceAsync(device); try { // BT_Code: BluetoothLEDevice.FromIdAsync must be called from a UI thread because it may prompt for consent. bluetoothLeDevice = await BluetoothLEDevice.FromIdAsync(device.Id); if (bluetoothLeDevice == null) { var dialog = new MessageDialog("Failed to connect to device."); await dialog.ShowAsync(); } else { GattDeviceServicesResult result = await bluetoothLeDevice.GetGattServicesAsync(BluetoothCacheMode.Uncached); if (result.Status == GattCommunicationStatus.Success) { var services = result.Services; OHtxtStat.Text = String.Format("Connected & Found {0} services", services.Count); } } } catch (Exception ex) { var dialog = new MessageDialog("Retrieving device properties failed with message: " + ex.Message); await dialog.ShowAsync(); } } } else//Disconnect { characteristics.ValueChanged -= Characteristic_ValueChanged; service.Dispose(); bluetoothLeDevice = null; GC.Collect(); } OHbtnConn.Content = OHbtnConn.Content.ToString() == "Disconnect" ? "Connect" : "Disconnect"; OHbtnConn.IsEnabled = true; }
public bool Disconnect() { if (GattService != null) { GattService.Dispose(); GattService = null; } Characteristics = null; ServiceUuid = Guid.Empty; BleDevice = null; return(true); }
private void ButtonDiscon_Click(object sender, RoutedEventArgs e) { if (Service_Fido != null) { Service_Fido.Dispose(); addLog("FIDO Service Disposed"); } if (BleDevice != null) { BleDevice.Dispose(); addLog("BLE Device Disposed"); } addLog("BLE FIDOキーと切断しました"); addLog(""); }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { { if (AdvWatcher != null) { this.AdvWatcher.Stop(); } if (Service_Fido != null) { Service_Fido.Dispose(); addLog("FIDO Service Disposed"); } if (BleDevice != null) { BleDevice.Dispose(); addLog("BLE Device Disposed"); } } // パスワードが求まっていない場合はここで通知する if (!string.IsNullOrEmpty(this.ArgUserID)) { if (string.IsNullOrEmpty(this.Password)) { var result = this.notify.Send(""); } } // save config { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (AuthUV == UVType.PIN) { config.AppSettings.Settings["SelectUV"].Value = "0"; } else { config.AppSettings.Settings["SelectUV"].Value = "1"; } config.Save(); } }
/// <summary> /// Cleaning up connections and variables. /// </summary> public void Dispose() { _currentDevice.DeviceInformation.Pairing.UnpairAsync(); Thread.Sleep(3000); _rxCharacteristic = null; _txCharacteristic = null; _service.Dispose(); _currentDevice.Dispose(); _currentDevice = null; _service = null; try { GC.Collect(); } catch (Exception e) { Console.WriteLine(e); } }
public void StopHeartrate() { if (!HeartrateMeasuringRuns) { return; } cts.Cancel(); heartrateService?.Dispose(); sensorService?.Dispose(); if (heartrateCharacteristic != null) { WriteToDevice(heartrateCharacteristic, new byte[] { 0x15, 0x01, 0x00 }); WriteToDevice(heartrateCharacteristic, new byte[] { 0x15, 0x02, 0x00 }); } HeartrateMeasuringRuns = false; }
private void App_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) { IsServiceInitialized = false; // This is an appropriate place to save to persistent storage any datapoint the application cares about. // Let us save the last known state of the backpack var lastItem = datapoints.Last(); localSettings.Values["last-backpack-state"] = lastItem.ToString(); // Then clear the information datapoints.Clear(); // Allow the GattDeviceService to get cleaned up by the Windows Runtime. // The Windows runtime will clean up resources used by the GattDeviceService object when the application is // suspended. The GattDeviceService object will be invalid once the app resumes, which is why it must be // marked as invalid, and reinitalized when the application resumes. if (service != null) { service.Dispose(); service = null; } if (rx_characteristic != null) { rx_characteristic = null; } if (tx_characteristic != null) { tx_characteristic = null; } if (watcher != null) { watcher.Stop(); watcher = null; } }
public void Dispose() { if (_isDisposed) { return; } BaseDevice?.Dispose(); _busService?.Dispose(); if (_busTxChar != null) { _busTxChar.ValueChanged -= _txChar_ValueChanged; } _busTxChar = null; _busRxChar = null; _isDisposed = true; }
//Stops the service internal void Stop() { IsServiceInitialized = false; _datapoints.Clear(); if (_service != null) { _service.Dispose(); } if (_characteristic != null) { _characteristic = null; } if (_watcher != null) { _watcher.Stop(); _watcher = null; } }
async Task Connect(DeviceInfo device) { bool connected = false; if (device.type == Constants.TYPE_DAYDREAM) { connected = await ConnectDaydream(device.info); } else if (device.type == Constants.TYPE_GEARVR) { connected = await ConnectGearVR(device.info); } if (!connected) { if (service != null) { service.Dispose(); service = null; } } }