Re: Problem with rfcommDataListener.
Re: Problem with rfcommDataListener.
- Subject: Re: Problem with rfcommDataListener.
- From: Geoffrey Schmit <email@hidden>
- Date: Fri, 26 May 2006 14:27:48 -0500
On 26/5/2006 at 8:58 PM +0530, (unknown sender) wrote:
> We're building a small application to read & write with Barcode Scanner
> which are Bluetooth enabled, and I'm writing a Carbon application in
> C++ using CW 9.3 to get and display data from the device. I've
> successfully established a connection but not sure that i am sending &
> receiving data back from device . We use LinkSys bluetooth adapter to
> communication with barcode device.
[...]
> //CFRunLoopRun(); // How should i put app in loop to read complete
> data if i send two commands.
> sendData((void *) l_pTrigger, l_iLength);
You are correct that you need to give the run loop time to run if you want to receive asynchronous Bluetooth events.
I'm sure there are many approaches. I run the run loop after I perform a Bluetooth operation for which I want to wait for a response. For example:
int returnValue = CFRunLoopRunInMode( kCFRunLoopDefaultMode, timeoutInSeconds, false );
The returnValue can be inspected to determine if the run loop stopped normally or due to the timeout.
In my event listener method, I stop the run loop once I receive the expected message:
CFRunLoopRef runLoopRef = CFRunLoopGetCurrent();
CFRunLoopStop( runLoopRef );
I'm not sure if this is significant, but I only use an event listener which I register when I invoke IOBluetoothDeviceOpenRFCOMMChannelAsync.
Another potential pitfall, although it's not an issue in your sample code, is that all calls into the Bluetooth frameworks must be done on the same thread.
geoff
--
Geoffrey Schmit
Principal Engineer
National Instruments
email@hidden
www.ni.com
_______________________________________________
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