如何在CoreBluetooth上同时将数据写入多个Bluetooth LE从属设备? [英] How to write data to multiple Bluetooth LE slaves simultaneously on CoreBluetooth?

查看:170
本文介绍了如何在CoreBluetooth上同时将数据写入多个Bluetooth LE从属设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的.我正在尝试在一个iOS应用程序上工作,在这里我可以与多个Bluetooth LE从设备交换数据.

I am new to this. I am trying to work on an iOS application where i can to exchange data to multiple Bluetooth LE slaves.

我能够连接并读取多个从站.但是问题是我只能(声音蜂鸣器)到其中一个(要连接的最新从站).

I am able to connect and read from the multiple slaves. But the problem is i can only write (sound buzzer) to only one of them (the latest slave to be connected).

我正在使用 http://processors.wiki.ti中提供的代码. .com/index.php/Category:IPhone4SBLEDemo

所有连接的设备如何发出蜂鸣声?

How is it possible to sound buzzer for all connected devices?

ViewController.m

ViewController.m

- (IBAction)TIBLEUISoundBuzzerButton:(id)sender {
[t soundBuzzer:0x02 p:[t activePeripheral]]; //Sound buzzer with 0x02 as data value

Keyfob.m

-(void) soundBuzzer:(Byte)buzVal p:(CBPeripheral *)p {
NSData *d = [[NSData alloc] initWithBytes:&buzVal length:TI_KEYFOB_PROXIMITY_ALERT_WRITE_LEN];
[self writeValue:TI_KEYFOB_PROXIMITY_ALERT_UUID characteristicUUID:TI_KEYFOB_PROXIMITY_ALERT_PROPERTY_UUID p:p data:d];}

推荐答案

我找到了自己问题的答案.通过使用didRetrieveConnectedPeripherals,我可以同时将数据写入所有连接的设备.希望这可以帮助正在寻找相同答案的任何人.谢谢!

I have found the answer to my own question. By making use of didRetrieveConnectedPeripherals, i can write data to all connected devices simultaneously. Hopefully this can help whoever is looking for the same answer. Thank you!

-(void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripherals {

for(CBPeripheral *peripheral in peripherals) {//(soundbuzzer) }}

这篇关于如何在CoreBluetooth上同时将数据写入多个Bluetooth LE从属设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆