Apple の外部アクセサリ フレームワークを使用して、次の入力および出力 Bluetooth ストリームを開きました。
session = [[EASession alloc] initWithAccessory:acc forProtocol:protocol];
if (session){
[[session inputStream] setDelegate:self];
[[session inputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[[session inputStream] open];
[[session outputStream] setDelegate:self];
[[session outputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[[session outputStream] open];
}
私はこのように書いています:
uint8_t aByte[] = {0x02, 0x06, 0x04};
[[session outputStream] write:aByte maxLength:4];
NSLog(@"%d", aByte[2]);
私はそれから次のように読んでいます:
case NSStreamEventHasBytesAvailable:
NSLog(@"NSStreamEventHasBytesAvailable");
uint8_t readBuf[128];
memset(readBuf, 0, sizeof(readBuf));
NSInteger numberRead = [[session inputStream] read:readBuf maxLength:3];
if(numberRead < 0){
NSError *error = [[session inputStream] streamError];
NSLog(@"%@", [error localizedDescription]);
}
else if (numberRead > 0) {
NSLog(@"numberRead: %d", numberRead);
NSLog(@"readBuf: %s", readBuf);
}
else{
break;
}
break;
デバイス「AA4」から受信する必要があります。これは、最後のストリーム イベントで送信された 3 バイトが後に続く 2 つの英字を送信するためです。デバイスの LCD 画面は、2、4、および 6 を受信したことを報告しています。また、A、A、および 4 を送信したことを報告しています。しかし、"NSLog(@"readBuf: %s", readBuf); " 常に出力します:
AA + a upside question mark//(can't seem to copy and paste that symbol from xcode)
私が間違ったことについて何か考えがある人はいますか?
ありがとう!