在 XCode 中创建基于终端的蓝牙监视器?
我想创建一个连接到蓝牙设备并输出蓝牙设备发送的任何命令的终端应用程序。到目前为止,我能够扫描并输出可用设备的列表。
任何方向将不胜感激 - 这可能吗?我现在应该看什么?我尝试使用 BluetoothDeviceAddress 和 IOBluetoothL2CAPChannelGetDevice 但尚未取得任何成功。
到目前为止,这是我的代码:
#include <Foundation/Foundation.h>
#include <Cocoa/Cocoa.h>
#include <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>
#include <IOBluetoothUI/IOBluetoothUI.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"start bluetooth search");
IOBluetoothDeviceInquiry *d = [[IOBluetoothDeviceInquiry new] init];
[d setInquiryLength: 5];
[d setUpdateNewDeviceNames: TRUE];
[d start];
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 7]];
[d stop];
NSArray *deviceList = [d foundDevices];
NSLog(@"found %d devices", [deviceList count]);
for(int i=0;i < [deviceList count]; i++) {
NSScanner *theScanner = [NSScanner scannerWithString:[NSString stringWithFormat:@"%@", [deviceList objectAtIndex:i]]];
NSString *tagDeviceName = @"mName - ";
NSString *tagEndLine = @"\n";
NSString *currentDeviceName;
// extract the mName from the current array value
while ([theScanner isAtEnd] == NO) {
[theScanner scanUpToString:tagDeviceName intoString:NULL];
[theScanner scanString:tagDeviceName intoString:NULL];
[theScanner scanUpToString:tagEndLine intoString:¤tDeviceName];
} // end [theScanner isAtEnd]
NSLog(@"device name: %@", currentDeviceName);
}
[pool release];
return 0;
}
I want to create a Terminal application that connects to a Bluetooth Device and outputs any commands that are sent out by the bluetooth device. So far, I am able to scan and output a list of available devices.
Any direction would be greatly appreciated - is this even possible? What should I be looking at now? I tried to use BluetoothDeviceAddress and IOBluetoothL2CAPChannelGetDevice but haven't had any success yet.
Here is my code so far:
#include <Foundation/Foundation.h>
#include <Cocoa/Cocoa.h>
#include <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>
#include <IOBluetoothUI/IOBluetoothUI.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"start bluetooth search");
IOBluetoothDeviceInquiry *d = [[IOBluetoothDeviceInquiry new] init];
[d setInquiryLength: 5];
[d setUpdateNewDeviceNames: TRUE];
[d start];
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 7]];
[d stop];
NSArray *deviceList = [d foundDevices];
NSLog(@"found %d devices", [deviceList count]);
for(int i=0;i < [deviceList count]; i++) {
NSScanner *theScanner = [NSScanner scannerWithString:[NSString stringWithFormat:@"%@", [deviceList objectAtIndex:i]]];
NSString *tagDeviceName = @"mName - ";
NSString *tagEndLine = @"\n";
NSString *currentDeviceName;
// extract the mName from the current array value
while ([theScanner isAtEnd] == NO) {
[theScanner scanUpToString:tagDeviceName intoString:NULL];
[theScanner scanString:tagDeviceName intoString:NULL];
[theScanner scanUpToString:tagEndLine intoString:¤tDeviceName];
} // end [theScanner isAtEnd]
NSLog(@"device name: %@", currentDeviceName);
}
[pool release];
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下一步将是:
1.通过SDP发现设备上可用的服务
2. 连接服务并读取数据。
您可以使用 SPP 配置文件进行数据发送/接收 - 假设您要连接的设备正在使用此配置文件发送数据。
The next step will be :
1. Discover the services available on the device via SDP
2. Connect to the service and read the data.
You can use the SPP profile for data send / receive - assuming that the device you are connecting to is using this profile to send the data.