Beispiel #1
0
        /// <summary>
        ///     Tries to discover enough devices
        /// </summary>
        /// <param name="discoverAttempts">How many times should we try to discover</param>
        /// <param name="minDevices">How many times devices do we minimally need</param>
        /// <param name="deviceType">Pozyx device type</param>
        /// <param name="idleSlots">Pozyx idle slot</param>
        /// <param name="idleSlotDuration">Pozyx idle slot duration</param>
        /// <returns> number of devices found. -1 means an error or not enough devices found</returns>
        public async Task <int> DiscoverDevices(int discoverAttempts = 10, int minDevices = 4, int deviceType = 0, int idleSlots = 3, int idleSlotDuration = 10)
        {
            bool discoverSuccess;

            int deviceListSize;

            for (int i = 0; i < discoverAttempts; i++)
            {
                discoverSuccess = DeviceListFunctions.DevicesDiscover(deviceType, idleSlots, idleSlotDuration);

                if (!discoverSuccess)
                {
                    return(-1);
                }

                await Task.Delay(2000);

                deviceListSize = GeneralData.GetDeviceListSize();
                if (deviceListSize >= minDevices)
                {
                    return(deviceListSize);
                }

                // Not enough deviced found wait 1 second and try again
                await Task.Delay(1000);
            }

            // Not enough devices found and out of attempts
            return(-1);
        }