I successfully open RFCOMM Channel to Lego EV3 brick with code:
IOBluetoothDevice *device = [IOBluetoothDevice deviceWithAddressString:@"xxxxxxxxxxxx"];
IOBluetoothRFCOMMChannel *rfCommChannel;
IOBluetoothSDPUUID *sppServiceUUID = [IOBluetoothSDPUUID uuid16:kBluetoothSDPUUID16ServiceClassSerialPort];
IOBluetoothSDPServiceRecord *sppServiceRecord = [device getServiceRecordForUUID:sppServiceUUID];
if ( sppServiceRecord == nil )
{
NSLog( @"Error - no spp service in selected device." );
}
UInt8 rfcommChannelID;
if ( [sppServiceRecord getRFCOMMChannelID:&rfcommChannelID] != kIOReturnSuccess )
{
NSLog( @"Error - no spp service in selected device." );
}
if ( ( [device openRFCOMMChannelAsync:&rfCommChannel withChannelID:rfcommChannelID delegate:d] != kIOReturnSuccess ) && ( rfCommChannel != nil ) )
{
NSLog( @"Error - open sequence failed." );
}
Now I wish to send direct command:
unsigned char play_tone[] = {0x0F,0x00,0x00,0x00,0x80,0x00,0x00,0x94,0x01,0x81,0x02,0x82,0xE8,0x03,0x82,0xE8,0x03};
over RFCOMM Channel using class IOBluetoothRFCOMMChannel method:
- (IOReturn)writeSync:(void *)data length:(UInt16)length
I tried to do send it using different ways but none of them worked. How should I do it properly?