コード例 #1
0
        public BleGattCharacteristicViewModel(Guid service, Guid characteristic, IBleGattServer device,
                                              IUserDialogs dialogs)
        {
            m_device         = device;
            m_dialogs        = dialogs;
            m_service        = service;
            m_characteristic = characteristic;

            RefreshValueCommand         = new Command(async() => { await ReadValue(); });
            EnableNotificationsCommand  = new Command(EnableNotifications);
            DisableNotificationsCommand = new Command(DisableNotifications);
            ToggleNotificationsCommand  = new Command(ToggleNotifications);
            WriteBytesCommand           = new Command(async() => { await WriteCurrentBytes(); });

            ValueAsHex    = String.Empty;
            ValueAsString = String.Empty;

            m_device.ReadCharacteristicProperties(m_service, m_characteristic).ContinueWith(
                x =>
            {
                Device.BeginInvokeOnMainThread(
                    () =>
                {
                    //Log.Trace( "Reading properties for characteristic. id={0}", m_characteristic );
                    m_props = x.Result;
                    RaisePropertyChanged(nameof(CanNotify));
                    RaisePropertyChanged(nameof(CanRead));
                    RaisePropertyChanged(nameof(CanWrite));
                });
            });
        }
コード例 #2
0
        public BleGattCharacteristicViewModel(Guid serviceGuid, Guid characteristicGuid, IBleGattServer gattServer,
                                              IUserDialogs dialogManager)
        {
            m_gattServer         = gattServer;
            m_dialogManager      = dialogManager;
            m_serviceGuid        = serviceGuid;
            m_characteristicGuid = characteristicGuid;

            RefreshValueCommand         = new Command(async() => { await ReadCharacteristicValue(); });
            EnableNotificationsCommand  = new Command(EnableNotifications);
            DisableNotificationsCommand = new Command(DisableNotifications);
            ToggleNotificationsCommand  = new Command(() => { NotifyEnabled = !NotifyEnabled; });
            WriteBytesCommand           = new Command(async() => { await WriteCurrentBytes(); });

            ValueAsHex    = String.Empty;
            ValueAsString = String.Empty;

            m_gattServer.ReadCharacteristicProperties(m_serviceGuid, m_characteristicGuid).ContinueWith(
                x =>
            {
                Device.BeginInvokeOnMainThread(
                    () =>
                {
                    if (x.IsFaulted)
                    {
                        m_dialogManager.Toast(x.Exception.GetBaseException().Message);
                    }
                    else
                    {
                        Log.Trace("Reading properties for characteristic. id={0}", m_characteristicGuid);
                        m_props = x.Result;
                        RaisePropertyChanged(nameof(CanNotify));
                        RaisePropertyChanged(nameof(CanRead));
                        RaisePropertyChanged(nameof(CanWrite));
                    }
                });
            });
        }