Beispiel #1
0
        public async Task <IEnumerable <DiscoveryInfoModel> > GetUnits()
        {
            var discoverer = new DeviceDiscoverer();
            var units      = await discoverer.Discover();

            return(units);
        }
Beispiel #2
0
        public static void UnpairByName(string name, int discoveryTime, Utils.DeviceType deviceType)
        {
            var devices = DeviceFinder.FindDevicesByName(DeviceDiscoverer.DiscoverPairedBluetoothDevices(discoveryTime), name, deviceType);

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

            DevicePairer.UnpairDevice(devices[0]);
        }
        public static void Execute(DiscoverDevicesOptions opts)
        {
            var devices = DeviceDiscoverer.DiscoverBluetoothDevices(opts.DiscoveryTime);

            Console.WriteLine("----------------------------------------------------------");
            foreach (var d in devices)
            {
                PrintDevice(d);
            }
            Console.WriteLine("----------------------------------------------------------");
        }
Beispiel #4
0
        /// <summary>
        /// Scans for connected devices.
        /// </summary>
        /// <param name="timeOut">Discovery time out in milliseconds.</param>
        /// <returns>
        /// Returns an array of connected devices
        /// </returns>
        /// <exception cref="System.ArgumentException">An error occured while attempting to scan for connected devices.</exception>
        internal async Task <Device[]> ScanDevicesAsync(int timeOut = 20000)
        {
            Device[] devices = new Device[0];

            try //Attempt to find connected palmsens/emstat devices
            {
                _deviceDiscoverer = new DeviceDiscoverer(Context);
                devices           = (await _deviceDiscoverer.Discover(EnableUSB, EnableBluetooth, timeOut)).ToArray();
                _deviceDiscoverer.Dispose();
            }
            catch (Exception ex)
            {
                throw new ArgumentException($"An error occured while attempting to scan for connected devices. {ex.Message}");
            }
            return(devices);
        }
        /*
         * 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");
         * }
         */

        private static async Task <bool> PairWithName(string name, int discoveryTime, Utils.DeviceType deviceType, string pin)
        {
            var devices = DeviceFinder.FindDevicesByName(DeviceDiscoverer.DiscoverBluetoothDevices(discoveryTime), name, deviceType);

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

            if (devices.Count == 2 && devices[0].Type == Bluetooth.DeviceType.BluetoothLE && devices[1].Type == Bluetooth.DeviceType.BluetoothLE)
            {
                return(await HandleSituation_2_BluetoothLe_devices_with_the_same_name_found(devices[0], devices[1], pin));
            }

            throw new Exception($"{devices.Count} devices with the name '{name}' found. Don't know which one to choose");
        }
        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");
        }