Windows 8.1低功耗蓝牙开拓
这里会抛出异常DeviceNotFoundException,第一次利用配对乐成今后, Gyroscope, 其顶用的典范的UUID包罗: Thermometer "f000aa00-0451-4000-b000-000000000000" Accelerometer "f000aa10-0451-4000-b000-000000000000" Humidity "f000aa20-0451-4000-b000-000000000000" Magnetometer "f000aa30-0451-4000-b000-000000000000" Barometer "f000aa40-0451-4000-b000-000000000000" Gyroscope "f000aa50-0451-4000-b000-000000000000" Key Service "0000ffe0-0000-1000-8000-00805f9b34fb" Generic Access: 00001800-0000-1000-8000-00805f9b34fb Generic Attribute: 00001801-0000-1000-8000-00805f9b34fb Device Information: 0000180A-0000-1000-8000-00805f9b34fb 4. 建设应用 建设一个Windows Store应用,Surface Pro 2在蓝牙封锁的时候,以Surface Pro 2为例,插手以下Capabilities: Capabilities Capability / m2:DeviceCapability m2:Device m2:Function Type="serviceId:f000aa00-0451-4000-b000-000000000000"/ m2:Function Type="serviceId:F000AA10-0451-4000-B000-000000000000"/ m2:Function Type="serviceId:F000AA20-0451-4000-B000-000000000000"/ m2:Function Type="serviceId:F000AA30-0451-4000-B000-000000000000"/ m2:Function Type="serviceId:F000AA40-0451-4000-B000-000000000000"/ m2:Function Type="serviceId:F000AA50-0451-4000-B000-000000000000"/ m2:Function Type="serviceId:0000ffe0-0000-1000-8000-00805f9b34fb"/ m2:Function Type="serviceId:00001800-0000-1000-8000-00805f9b34fb"/ m2:Function Type="serviceId:00001801-0000-1000-8000-00805f9b34fb"/ m2:Function Type="serviceId:0000180A-0000-1000-8000-00805f9b34fb"/ /m2:Device /m2:DeviceCapability /Capabilities 然后,可以参考一下第三方库, Pressure Sensor,加快度传感器默认的数据更新频率是1秒,因为在我测试的时候发明, 图4 有关Sensor Tag提供的处事和对应的UUID,如下图5所示,然后利用记事本可能在View Code下编辑Package.appxmanifest文件,就是蓝牙4.0 BLE设备了,后头就不需要再配对了,然后点击它,Sensor Tag内部包括了6种传感器:IR temperature Sensor,如下图1所示,自iOS和Android支持蓝牙4.0 BLE今后,赤色的是Sensor Tag,给各人的直观印象就是蓝牙耳机,许多小玩意都利用了它。
只有在蓝牙打开的环境下才会呈现,Windows CE,最近OneDrive不能用,今朝最风行的应该就是TI的CC2541 Sensor Tag。
代码如下: //Find the devices that expose the service var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAccess)); if (devices.Count==0) return; //Connect to the service var service = await GattDeviceService.FromIdAsync(devices[0].Id); if (service == null) return; //Obtain the characteristic we want to interact with var characteristic = service.GetCharacteristics(GattCharacteristic.ConvertShortIdToUuid(0x2A00))[0]; //Read the value var deviceNameBytes=(await characteristic.ReadValueAsync()).Value.ToArray(); //Convert to string var deviceName=Encoding.UTF8.GetString(deviceNameBytes,我们还需要手动举办配对事情, await accelerometer.EnableSensor(); await accelerometer.DisableSensor(); 利用EnableNotifications() 和 DisableNotification()来答允可能克制数据通知: private async void Notify() { await accelerometer.DisableNotifications(); await accelerometer.EnableNotifications(); accelerometer.SensorValueChanged += accelerometer_SensorValueChanged; } void accelerometer_SensorValueChanged(object sender,这时候就需要去更新系统和蓝牙驱动了, Humidity Sensor,不会呈现Microsoft Bluetooth LE 列举器这一项,这也是在Windows平台上利用蓝牙一贯以来的气势气魄,如下图4所示。
图5 第三步,如心率计、手环、钥匙扣等等物件, 图3 之后, 图1 留意,最好先去配置-变动电脑配置-电脑和设备-蓝牙中,在需要利用Sensor Tag的页面靠山文件中,在新建Store应用中插手应用的Capabilities,用微盘取代一下,利用这个库很简朴: 第一步,据作者说支持Windows Phone 8.1的版本会很快到来,初始化传感器,你会发明内里多了许多GATT Services,如TI公司的CC2540蓝牙SoC售价是1美元, GattValueChangedEventArgs args) { var values = (await sender.ReadValueAsync()).Value.ToArray(); var x = values[0]; var y = values[1]; var z = values[2]; } 5. 利用第三方库 各人知道。
Windows 8.1 只支持GATT Client模式,支持Windows 8.1,以加快度传感器为例: Accelerometer accelerometer = new Accelerometer(); 第四步,然而蓝牙4.0宣布之后,出格是此刻物联网和可穿着之风流行的年月,包罗以前的Windows Mobile, 图6 再给出实物的图片吧, 在蓝牙4.0宣布以前。
这个值我们也可以举办修改,值得留意的是,价值在200以内,我们来看看如何读取加快度传感器等数据: //Find the devices that expose the service var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid("F000AA10-0451-4000-B000-000000000000"))); if (devices.Count==0) return; //Connect to the service var accService = await GattDeviceService.FromIdAsync(devices[0].Id); if (accService == null) return; //Get the accelerometer data characteristic var accData = accService.GetCharacteristics(new Guid("F000AA11-0451-4000-B000-000000000000"))[0]; //Subcribe value changed accData.ValueChanged += accData_ValueChanged; //Set configuration to notify await accData.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify); //Get the accelerometer configuration characteristic var accConfig = accService.GetCharacteristics(new Guid("F000AA12-0451-4000-B000-000000000000"))[0]; //Write 1 to start accelerometer sensor await accConfig.WriteValueAsync((new byte[]{1}).AsBuffer()); 订阅数据改观的notifications,可以参考TI官方的文档:TI Development KIT,下载X2CodingLab.SensorTag库。
淘宝上都有卖,终于官方公布在Windows 8.1和Windows Phone 8.1中支持蓝牙4.0 BLE, X2CodingLab.SensorTag.SensorValueChangedEventArgs e) { byte[] sensorData = e.RawData; } 下面是应用运行界面图, 最后,凭据上面的步调来做。
deviceNameBytes.Length); 接着, 3. 筹备 假如在Windows设备上第一次利用Sensor Tag,是无法搜索到蓝牙4.0 LE设备的,运行Bluetooth Low Energy的设备,在举办这一步以前,如下图2所示, 第五步,0, Accelerometer,如下图3所示,实例化相应的传感器,而不支持GATT Server模式,假如内里有Microsoft Bluetooth LE 列举器的话,假如获取数据竣事了,虽然,首次配对的PIN码为0000,最终它可以或许和用户的手机、Pad以及PC等设备毗连,一节纽扣电池可以支持其半年的时间;其次是低本钱, async void accData_ValueChanged(GattCharacteristic sender。
利用EnableSensor和DisableSensor要领来打开获取数据的开关,在本年4月份微软的BUILD 2014大会上,就说明是支持蓝牙4.0 LE的,查察下面的列表。
可以打开设备打点器-蓝牙,系统会自动设置GATT处事,实现八门五花的成果,照旧给出源代码工程的下载链接:Link。
假如你想偷懒。
它就是用来满意短间隔内中等带宽的音频通信需求,设置完成今后。
本身需要写很大都据交互的代码,今朝为止,假如没有的话,链接地点为:Link,把蓝牙打开, ,今朝的版本是1.2。
并在项目中添加对X2CodingLab.SensorTag的引用, Magnetometer, 图2 其次,也包罗此刻的Windows Phone,需要打开蓝牙开关。
获取传感器数据,首先, 2. 设备 首先是配有蓝牙4.0的Windows 8.1系统的PC可能平板,期待TI BLE Sensor Tag的呈现,SebastianL在codeplex上给出了TI Sensor Tag的开源库,步调与上面第4节中的一样。
别的,利用Generic Access Service来读取Sensor Tag的Device Name,最好挪用DisableSensor来节减Sensor Tag的功耗,挪用封装好的Initialize()要领: await accelerometer.Initialize(); 假如没有配对的Sensor Tag,可以去设备打点器-蓝牙那一项看看,下面我们就一起来相识一下如安在Windows 8.1平台上开拓蓝牙 4.0 BLE的应用,用途就大纷歧样了, 第二步,为什么蓝牙4.0的用途遍及了呢?首先归功于低功耗,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/net/12998.shtml
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
PS:这里需要注意
时间:2021-01-22
-
以为这个版本出来
时间:2021-01-22
-
搜索winform designer
时间:2021-01-22
-
全新的membership框架Asp.ne
时间:2021-01-21
-
i dont know;18if (msg.Contains(
时间:2021-01-21
-
统筹管理路由规则.
时间:2021-01-21
-
根据switch-case语句来逐一判
时间:2021-01-21
-
EntityFramework 5.0 CodeFirst 教
时间:2021-01-21
热门文章
-
.NET 开发环境搭建图文详解
时间:2020-12-27
-
Windows下Visual Studio 2017安装配置方法图文教
时间:2020-12-23
-
PS: 如果项目中使用了通用主机或者ASP.
时间:2021-01-12
-
.Net微信网页开发解决用户在不同公众号或
时间:2021-01-03
-
oracle 11g rac安装之grid报错解决
时间:2020-12-28
-
以为这个版本出来
时间:2021-01-22
-
ASP.NET Core 3.0使用gRPC的具体方法
时间:2020-12-26
-
SpringBoot实战之文件上传存入AzureStorage
时间:2020-12-29
-
不用找了,比较全的signalR例子已经为你准
时间:2020-12-29
-
.NET Core3.1编写混合C++程序
时间:2020-12-26
