Exemplo n.º 1
0
        public static void UnpairByMac(MacAddress mac, int discoveryTime, Utils.DeviceType deviceType)
        {
            var devices = DeviceFinder.FindDevicesByMac(DeviceDiscoverer.DiscoverPairedBluetoothDevices(discoveryTime), mac, deviceType);

            if (devices.Count > 1)
            {
                throw new Exception($"{devices.Count} devices found, don't know which one to choose");
            }

            DevicePairer.UnpairDevice(devices[0]);
        }
        private static void PairWithMac(MacAddress mac, int discoveryTime, Utils.DeviceType deviceType, string pin)
        {
            var devices = DeviceFinder.FindDevicesByMac(DeviceDiscoverer.DiscoverBluetoothDevices(discoveryTime), mac, deviceType);

            if (devices.Count == 1)
            {
                DevicePairer.PairDevice(devices[0], pin);
                return;
            }

            if (devices.Count == 2)
            {
                throw new Exception(
                          $"2 devices with the mac '{mac}' found \"{devices[0]}\" and \"{devices[1]}\". Don't know which one to choose.\n");
            }

            throw new Exception(
                      $"{devices.Count} devices with the mac '{mac}' found. Don't know which one to choose");
        }