繁体   English   中英

IOS:将命令值写入核心蓝牙外围设备以获取响应

[英]IOS:Write command values to corebluetooth peripheral device to get the response

开发corebluetooth应用程序并被吸引到与外围设备通信等方面的问题。我很困惑编写命令来观看以从中检索信息。请在下面找到我的代码

  int sendcommand[6];
  sendcommand[0]=0x01;
  sendcommand[1]=6;
  sendcommand[2]=0x70;
  sendcommand[3]=0x00;
  sendcommand[4]=crcData[0];// value is -100
  sendcommand[5]=crcData[1];// value is -31

  NSMutableArray *arr=[[NSMutableArray  alloc]initWithCapacity:6];
  for (int i = 0; i < 6; i++) {
    NSNumber *number = [NSNumber numberWithFloat:sendcommand[i]];
    [arr addObject:number];
   }
   NSLog(@"mutable arr is %@",arr);

  NSString *error1;
   NSData *dataarr = [NSPropertyListSerialization dataFromPropertyList:arr    
   format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error1];


CBMutableCharacteristic *testCharacteristic = [[CBMutableCharacteristic alloc]  
initWithType:characteristicUUID 
properties:CBCharacteristicPropertyRead|CBCharacteristicPropertyWrite value:dataarr 
 permissions:CBAttributePermissionsReadable|CBAttributePermissionsWriteable];
NSLog(@"Read or Write %@ ",testCharacteristic);

[peripheral writeValue:dataarr forCharacteristic:testCharacteristic 
type:CBCharacteristicWriteWithoutResponse];

我的问题是通过使用上述六个命令来创建一个打包程序,并将数据发送到外围设备,并作为响应,它通过更新values.am将控制台值返回给一些信息。

  2014-12-19 19:26:51.068 Bluetooth_iph[1267:180180]    

   didUpdateNotificationStateForCharacteristic
   2014-12-19 19:26:51.069 Bluetooth_iph[1267:180180] characteristic.UUID : 8881
   2014-12-19 19:26:51.069 Bluetooth_iph[1267:180180] characteristic.value : (null)
   2014-12-19 19:26:51.069 Bluetooth_iph[1267:180180]    
    didUpdateNotificationStateForCharacteristic
    2014-12-19 19:26:51.070 Bluetooth_iph[1267:180180] characteristic.UUID : 8882
    2014-12-19 19:26:51.070 Bluetooth_iph[1267:180180] characteristic.value : (null)

请帮助我为上述命令创建数据包,以获取蓝色外围设备的响应。

您不应该手动创建CBCharacteristics。 您应该在方法中使用CBCentralManager返回的值:

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error

您可以从以下位置访问特征:

service.characteristics

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM