/// <summary>
        ///
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private Task <bool> WaitForParameterChanged(R7GenericDeviceParameter parameter, int value, bool throwOnError = false)
        {
            return(Task.Run(() =>
            {
                try
                {
                    var current = ConnectedDevice.Parameters.SingleOrDefault(x => x.Id == parameter.FromR7());

                    if (current == null)
                    {
                        throw new Exception();
                    }

                    //if (Convert.ToInt32(current.CachedValue) == value)
                    //return true;

                    AutoResetEvent r = new AutoResetEvent(false);

                    EventHandler <ParameterChangedEventArgs> handler = (s, e) =>
                    {
                        if (e.Parameter.Id.ToR7().EnumToInt() == parameter.EnumToInt())
                        {
                            r.Set();
                        }
                    };

                    try
                    {
                        ConnectedDevice.ParameterChanged += handler;
                        r.WaitOne(TimeSpan.FromSeconds(10));

                        var @new = ConnectedDevice.Parameters.SingleOrDefault(x => x.Id == parameter.FromR7());

                        if (Convert.ToInt32(@new.CachedValue) != value)
                        {
                            throw new Exception();
                        }

                        return true;
                    }
                    finally
                    {
                        ConnectedDevice.ParameterChanged -= handler;
                    }
                }
                catch (Exception e)
                {
                    if (throwOnError)
                    {
                        throw e;
                    }

                    return false;
                }
            }));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private Task <bool> WaitForParameterAny(R7GenericDeviceParameter parameter, bool throwOnError = false)
        {
            return(Task.Run(() =>
            {
                try
                {
                    var current = comms.CurrentDevice.ParameterForIdentifier(parameter.EnumToInt())?.CachedValue;


                    if (current != 999 &&
                        current != 255
#if ANDROID
                        && current != -1
#endif
                        )
                    {
                        return true;
                    }

                    AutoResetEvent r = new AutoResetEvent(false);

                    EventHandler <ParameterChangedEventArgs> handler = (s, e) =>
                    {
                        if (e.Parameter.Id.ToR7().EnumToInt() == parameter.EnumToInt())
                        {
                            r.Set();
                        }
                    };

                    EventHandler <DeviceParameter> handler1 = (s, e) =>
                    {
                        if (e.Identifier.ToR7().EnumToInt() == parameter.EnumToInt())
                        {
                            r.Set();
                        }
                    };

                    EventHandler <LockStatusUpdatedEventArgs> handler2 = (s, e) =>
                    {
                        if (e.New != LockState.Unlocked)
                        {
                            r.Set();
                        }
                    };

                    try
                    {
                        __DeviceParameterUpdated += handler1;
                        ConnectedDevice.ParameterChanged += handler;
                        ConnectedDevice.DeviceLockStatusUpdated += handler2;
                        r.WaitOne(TimeSpan.FromSeconds(10));

                        var @new = comms.CurrentDevice.ParameterForIdentifier(parameter.EnumToInt())?.CachedValue;

                        if (@new == 999 ||
                            @new == 255
#if ANDROID
                            || @new == -1
#endif
                            )
                        {
                            if (device.LockStatus == LockState.Locked)
                            {
                                throw new DeviceIsLockedException();
                            }

                            throw new Exception();
                        }


                        return true;
                    }
                    finally
                    {
                        __DeviceParameterUpdated -= handler1;
                        ConnectedDevice.ParameterChanged -= handler;
                        ConnectedDevice.DeviceLockStatusUpdated -= handler2;
                    }
                }
                catch (Exception e)
                {
                    if (throwOnError)
                    {
                        throw e;
                    }

                    return false;
                }
            }));
        }