Re: Leopard & Bluetooth RFCOMM channels
Re: Leopard & Bluetooth RFCOMM channels
- Subject: Re: Leopard & Bluetooth RFCOMM channels
- From: Ralf Menssen <email@hidden>
- Date: Thu, 31 Jan 2008 12:00:43 +0100
- Thread-topic: Leopard & Bluetooth RFCOMM channels
Looks like you do not really know which channel to open, because your
iteration through the service directory simply returns the first channel
which is not necessarily the right one. The channels are defined in
"BluetoothAssignedNumbers.h".
You can ask for a certain channel ID e.g. for a serial port like this:
BluetoothRFCOMMChannelID getSerialPortChannel (IOBluetoothDevice *inDevice)
{
IOBluetoothSDPServiceRecord *dialupServiceRecord;
BluetoothRFCOMMChannelID channel = 255;
IOBluetoothSDPUUID *ourUUID = [IOBluetoothSDPUUID
uuid16:(UInt16)kBluetoothSDPUUID16ServiceClassSerialPort];
dialupServiceRecord = [ inDevice getServiceRecordForUUID:ourUUID];
if (dialupServiceRecord)
{
IOReturn status = [dialupServiceRecord getRFCOMMChannelID:&channel];
if (status == noErr)
return channel;
}
return 255;
}
You need to know the UUID of the service you want to connect to. If it is a
predefined service like serial port, you find it in "SDPServiceClasses"
otherwise you must create a SDPServiceClasses yourself.
On 31.01.2008 11:21 Uhr, "Janusz Bossy" <email@hidden> wrote:
> On 1/31/08, Joseph Kelly <email@hidden> wrote:
>> Post the code that you're using to open the channel to the list and
>> maybe somebody can spot something.
>
> Here it goes:
>
> -(void)awakeFromNib
> {
> isConnected = false;
> [IOBluetoothDevice
> registerForConnectNotifications:self selector:@selector(newConnection:fromDevi
> ce:)];
> }
>
> - (IBAction)click: (id)sender
> {
> NSArray *devices = [IOBluetoothDevice pairedDevices];
> IOBluetoothDevice* dev = [devices objectAtIndex:0];
> [dev openConnection];
> }
>
> -(void)newConnection:(IOBluetoothUserNotification*)notification
> fromDevice:(IOBluetoothDevice*)device
> {
> NSLog(@"New connection from %@", [device getName]);
>
> IOReturn ret;
> NSArray* services = [device getServices];
>
> BluetoothRFCOMMChannelID rfcommChannelID;
>
> for (IOBluetoothSDPServiceRecord* service in services) {
> NSLog(@"Service: %@", [service getServiceName]);
> ret = [service getRFCOMMChannelID:&rfcommChannelID];
> if (ret == kIOReturnSuccess) {
> NSLog(@"ChannelID FOUND");
> break;
> }
> }
>
> [device openRFCOMMChannelAsync:&channel withChannelID:rfcommChannelID
> delegate:self];
> }
>
> This is just a cut from the source code that seems adequate to my
> question. Console output for this code is:
>
> 2008-01-31 11:16:24.600 BluetoothGPS[1059:10b] New connection from BT GPS V10
> 2008-01-31 11:16:24.601 BluetoothGPS[1059:10b] Service: Spp
> 2008-01-31 11:16:24.603 BluetoothGPS[1059:10b] ChannelID FOUND
>
> Ofcourse the class implements also all the RFCOMM delegate methods
> which don't get called at all.
>
> - (void)rfcommChannelOpenComplete:(IOBluetoothRFCOMMChannel*)rfcommChannel
> status:(IOReturn)error;
> - (void)rfcommChannelData:(IOBluetoothRFCOMMChannel*)rfcommChannel
> data:(void *)dataPointer length:(size_t)dataLength;
> - (void)rfcommChannelClosed:(IOBluetoothRFCOMMChannel*)rfcommChannel;
> -
> (void)rfcommChannelControlSignalsChanged:(IOBluetoothRFCOMMChannel*)rfcommChan
> nel;
> -
>
(void)rfcommChannelFlowControlChanged:(IOBluetoothRFCOMMChannel*)rfcommChannel>
;
> - (void)rfcommChannelWriteComplete:(IOBluetoothRFCOMMChannel*)rfcommChannel
> refcon:(void*)refcon status:(IOReturn)error;
> -
> (void)rfcommChannelQueueSpaceAvailable:(IOBluetoothRFCOMMChannel*)rfcommChanne
> l;
Ralf
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden