Пример #1
0
        /// <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(string.Format(
                                                    "{0}In BECharacteristicVM, BEServiceModel cannot be null.", "ARG0"));
            }

            ServiceM = serviceM;

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

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

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

            //  ToastInit();
        }
Пример #2
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(string.Format("Dev{0}ice cannot be null.", "ARG0"));
            }
            if (deviceInfo == null)
            {
                throw new ArgumentNullException(string.Format("{0} DeviceInformation cannot be null.", "In BEDeviceVM,"));
            }

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

            foreach (var service in _device.GattServices)
            {
                var 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);
        }