public static EddystoneFrameType FrameTypeForFrame(NSDictionary advertisementFrameList) { var frameData = advertisementFrameList.ObjectForKey(CBUUID.FromString("FEAA")) as NSData; if (frameData != null && frameData.Length >= 1) { var frameBytes = frameData.ToArray(); if (frameBytes[0] == EddystoneUIDFrameTypeID) { return(EddystoneFrameType.UIDFrameType); } else if (frameBytes[0] == EddystoneTLMFrameTypeID) { return(EddystoneFrameType.TelemetryFrameType); } else if (frameBytes[0] == EddystoneEIDFrameTypeID) { return(EddystoneFrameType.EIDFrameType); } else if (frameBytes[0] == EddystoneURLFrameTypeID) { return(EddystoneFrameType.URLFrameType); } else { return(EddystoneFrameType.UnknownFrameType); } } return(EddystoneFrameType.UnknownFrameType); }
public async Task StartAdvertising(string localName, List <IService> services) { if (_peripheralManager.State != CBPeripheralManagerState.PoweredOn) { throw new InvalidStateException((ManagerState)_peripheralManager.State); } var cbuuIdArray = new NSMutableArray(); var optionsDict = new NSMutableDictionary(); if (services != null) { foreach (Service service in services) { cbuuIdArray.Add(CBUUID.FromString(service.Uuid)); //_peripheralManager.AddService((CBMutableService) service.NativeService); } optionsDict[CBAdvertisement.DataServiceUUIDsKey] = cbuuIdArray; } if (localName != null) { optionsDict[CBAdvertisement.DataLocalNameKey] = new NSString(localName); } _peripheralManager.StartAdvertising(optionsDict); }
public override void DiscoveredService(CBPeripheral peripheral, NSError error) { var descriptor = peripheral.ToDeviceDescriptor(); if (error != null) { _deviceManager.HandleDeviceCommunicationDiscoveryServiceError(descriptor, error.LocalizedFailureReason, (d) => { _centralManager.CancelPeripheralConnection(peripheral); }); return; } CBUUID uuidCharacteristic = CBUUID.FromString(_tracingInformation.CharacteristicId); CBUUID uuidService = CBUUID.FromString(_tracingInformation.ServiceId); var service = peripheral.Services.FirstOrDefault(x => x.UUID == uuidService); if (service != null) { _deviceManager.HandleDeviceCommunicationDiscoveredService(descriptor, (d) => { peripheral.DiscoverCharacteristics(new[] { uuidCharacteristic }, service); }); } else { _deviceManager.HandleIncorrectDevice(descriptor); _centralManager.CancelPeripheralConnection(peripheral); } }
public async void StartScanningForDevices(Guid serviceUuid) { await WaitForState(CBCentralManagerState.PoweredOn); Debug.WriteLine("Adapter: Starting a scan for devices."); CBUUID[] serviceUuids = null; // TODO: convert to list so multiple Uuids can be detected if (serviceUuid != Guid.Empty) { var suuid = CBUUID.FromString(serviceUuid.ToString()); serviceUuids = new CBUUID[] { suuid }; Debug.WriteLine("Adapter: Scanning for " + suuid); } // clear out the list DiscoveredDevices = new List <IDevice>(); // start scanning IsScanning = true; CentralManager.ScanForPeripherals(serviceUuids); // in 10 seconds, stop the scan await Task.Delay(10000); // if we're still scanning if (IsScanning) { Console.WriteLine("Adapter: Scan timeout has elapsed."); IsScanning = false; CentralManager.StopScan(); ScanTimeoutElapsed(this, new EventArgs()); } }
public void StartScan(BleDevice device) { _CentralManager = new CBCentralManager(this, null); if (device == null) { throw new Exception("Could not start client without a service type to scan for."); } _CentralManager.DiscoveredPeripheral += (o, e) => { DeviceFound?.Invoke(this, new DeviceEventArgs { Device = new BleDevice { Guid = e.Peripheral.UUID.Uuid } }); }; _CentralManager.ConnectedPeripheral += (o, e) => { DeviceConnected?.Invoke(this, new DeviceEventArgs { Device = new BleDevice { Guid = e.Peripheral.UUID.Uuid } }); }; //_CentralManager.ScanForPeripherals(CBUUID.FromPartial(device.GuidValue)); _CentralManager.ScanForPeripherals(CBUUID.FromString(device.Guid)); }
public async void StartScanningForDevices(Guid serviceUuid, int timeOutSeconds = 10) { // // Wait for the PoweredOn state // await WaitForState(CBCentralManagerState.PoweredOn); Debug.WriteLine("Adapter: Starting a scan for devices."); CBUUID[] serviceUuids = null; // TODO: convert to list so multiple Uuids can be detected if (serviceUuid != Guid.Empty) { var suuid = CBUUID.FromString(serviceUuid.ToString()); serviceUuids = new CBUUID[] { suuid }; Debug.WriteLine("Adapter: Scanning for " + suuid); } // clear out the list this._discoveredDevices = new List <IDevice> (); // start scanning this._isScanning = true; this._central.ScanForPeripherals(serviceUuids); // in 10 seconds, stop the scan await Task.Delay(TimeSpan.FromSeconds(timeOutSeconds)); // if we're still scanning if (this._isScanning) { Console.WriteLine("BluetoothLEManager: Scan timeout has elapsed."); StopScanningForDevices(); this.ScanTimeoutElapsed(this, new EventArgs()); } }
public Task <byte[]> ReadValue(string characteristicGuid, bool important = false) { var cbuuid = CBUUID.FromString(characteristicGuid); // TODO: Check for connected devices? if (_characteristics.ContainsKey(cbuuid) == false) { // TODO Error? return(null); } // Already awaiting it. if (_readQueue.ContainsKey(cbuuid)) { return(_readQueue[cbuuid].Task); } var taskCompletionSource = new TaskCompletionSource <byte[]>(); if (important) { // TODO: Put this at the start of the queue. _readQueue.Add(cbuuid, taskCompletionSource); } else { _readQueue.Add(cbuuid, taskCompletionSource); } _peripheral.ReadValue(_characteristics[cbuuid]); return(taskCompletionSource.Task); }
public void Start(TracingInformation tracingInformation) { if (tracingInformation == null || _enabled) { return; } _tracingInformation = tracingInformation; _peripheralManager.RemoveAllServices(); CBUUID uuidService = CBUUID.FromString(tracingInformation.ServiceId); CBUUID uuidCharacteristic = CBUUID.FromString(tracingInformation.CharacteristicId); var data = NSData.FromArray(PayloadFormatter.GetBytesToSend(new PackageData(tracingInformation.DeviceId))); var characteristic = new CBMutableCharacteristic(uuidCharacteristic, CBCharacteristicProperties.Read, data, CBAttributePermissions.Readable); var service = new CBMutableService(uuidService, true); service.Characteristics = new CBCharacteristic[] { characteristic }; _peripheralManager.AddService(service); StartAdvertisingOptions advData = new StartAdvertisingOptions { ServicesUUID = new CBUUID[] { uuidService } }; _peripheralManager.StartAdvertising(advData); TracingState.Instance.SetAdvertisingState(true); _enabled = true; _logger.LogDebug("Advertising starting. DeviceId: " + _tracingInformation.DeviceId); }
public static EddystoneFrameType FrameTypeForFrame(NSDictionary advertisementFrameList) { var uuid = CBUUID.FromString("FEAA"); var frameData = advertisementFrameList[uuid] as NSData; if (frameData != null) { var count = frameData.Length; if (count > 1) { var frameBytes = Enumerable.Repeat((byte)0, (int)count).ToArray(); Marshal.Copy(frameData.Bytes, frameBytes, 0, (int)count); if (frameBytes[0] == BeaconInfo.EddystoneUIDFrameTypeID) { return(BeaconInfo.EddystoneFrameType.UIDFrameType); } else if (frameBytes[0] == BeaconInfo.EddystoneTLMFrameTypeID) { return(BeaconInfo.EddystoneFrameType.TelemetryFrameType); } else if (frameBytes[0] == BeaconInfo.EddystoneEIDFrameTypeID) { return(BeaconInfo.EddystoneFrameType.EIDFrameType); } else if (frameBytes[0] == BeaconInfo.EddystoneURLFrameTypeID) { return(BeaconInfo.EddystoneFrameType.URLFrameType); } } } return(EddystoneFrameType.UnknownFrameType); }
public static BeaconInfo BeaconInfoForUIDFrameData(NSDictionary advertisementFrameList, NSData telemetry, int rssi) { var frameData = advertisementFrameList.ObjectForKey(CBUUID.FromString("FEAA")) as NSData; if (frameData.Length > 1) { var frameBytes = frameData.ToArray(); if (frameBytes[0] != EddystoneUIDFrameTypeID) { System.Diagnostics.Debug.WriteLine("Unexpected non UID Frame passed to BeaconInfoForUIDFrameData."); return(null); } else if (frameBytes.Length < 18) { System.Diagnostics.Debug.WriteLine("Frame Data for UID Frame unexpectedly truncated in BeaconInfoForUIDFrameData."); } var txPower = Convert.ToInt32(frameBytes[1]); var beaconID = new byte [frameBytes.Length - 2]; Array.Copy(frameBytes, 2, beaconID, 0, beaconID.Length); var bid = new BeaconID(BeaconType.Eddystone, beaconID); return(new BeaconInfo(bid, txPower, rssi, telemetry)); } return(null); }
public void Equality_PartialEqualsFull() { using (var u1 = CBUUID.FromPartial(0x0127)) using (var u2 = MakeFull(0x01, 0x27)) { Assert.True(u1.Equals((object)u2), "Equals-1a"); Assert.True(u1.Equals((NSObject)u2), "Equals-1b"); Assert.True(u1.Equals((CBUUID)u2), "Equals-1b"); Assert.That(u1.GetHashCode(), Is.EqualTo(u2.GetHashCode()), "GetHashCode-1"); } using (var u1 = CBUUID.FromBytes(new byte [] { 0xab, 0xcd })) using (var u2 = MakeFull(0xab, 0xcd)) { Assert.True(u1.Equals((object)u2), "Equals-2a"); Assert.True(u1.Equals((NSObject)u2), "Equals-2b"); Assert.True(u1.Equals((CBUUID)u2), "Equals-2b"); Assert.That(u1.GetHashCode(), Is.EqualTo(u2.GetHashCode()), "GetHashCode-2"); } using (var u1 = CBUUID.FromString("1234")) using (var u2 = CBUUID.FromString("00001234-0000-1000-8000-00805f9b34fb")) { Assert.True(u1.Equals((object)u2), "Equals-3a"); Assert.True(u1.Equals((NSObject)u2), "Equals-3b"); Assert.True(u1.Equals((CBUUID)u2), "Equals-3b"); Assert.That(u1.GetHashCode(), Is.EqualTo(u2.GetHashCode()), "GetHashCode-3"); } #if MONOMAC Assert.That(CBUUID.FromBytes(new byte [] { 0xab, 0xcd, 0xef, 0x12 }), Is.EqualTo(MakeFull(0xab, 0xcd, 0xef, 0x12))); Assert.That(CBUUID.FromString("12345678"), Is.EqualTo(CBUUID.FromString("12345678-0000-1000-8000-00805f9b34fb"))); #endif }
public static CBUUID ToCBUUID(this Guid guid) { var bytes = guid.ToByteArray(); return(CBUUID.FromString(guid.ToString())); //return CBUUID.FromBytes(guid.ToByteArray()); }
protected override async Task <bool> StartScanningForDevicesNativeAsync(Guid[] serviceUuids, Boolean allowDuplicatesKey, CancellationToken scanCancellationToken) { // Wait for the PoweredOn state await this.WaitForState(CBCentralManagerState.PoweredOn, scanCancellationToken).ConfigureAwait(false); if (scanCancellationToken.IsCancellationRequested) { throw new TaskCanceledException("StartScanningForDevicesNativeAsync cancelled"); } Trace.Message("Adapter: Starting a scan for devices."); CBUUID[] serviceCbuuids = null; if (serviceUuids != null && serviceUuids.Any()) { serviceCbuuids = serviceUuids.Select(u => CBUUID.FromString(u.ToString())).ToArray(); Trace.Message("Adapter: Scanning for " + serviceCbuuids.First()); } this.DiscoveredDevices.Clear(); this._centralManager.ScanForPeripherals(serviceCbuuids, new PeripheralScanningOptions { AllowDuplicatesKey = allowDuplicatesKey }); return(true); }
/// <summary> /// Gets the paired devices. /// </summary> /// <returns>Task<IReadOnlyList<IBluetoothDevice>>.</returns> public async Task <IReadOnlyList <IBluetoothDevice> > GetPairedDevices() { return(await Task.Factory.StartNew(() => { var devices = new List <IBluetoothDevice>(); var action = new EventHandler <CBPeripheralsEventArgs>((s, e) => devices.AddRange(e.Peripherals.Select(a => new BluetoothDevice(a)))); this.manager.RetrievedPeripherals += action; this.manager.RetrievedConnectedPeripherals += ManagerOnRetrievedConnectedPeripherals; this.manager.DiscoveredPeripheral += manager_DiscoveredPeripheral; //CBUUID id = null; // Bug in Xamarin? https://bugzilla.xamarin.com/show_bug.cgi?id=5808 //this.manager.ScanForPeripherals(id, null); this.manager.ScanForPeripherals(CBUUID.FromString(TransferServiceUuid)); this.manager.RetrievePeripherals(CBUUID.FromString(TransferServiceUuid)); //this.manager.RetrieveConnectedPeripherals(new[] { CBUUID.FromString(TransferServiceUuid) }); this.manager.RetrievedPeripherals -= action; this.manager.RetrievedConnectedPeripherals -= ManagerOnRetrievedConnectedPeripherals; this.manager.DiscoveredPeripheral -= manager_DiscoveredPeripheral; return devices; })); }
public async Task <CBService> GetService(CBPeripheral peripheral, string serviceUuid) { var service = this.GetServiceIfDiscovered(peripheral, serviceUuid); if (service != null) { return(service); } var taskCompletion = new TaskCompletionSource <bool>(); var task = taskCompletion.Task; EventHandler <NSErrorEventArgs> handler = (s, e) => { if (this.GetServiceIfDiscovered(peripheral, serviceUuid) != null) { taskCompletion.SetResult(true); } }; try { peripheral.DiscoveredService += handler; peripheral.DiscoverServices(new[] { CBUUID.FromString(serviceUuid) }); await this.WaitForTaskWithTimeout(task, ConnectionTimeout); return(this.GetServiceIfDiscovered(peripheral, serviceUuid)); } finally { peripheral.DiscoveredService -= handler; } }
public Characteristic(Guid uuid, CharacterisiticPermissionType permissions, CharacteristicPropertyType properties) { CBAttributePermissions nativePermissions = 0; nativePermissions = GetNativePermissions(permissions); _nativeCharacteristic = new CBMutableCharacteristic(CBUUID.FromString(uuid.ToString()), (CBCharacteristicProperties)properties, null, nativePermissions); }
public async void StartScanningForDevices(Guid serviceUuid) { await WaitForState(CBCentralManagerState.PoweredOn); Debug.WriteLine("Adapter: Starting a scan for devices."); CBUUID[] serviceUuids = null; // TODO: convert to list so multiple Uuids can be detected if (serviceUuid != Guid.Empty) { var suuid = CBUUID.FromString(serviceUuid.ToString()); serviceUuids = new CBUUID[] { suuid }; Debug.WriteLine("Adapter: Scanning for " + suuid); } this._discoveredDevices = new List <IDevice>(); this._isScanning = true; this._central.ScanForPeripherals(serviceUuids); await Task.Delay(10000); if (this._isScanning) { Console.WriteLine("BluetoothLEManager: Scan timeout has elapsed."); this._isScanning = false; this._central.StopScan(); this.ScanTimeoutElapsed(this, new EventArgs()); } }
public void Build(CBMutableService service) { this.native = new CBMutableCharacteristic( CBUUID.FromString(this.Uuid), this.properties, null, this.permissions ); service.Characteristics = service.Characteristics.Expand(this.native); if (this.onWrite != null) { this.manager.WriteRequestsReceived += this.OnWrite; } if (this.onRead != null) { this.manager.ReadRequestReceived += this.OnRead; } if (this.onSubscribe != null) { this.manager.CharacteristicSubscribed += this.OnSubscribed; this.manager.CharacteristicUnsubscribed += this.OnUnSubscribed; } }
public BtError enumerateDevices() { if (!isScanning) { devices.Clear(); deviceAddresses.Clear(); serviceObjects.Clear(); characteristicObjects.Clear(); descriptorObjects.Clear(); var error = checkBtSupport(); if (error != BtError.None) { return(error); } var uuids = new List <CBUUID>(); foreach (var s in scanServices) { uuids.Add(CBUUID.FromString(s)); } var options = new PeripheralScanningOptions(); options.AllowDuplicatesKey = true; centralManager.ScanForPeripherals(uuids.ToArray(), options); isScanning = true; return(BtError.None); } else { return(BtError.AlreadyRunning); } }
public void WakeUp(CBPeripheral peripheral) { // Method that sends commands to sphero in specific order to wake it up // Create required data NSData antiDOS = NSData.FromString("011i3"); var txdata = new byte[1]; txdata[0] = 0x07; NSData TXdata = NSData.FromArray(txdata); var wakeupdata = new byte[1]; wakeupdata[0] = 0x01; NSData WakeupData = NSData.FromArray(wakeupdata); // Notes // peripheral.Services[0].Characteristics is Control/Response Characteristics // Control first, then Response // peripheral.Services[1].Characteristics is Radio Service Characteristics // peripheral.Services[2].Characteristics is Device Info Characteristics // peripheral.Services[3].Characteristics is Device Information // Sending the wake up commands to the sphero // Can be simplified (either if discovery of services and characteristics are static, or by sorting the arrays // that information is contained in. For now this is just a working version. foreach (var characteristic in peripheral.Services[1].Characteristics) { if (characteristic.UUID == CBUUID.FromString("22bb746f-2bbd-7554-2D6F-726568705327")) { Console.WriteLine("Writing to Anti DOS"); peripheral.WriteValue(antiDOS, characteristic, CBCharacteristicWriteType.WithResponse); } } foreach (var characteristic in peripheral.Services[1].Characteristics) { if (characteristic.UUID == CBUUID.FromString("22bb746f-2bb2-7554-2D6F-726568705327")) { Console.WriteLine("Writing to TX Power"); peripheral.WriteValue(TXdata, characteristic, CBCharacteristicWriteType.WithResponse); } } foreach (var characteristic in peripheral.Services[1].Characteristics) { if (characteristic.UUID == CBUUID.FromString("22bb746f-2bbf-7554-2D6F-726568705327")) { Console.WriteLine("Writing to Wakeup"); peripheral.WriteValue(WakeupData, characteristic, CBCharacteristicWriteType.WithResponse); } } /* * peripheral.WriteValue(antiDOS, peripheral.Services[1].Characteristics[3], CBCharacteristicWriteType.WithResponse); * peripheral.WriteValue(TXdata, peripheral.Services[1].Characteristics[0], CBCharacteristicWriteType.WithResponse); * peripheral.WriteValue(WakeupData, peripheral.Services[1].Characteristics[5], CBCharacteristicWriteType.WithResponse); */ }
public void ClearUnusedConnections() { connectionLookup.Clear(); foreach (var device in ion.deviceManager.knownDevices) { connectionLookup[CBUUID.FromString(device.connection.address)] = device.connection; } }
public GattService(CBPeripheralManager manager, string uuid, bool primary) { this.manager = manager; this.Native = new CBMutableService(CBUUID.FromString(uuid), primary); this.characteristics = new List <GattCharacteristic>(); this.Uuid = uuid; this.Primary = primary; }
public void subscribeToUartChars() { var tx = getCharacteristic(CBUUID.FromString(BTValues.txCharacteristic)); if (tx != null && connectedPeripheral != null) { connectedPeripheral.SetNotifyValue(true, tx); } }
public IEnumerable <BluetoothDevice> ScanForDevices() { _devices = new List <BluetoothDevice>(); _nativeDevices = new List <CBPeripheral>(); _manager?.ScanForPeripherals(CBUUID.FromString("00001101-0000-1000-8000-00805F9B34FB")); _manager?.StopScan(); return(_devices); }
public Service(Guid uuid, bool isPrimary) { this.uuid = uuid; NativeService = new CBMutableService(CBUUID.FromString(uuid.ToString()), isPrimary); var characteristics = new ObservableCollection <ICharacteristic>(); characteristics.CollectionChanged += CharacteristicsOnCollectionChanged; Characteristics = characteristics; }
public void writeToUart(byte[] data) { var c = getCharacteristic(CBUUID.FromString(BTValues.rxCharacteristic)); if (c != null && connectedPeripheral != null) { connectedPeripheral.WriteValue(NSData.FromArray(data), c, CBCharacteristicWriteType.WithoutResponse); callback.onUartDataSent(data); } }
public void Start(BleDevice device, BleCharacteristic[] characteristics) { string dataServiceUUIDsKey = "71DA3FD1-7E10-41C1-B16F-4430B5060000"; string customBeaconServiceUUIDsKey = "71DA3FD1-7E10-41C1-B16F-4430B5060001"; string customBeaconCharacteristicUUIDKey = "71DA3FD1-7E10-41C1-B16F-4430B5060002"; string identifier = "71DA3FD1-7E10-41C1-B16F-4430B5060003"; peripheralManager = new CBPeripheralManager(this, DispatchQueue.DefaultGlobalQueue); peripheralManager.AdvertisingStarted += (sender, e) => { if (e.Error != null) { System.Diagnostics.Debug.WriteLine(string.Format("*** BleServer -> Advertising error: {0}", e.Error.Description)); } else { System.Diagnostics.Debug.WriteLine("*** BleServer -> We are advertising."); } }; var customBeaconServiceUUID = CBUUID.FromString(customBeaconServiceUUIDsKey); var customBeaconCharacteristicUUID = CBUUID.FromString(customBeaconCharacteristicUUIDKey); var service = new CBMutableService(customBeaconServiceUUID, true); var dataUUID = NSData.FromString(identifier, NSStringEncoding.UTF8); var characteristic = new CBMutableCharacteristic( customBeaconCharacteristicUUID, CBCharacteristicProperties.Read, dataUUID, CBAttributePermissions.Readable); service.Characteristics = new CBCharacteristic[] { characteristic }; peripheralManager.AddService(service); var localName = new NSString("CustomBeacon"); //var advertisingData = new NSDictionary( CBAdvertisement.DataLocalNameKey, localName, // CBAdvertisement.IsConnectable, false, // CBAdvertisement.DataManufacturerDataKey, CBUUID.FromString(dataServiceUUIDsKey), // CBAdvertisement.DataServiceUUIDsKey, CBUUID.FromString(dataServiceUUIDsKey)); //peripheralManager.StartAdvertising(advertisingData); var UUI = new CBUUID[] { CBUUID.FromString("71DA3FD1-7E10-41C1-B16F-4430B5060000") }; NSArray arry = NSArray.FromObjects(UUI); var test = NSObject.FromObject(arry); var ad = new NSDictionary(CBAdvertisement.DataServiceUUIDsKey, test); peripheralManager.StartAdvertising(ad); }
public void Roundtrip_128bits() { using (CBUUID uuid = CBUUID.FromString("12345678-90AB-CDEF-cafe-c80c20443d0b")) { Assert.That(uuid.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle"); Assert.IsNotNull(uuid.Data, "Data"); Assert.That(uuid.ToString(false), Is.EqualTo(uuid.ToString(true)), "ToString"); using (CBUUID u2 = CBUUID.FromString(uuid.ToString())) { Assert.That(u2.ToString(), Is.EqualTo(uuid.ToString()), "Roundtrip"); } } }
public async void StartScanningForDevices(Guid[] serviceUuids) { if (_isScanning) { Mvx.Trace("Adapter: Already scanning!"); return; } _isScanning = true; // in ScanTimeout seconds, stop the scan _cancellationTokenSource = new CancellationTokenSource(); try { // Wait for the PoweredOn state await WaitForState(CBCentralManagerState.PoweredOn, _cancellationTokenSource.Token).ConfigureAwait(false); Mvx.Trace("Adapter: Starting a scan for devices."); CBUUID[] serviceCbuuids = null; if (serviceUuids != null && serviceUuids.Any()) { serviceCbuuids = serviceUuids.Select(u => CBUUID.FromString(u.ToString())).ToArray(); Mvx.Trace("Adapter: Scanning for " + serviceCbuuids.First()); } // clear out the list _discoveredDevices = new List <IDevice>(); // start scanning _central.ScanForPeripherals(serviceCbuuids); await Task.Delay(ScanTimeout, _cancellationTokenSource.Token); Mvx.Trace("Adapter: Scan timeout has elapsed."); StopScan(); TryDisposeToken(); _isScanning = false; //important for this to be caled after _isScanning = false so don't move to finally block ScanTimeoutElapsed(this, new EventArgs()); } catch (TaskCanceledException) { Mvx.Trace("Adapter: Scan was cancelled."); StopScan(); TryDisposeToken(); _isScanning = false; } }
public void Roundtrip_16bits() { using (CBUUID uuid = CBUUID.FromString("1234")) { Assert.That(uuid.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle"); Assert.IsNotNull(uuid.Data, "Data"); Assert.That(uuid.ToString(false), Is.EqualTo("1234"), "ToString(false)"); Assert.That(uuid.ToString(true), Is.EqualTo("00001234-0000-1000-8000-00805f9b34fb"), "ToString(true)"); using (CBUUID u2 = CBUUID.FromString(uuid.ToString())) { Assert.That(u2.ToString(), Is.EqualTo(uuid.ToString()), "Roundtrip"); } } }