コード例 #1
0
        private async Task <GattCharacteristic> AddNewCharacteristic(GattService gattService, GattCharacteristicDescription characteristic)
        {
            var gattCharacteristic1Properties = GattPropertiesFactory.CreateGattCharacteristic(characteristic);
            var gattCharacteristic            = gattService.AddCharacteristic(gattCharacteristic1Properties, characteristic.CharacteristicSource);
            await _ServerContext.Connection.RegisterObjectAsync(gattCharacteristic);

            return(gattCharacteristic);
        }
コード例 #2
0
        public void BeforeEach()
        {
            device = SimulatedDevice.Reset();

            service = CreateTestService();

            host = BluetoothHost.Initialize(new BluetoothHostConfiguration(deviceName), service);

            advertisement = new Advertisement(
                new Advertisement.DataFragment(SigAdvertisingDataType.CompleteListof128bitServiceClassUUIDs, service.UUID.Bytes)
                );
        }
コード例 #3
0
        internal void TestSetString(GattService service, TextCharacteristic textCharacteristic, string value)
        {
            // Write to store
            var entry = GetValueEntry(service.Index, textCharacteristic.Index);

            entry.Value = OS.Encode(value);

            // Call Handler
            EventSink.Fire(new BluetoothEvent
            {
                EventType           = BluetoothEventType.ValueWritten,
                ServiceIndex        = service.Index,
                CharacteristicIndex = textCharacteristic.Index,
            });
        }
コード例 #4
0
ファイル: loveToy.cs プロジェクト: XAYRGA/loveTalk
        public async Task <bool> connect()
        {
            Debug.WriteLine("Connecting to GATT");
            await btDevice.Gatt.ConnectAsync();

            for (int i = 0; i < rxCharacteristics.Length; i++)
            {
                var service = serviceUID[i];
                var rxChar  = rxCharacteristics[i];
                var txChar  = txCharacteristics[i];
                try
                {
                    Debug.WriteLine("Connecting to service");
                    btSevice = await btDevice.Gatt.GetPrimaryServiceAsync(BluetoothUuid.FromGuid(new Guid(service)));

                    if (btSevice == null)
                    {
                        continue; // skip iteration, it was bad.
                    }
                } catch { Debug.WriteLine("Failed to connect to toy");  continue; }
                try
                {
                    Debug.WriteLine("Getting TXRX");
                    btRxChr = (await btSevice.GetCharacteristicAsync(new Guid(rxChar)));
                    btTxChr = (await btSevice.GetCharacteristicAsync(new Guid(txChar)));
                    if (btRxChr == null || btTxChr == null)
                    {
                        continue; // skip iteration, not good.
                    }
                    Debug.WriteLine("Success, got TXRX");
                    break;
                }
                catch { Debug.WriteLine("Failed to connect to toy (characteristic)");  continue; }
            }
            if (btSevice == null || btRxChr == null || btTxChr == null)
            {
                Debug.WriteLine("Service or characteristic was null!");
                return(false);
            }
            var devInfo = sendCommand("DeviceType;").Result;

            Model = lookupToyName(devInfo[0]);
            Debug.WriteLine($"Toy type connected . . . {Model}");
            return(true);
        }
コード例 #5
0
        async Task Send(byte[] byteArray)
        {
#if disableBluetoothLights
#else
            await GetDevice();

            if (device == null)
            {
                return;
            }

            const string  STR_LightControlServiceId = "69400001-b5a3-f393-e0a9-e50e24dcca99";
            BluetoothUuid bluetoothUuid             = BluetoothUuid.FromGuid(new Guid(STR_LightControlServiceId));
            GattService   controlService            = await device.Gatt.GetPrimaryServiceAsync(BluetoothUuid.FromGuid(new Guid(STR_LightControlServiceId)));

            if (controlService != null)
            {
                const string       STR_CharacteristicID = "69400002-b5a3-f393-e0a9-e50e24dcca99";
                GattCharacteristic gattCharacteristic   = await controlService.GetCharacteristicAsync(BluetoothUuid.FromGuid(new Guid(STR_CharacteristicID)));

                await gattCharacteristic.WriteValueWithoutResponseAsync(byteArray);
            }
#endif
        }