连接到设备后,BLE中多次写入命令 [英] Multiple times of Write command in BLE after connecting to device
本文介绍了连接到设备后,BLE中多次写入命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,目前我在BLE工作。
我已连接到设备。读命令和写命令工作正常。
我的问题是什么...
连接后我可以一次又一次地发送写命令到了设备。
Hi all, currently i'm working in BLE.
I have connected to the device. Read command and write command works fine.
What My question is...
Can I send the write command again and again after connected to the device.
推荐答案
啊最后我得到了解决方案。感谢所有帮助过我的人。这是解决方案。现在我可以把这个写mtd称为任何地方&任何次数。
Ah finally i got the solution. Thanks for everyone who helped me. Here is the solution. Now i can call this write mtd anywhere & any number of times.
CBCharacteristic *Writechar = nil;
CBPeripheral *writePeri = nil;
-(void)peripheral:(CBPeripheral *)peripheral
didDiscoverCharacteristicsForService:(CBService *)service
error:(NSError *)error
{
for (CBCharacteristic *characteristic in service.characteristics)
{
[peripheral readValueForCharacteristic:characteristic];
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"ABCD"]])
{
Writechar = (CBCharacteristic*)characteristic.UUID;
writePeri = (CBPeripheral*)peripheral;
[writePeri readValueForCharacteristic:characteristic];
[writePeri setNotifyValue:YES forCharacteristic:characteristic];
}
}
}
- (void) write
{
for(CBService *service in writePeri.services)
{
for (CBCharacteristic *characteristic in service.characteristics) {
[writePeri readValueForCharacteristic:characteristic];
[writePeri setNotifyValue:YES forCharacteristic:characteristic];
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"ABCD"]])
{
[writePeri writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
}
}
}
}
这篇关于连接到设备后,BLE中多次写入命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文