コード例 #1
0
ファイル: MiniZService.cs プロジェクト: sengeiou/drme
        public async void FindAndConnect()
        {
//			Task.Factory.StartNew(new Action(async () =>
            {
                String sid = GattDeviceService.GetDeviceSelectorFromShortId(serviceId);

                var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromShortId(serviceId), new string[] { "System.Devices.ContainerId" });

                if (devices.Count > 0)
                {
                    InitializeService(devices[0]);
                }
            }
            //));
        }
コード例 #2
0
ファイル: BluetoothLECar.cs プロジェクト: sengeiou/drme
        public async Task <List <ICar> > FindAvailableCars()
        {
            List <ICar> cars = new List <ICar>();

            var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromShortId(serviceId), new string[] { "System.Devices.ContainerId" });

            foreach (var device in devices)
            {
                cars.Add(new BluetoothLECar(device));
            }

            var devicesLong = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(serviceUuid), new string[] { "System.Devices.ContainerId" });

            foreach (var device in devicesLong)
            {
                cars.Add(new BluetoothLECar(device));
            }

            return(cars);
        }
コード例 #3
0
 /// <summary>
 /// GATTサービス情報を取得します。
 /// </summary>
 /// <param name="serviceShortId">サービスID</param>
 /// <returns>GATTサービス情報</returns>
 public static IAsyncOperation <DeviceInformationCollection> FindGattServicesAsync(ushort serviceShortId)
 {
     return(DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromShortId(serviceShortId), new string[] { "System.Devices.ContainerId", "System.Devices.InterfaceClassGuid" }));
 }
コード例 #4
0
        public async Task <List <Device> > GetDevicesAsync()
        {
            var batteryServiceDeviceInfoCollection = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromShortId(0x180F), new string[] { "System.Devices.ContainerId" });

            var res = new List <Device>();

            foreach (var device in batteryServiceDeviceInfoCollection)
            {
                //Output("\nDevice id : " + device.Id + "  name " + device.Name);

                //    //foreach (var prop in device.Properties)
                //    //{
                //    //    Output(" " + prop.Key + " " + (prop.Value == null ? null : prop.Value.GetType() + " " + prop.Value));
                //    //}

                var deviceContainerId = "{" + device.Properties["System.Devices.ContainerId"] + "}";

                string macaddr = "";
                try
                {
                    macaddr = device.Id.Split('_')[1].Substring(0, 12);
                }
                catch
                {
                    Output("Unable to parse mac address for device " + device.Id);
                    continue;
                }

                Device d = new Device("BLE device " + device.Name, "bleproximity-" + macaddr, "", DateTime.Now, "HomeOS.Hub.Drivers.BLEProximity", false);
                //intialize the parameters for this device
                d.Details.DriverParams = new List <string>()
                {
                    macaddr
                };
                res.Add(d);
            }
            Output("BLE prox scout found " + res.Count + " paired devices with battery characteristics");
            return(res);
        }
コード例 #5
0
        private async void cbConnect_Click(object sender, RoutedEventArgs e)
        {
            var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromShortId(0x0EE0));

            if (devices.Count < 1)
            {
                await new MessageDialog("Could not locate any EEG devices in the vinicity").ShowAsync();
                return;
            }

            //By default connect to the first EEG service found
            eegService.Instance.service = await GattDeviceService.FromIdAsync(devices[0].Id);

            eegService.Instance.IsInitialised = true;
            var eegData = eegService.Instance.service.GetCharacteristics(new Guid("00000EE1-0000-1000-8000-00805f9b34fb"))[0];

            eegData.ValueChanged += eegData_ValueChanged;

            //devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromShortId(0x2A37));
            //batteryService.Instance.service = await GattDeviceService.FromIdAsync(devices[0].Id);
            //var batteryData = batteryService.Instance.service.GetCharacteristics(new Guid("00002a19-0000-1000-8000-00805f9b34fb"))[0];
            //batteryData.ValueChanged += batteryData_ValueChanged;
            //Start notifications
            await eegData.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);

            //var x = await batteryData.ReadClientCharacteristicConfigurationDescriptorAsync();

            //TimerElapsedHandler f = new TimerElapsedHandler(batchUpdate);
            //periodicTimer = ThreadPoolTimer.CreatePeriodicTimer(f, new TimeSpan(0, 0, 0, 0, 40000));



            //////////////////////
            //var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromShortId(0x1800));
            //var service = await GattDeviceService.FromIdAsync(devices[0].Id);

            //var gapData = service.GetCharacteristics(new Guid("00002A04-0000-1000-8000-00805f9b34fb"))[0];
            //var raw = await gapData.ReadValueAsync();

            //byte[] conParas = new byte[raw.Value.Length];
            //DataReader.FromBuffer(raw.Value).ReadBytes(conParas);
            ////I can breakpoint and verify that the read works fine

            ////var tmp = conParas[0];
            ////conParas[0] = conParas[1];
            ////conParas[1] = tmp;
            ////tmp = conParas[2];
            ////conParas[2] =conParas[3]; conParas[3] = tmp;
            ////tmp = conParas[4];
            ////conParas[5] = conParas[4];
            ////conParas[5] = tmp;
            ////tmp = conParas[6];
            ////conParas[6] = conParas[7];
            ////conParas[7] = tmp;
            //DataWriter writer = new DataWriter();
            ////Endianess of reciever data inverted
            //writer.WriteInt16((Int16)SwapUInt16(100));
            //writer.WriteInt16((Int16)SwapUInt16(100));
            //writer.WriteInt16((Int16)SwapUInt16(100));
            //writer.WriteInt16((Int16)SwapUInt16(100));
            //var z = conParas.AsBuffer();
            //var status = await gapData.WriteValueAsync(conParas.AsBuffer());
        }