コード例 #1
0
        /// <summary>
        /// Initialization
        /// </summary>
        /// <param name="device"></param>
        /// <param name="deviceInfo"></param>
        public void Initialize(BluetoothLEDevice device, DeviceInformation deviceInfo)
        {
            // Check for valid input
            if (device == null)
            {
                throw new ArgumentNullException("In BEDeviceVM, BluetoothLEDevice cannot be null.");
            }
            if (deviceInfo == null)
            {
                throw new ArgumentNullException("In BEDeviceVM, DeviceInformation cannot be null.");
            }

            // Initialize variables
            _device     = device;
            _deviceInfo = deviceInfo;
            if (_device.ConnectionStatus == BluetoothConnectionStatus.Connected)
            {
                Connected = true;
            }

            foreach (GattDeviceService service in _device.GattServices)
            {
                BEServiceModel serviceM = new BEServiceModel();
                serviceM.Initialize(service, this);
                ServiceModels.Add(serviceM);
            }

            // Register event handlers
            _device.ConnectionStatusChanged += OnConnectionStatusChanged;
            _device.NameChanged             += OnNameChanged;
            _device.GattServicesChanged     += OnGattervicesChanged;

            // Register for notifications from the device, on a separate thread
            //
            // NOTE:
            // This has the effect of telling the OS that we're interested in
            // these devices, and for it to automatically connect to them when
            // they are advertising.
            Utilities.RunFuncAsTask(RegisterNotificationsAsync);
        }
        /// <summary>
        /// Performs the bare minimum initialization of this class.
        /// </summary>
        /// <param name="serviceM"></param>
        /// <param name="characteristic"></param>
        public void Initialize(BEServiceModel serviceM, GattCharacteristic characteristic)
        {
            if (serviceM == null)
            {
                throw new ArgumentNullException("In BECharacteristicVM, BEServiceModel cannot be null.");
            }

            ServiceM = serviceM;

            if (characteristic == null)
            {
                throw new ArgumentNullException("In BECharacteristicVM, GattCharacteristic cannot be null.");
            }

            _characteristic     = characteristic;
            CharacteristicValue = CHARACTERISTIC_VALUE_DEFAULT_STRING;
            GetDictionaryAndUpdateProperties();

            Writable |= ((_characteristic.CharacteristicProperties & GattCharacteristicProperties.WriteWithoutResponse) != 0);
            Writable |= ((_characteristic.CharacteristicProperties & GattCharacteristicProperties.Write) != 0);

            ToastInit();
        }