Re: Still confuse about rfcomm send and receive.....
Hi, Personally, I changed the design to make a BTConnection = singleton, and =20 use asynchronous calls to send data. You should wait for a OK after each command to send the next one If you set your object as the delegate for the RFCOMMChannel, = your =20 (void)rfcommChannelData:(IOBluetoothRFCOMMChannel*)rfcommChanneldata:=20 (void *)dataPointer length:(size_t)dataLength; method will be called =20 with appropriate received data each time you get something from the =20 phone. The method I use is feeding an NSMutableArray with commands I = want to =20 use, and flush it everytime I receive a return code from the phone "OK" =20= or "ERROR" I can send you my BTConnection class, it is quite easy to use, = you =20 just have to setDevice: with an NSString representation of the phone =20 address and use senString: method for each string you want to use. Here =20= is an example : [[ BTConnection sharedConnection ] setDelegate: self ]; [[ BTConnection sharedConnection ] setDevice: [[ NSUserDefaults =20 standardUserDefaults ] objectForKey: @"deviceID" ]]; [[ BTConnection sharedConnection ] connect ]; -(void)btDeviceConnected:(id)sender { if ([[[ NSUserDefaults standardUserDefaults ] objectForKey: =20 @"callerID" ] boolValue ]) { [[BTConnection sharedConnection]sendString:@"AT*ECAM=3D1\r" ]; [[BTConnection sharedConnection]sendString:@"AT+CLIP=3D1\r" ]; } } Here is the method in my class the sends string to the phone. Notice =20 that it is important to take care of the channel MTU : - (void)_sendData:(void*)buffer length:(UInt32)length ; { if ( mRFCOMMChannel !=3D nil ) { UInt32 numBytesRemaining; IOReturn result; BluetoothRFCOMMMTU rfcommChannelMTU; numBytesRemaining =3D length; result =3D kIOReturnSuccess; // Get the RFCOMM Channel's MTU. Each write can only contain =20= up to the MTU size // number of bytes. rfcommChannelMTU =3D [mRFCOMMChannel getMTU]; // Loop through the data until we have no more to send. while ( ( result =3D=3D kIOReturnSuccess ) && ( = numBytesRemaining > =20 0 ) ) { // finds how many bytes I can send: UInt32 numBytesToSend =3D ( ( numBytesRemaining > =20 rfcommChannelMTU ) ? rfcommChannelMTU : numBytesRemaining ); // This method won't return until the buffer has been =20 passed to the Bluetooth hardware to be sent to the remote device. // Alternatively, the asynchronous version of this method =20= could be used which would queue up the buffer and return immediately. result =3D [mRFCOMMChannel writeSync:buffer =20 length:numBytesToSend]; // Updates the position in the buffer: numBytesRemaining -=3D numBytesToSend; buffer +=3D numBytesToSend; } } } Le 24 mai 04, =E0 16:46, Nathanael P a =E9crit :
Hi everyone..
I am a student of a college in Indonesia, and I am
currently doing a final task. I am a newbie in mac
programming. For my final task, I want to build a
bluetooth communication between my se t610 and my mac.
I have built a rfcomm sync connection, but I do not
how to receive the response from what I have sent. I
have asked to bluetooth developer mailing list, they
told me to set the callback from setdelegate: and use
this function:
(void)rfcommChannelData:(IOBluetoothRFCOMMChannel*)rfcommChannel
data:(void *)dataPointer length:(size_t)dataLength;
But I do not know how to use it both. Currently, this
is what i have done:
IOBluetoothDeviceSelectorController *deviceSelector;
NSArray *deviceArray;
deviceSelector =3D [IOBluetoothDeviceSelectorController
deviceSelector];
[deviceSelector runModal];
deviceArray =3D [deviceSelector getResults];
selectedDevice =3D [deviceArray objectAtIndex:0];
[selectedDevice openRFCOMMChannelSync:&mRFCOMMChannel
withChannelID:10 delegate:self];
[mRFCOMMChannel retain];
char *s1 =3D "at+cmgf=3D1\r"; =09
[mRFCOMMChannel writeSync:s1 length:strlen(s1)];
char *s2 =3D "at+cmgl=3D\"all\"\r";
[mRFCOMMChannel writeSync:s2 length:strlen(s2)];
These code is learned from the example that comes
along with project builder. I'd be so grateful if
anyone could explain me.
Thanks a lot,
Nathanael
=09
=09
__________________________________
Do you Yahoo!?
Yahoo! Domains =16 Claim yours for only $14.70/year
_______________________________________________
bluetooth-dev mailing list | bluetooth-dev@lists.apple.com
Help/Unsubscribe/Archives: =20
Do not post admin requests to the list. They will be ignored.
--=20 Yann Bizeul - yann at tynsoe.org http://projects.tynsoe.org/ [demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s] _______________________________________________ bluetooth-dev mailing list | bluetooth-dev@lists.apple.com Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/bluetooth-dev Do not post admin requests to the list. They will be ignored.
participants (1)
-
Yann Bizeul