gpt4 book ai didi

IOS:Write command values to corebluetooth peripheral device 获取响应

转载 作者:行者123 更新时间:2023-11-29 02:25:40 26 4
gpt4 key购买 nike

开发 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];

我的问题是通过使用以上六个命令创建一个打包器并将数据发送到外围设备并作为响应它通过更新值返回一些信息。我将控制台值获取为

  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

关于IOS:Write command values to corebluetooth peripheral device 获取响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27567684/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com