read of Characteristic causes disconnect
I am implementing a central using on ios7 on an iPhone5s. I am able to scan for devices and can connect to the desired peripheral device. As part of the overall connection procedure, I also undertake the discovery procedure of service and characteristics. I have properties(obj-C) for the CBService - aService and CBCharacteristic aChar . As part of the didDiscoverServices , I store the service and as part of didDiscoverCharacteristicsForService and store the cache the characteristic which is has a property of 0x0A(Read/Write) - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error { CBUUID *svcUUID = [ CBUUID UUIDWithString:@"<SOME UUID>"]; for (CBService *service in peripheral.services) { NSLog(@"Service discovered - %@", service); if([service.UUID.data isEqualToData:svcUUID.data] ) { _aService = service; NSLog((@"Service found")); } } if(_aService) { dispatch_async(dispatch_get_main_queue(), ^{ [_targetDevice discoverCharacteristics:nil forService:t_aService]; }); } } - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error { CBUUID *charUUID = [ CBUUID UUIDWithString:@"<some UUID>"]; for( CBCharacteristic *cs in service.characteristics) { NSLog(@"Characteristics discovered - %@", cs); if([cs.UUID.data isEqualToData:charUUID.data] ) { _aChar = cs; NSLog(@"Characteristic %@ Found",cs); // This works btw [peripheral readValueForCharacteristic:_aChar]; break; } } } Now I have a button that i use to read the char . In the button handler, I use the following call to read the characteristic for the service . -(IBAction) buttonDown:(id)sender { // immediate disconnection after this ! [_aService readValueForCharacteristic:_aChar]; } I immediately see a disconnect. Any clues as to why this might me occurring? On the other hand, I observe that if I invoke this same request in the didDiscoverCharacteristicsForService then the calls succeeds and the data is available. _______________________________________________ Do not post admin requests to the list. They will be ignored. Bluetooth-dev mailing list (Bluetooth-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/bluetooth-dev/site_archiver%40lists.... This email sent to site_archiver@lists.apple.com
participants (1)
-
RAM KUMAR