1

Currently trying to get a Bluteooth sample working.

I'm using this sample as reference - http://developer.apple.com/library/mac/#samplecode/HeartRateMonitor/Listings/HeartRateMonitor_HeartRateMonitorAppDelegate_m.html#//apple_ref/doc/uid/DTS40011322-HeartRateMonitor_HeartRateMonitorAppDelegate_m-DontLinkElementID_4

Bluetooth is enabled on my device.

I've tried using code like:

_manager = new CBCentralManager ();
_manager.DiscoveredPeripheral += HandleDiscoveredPeripheral;
_manager.ConnectedPeripheral += HandleConnectedPeripheral;
_manager.DisconnectedPeripheral += HandleDisconnectedPeripheral;

and I've tried writing my own delegate inheriting from CBCentralManagerDelegate

but when I call StartScan

    void StartScan ()
    {
        var spp = Guid.Parse("00001101-0000-1000-8000-00805f9b34fb");
        _manager.ScanForPeripherals(new [] { spp }, null);
    }

then I see an error:

bluetooth1[1210:907] CoreBluetooth[WARNING] <CBConcreteCentralManager: 0x9beea0> is not powered on

Looking around for this error I've found just a couple of hits:

But neither of these is particularly helpful...

I tried delaying start until the state changed:

    void HandleUpdatedState (object sender, EventArgs e)
    {
        // more to do here....
        Console.WriteLine("State updated " + e.ToString());

        switch (_manager.State) {
        case CBCentralManagerState.PoweredOn:
            _manager.DiscoveredPeripheral += HandleDiscoveredPeripheral;
            _manager.ConnectedPeripheral += HandleConnectedPeripheral;
            _manager.DisconnectedPeripheral += HandleDisconnectedPeripheral;
            StartScan();
            break;          
        case CBCentralManagerState.Unauthorized:
            break;          
        }
    }
  • but this never seems to be called.

I've also tried to run the xcode sample, but the force is not with me today...

Anyone got any ideas what CBConcreteCentralManager: 0x9beea0 is not powered on means and how to solve it here?

Community
  • 1
  • 1
Stuart
  • 66,722
  • 7
  • 114
  • 165

1 Answers1

4

Answer: To get past this in MonoTouch I had to use a different constructor:

CBCentralManager(_delegate, MonoTouch.CoreFoundation.DispatchQueue.CurrentQueue) 

When I switched to that it started working...

Stuart
  • 66,722
  • 7
  • 114
  • 165
  • 1
    You're right. The binding generator creates default constructor (unless it's told not to) and Apple documentation about that can be `init`ed is lacking quite a bit. I found out about CoreBluetooth extra ctors this week (since they crash at dispose time using OSX) and they will be marked as `[Obsolete]` in the next MT releases. – poupou Dec 01 '12 at 15:23
  • Thanks :) My other findings are on http://forums.xamarin.com/discussion/476/corebluetooth-spp-sample#latest - feels like an issue with .Net Guid to CBUUID translation. I'm still failing to get connection to my sphero working right now - not sure why as the Sphero docs are also a bit lacking! If you want to discuss, then see you on that forum thread (StackOverflow comments not as good for chat!) – Stuart Dec 01 '12 at 16:54
  • I think the problem is that .Net cannot distinguish between a Guid null array and CBUUID null array, you have to specify the type. I just used "new CBUUID[] {}" and it works.. – Rogier Dec 16 '12 at 23:04