locked
RfcommDeviceService object as null value using Bluetooth communication

    Question

  • Hi MSDN,

    I'm using bluetooth communication to print the label. I'm using Windows 8.1 app store application(Testing in Tablet).

    I'm getting RfcommDeviceService object as null value.

    I've also tried as suggest by Matt, but there is no luck in it.

    http://blogs.msdn.com/b/wsdevsol/archive/2014/11/10/why-doesn-t-the-windows-8-1-bluetooth-rfcomm-chat-sample-work.aspx?CommentPosted=true#commentmessage

    Please suggest a way forward.

    Here is my code :

    private static readonly Guid RfcommChatServiceUuid = Guid.Parse("00001101-0000-1000-8000-00805f9b34fb");
    private async void Button_Click(object sender, RoutedEventArgs e)
            {
                try
                {
    
                    DeviceInformationCollection obj = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(RfcommChatServiceUuid)));
    
                   RfcommDeviceService service = null;
    
                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
                    {
                        service = await RfcommDeviceService.FromIdAsync(obj[0].Id);                    
                    });
    
                    if (service == null)              <--- Always service object is null
                    {
                        MessageDialog d = new MessageDialog("*** Empty ***");
                        await d.ShowAsync();
                    }
                    else
                    {
    
                       var _socket = new StreamSocket();
    
                       await _socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName);
    
                       //Here code to print
    
                        _socket.Dispose();
                        MessageDialog d1 = new MessageDialog("*** Done ***");
                        await d1.ShowAsync();
                    }               
                }
                catch (Exception ex)
                {
                    MessageDialog d = new MessageDialog(ex.Message);
                    d.ShowAsync();               
                }
            }
    
    package.appmanifest :
     <Capabilities>
        <Capability Name="internetClientServer" />   
        <Capability Name="privateNetworkClientServer" />
        <DeviceCapability Name="proximity" />
        <m2:DeviceCapability Name="bluetooth.rfcomm">
          <m2:Device Id="any">
            <m2:Function Type="serviceId:00001101-0000-1000-8000-00805f9b34fb" />
            <m2:Function Type="name:serialPort" />
          </m2:Device>
        </m2:DeviceCapability>
      </Capabilities>

    ----

    Thanks,

    Nagarjuna Dilip

                       
    • Edited by B Dilip Thursday, April 16, 2015 7:18 AM Edited Title
    Monday, April 13, 2015 5:01 PM

Answers

  • Hi,

    After a lot of work around fond the solution. People who all are facing this issue. Please check the below mentioned checklist.

        1) Make sure Latest Bluetooth drivers are installed
        2) GetDeviceSelector(Windows.Devices.Bluetooth.Rfcomm.RfcommServiceId.serialPort) and remove the UUID from code and manifest
        3) When the app runs, are you prompted to allow the app to access the device?  If not, uninstall and re-deploy from scratch
        4) In Settings  app -> Privacy -> Other devices, do you see the printer and/or an app there with access set to Off? then set it to ON
        5) Please remove dispatcher code for the service objectas mentioned below

    From : await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher

    .RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { service = await RfcommDeviceService.FromIdAsync(obj[0].Id); }); To : service = await RfcommDeviceService.FromIdAsync(obj[0].Id);



    Nagarjuna Dilip


    • Edited by NagarjunaDilip Friday, April 17, 2015 12:32 PM Formatted
    • Marked as answer by B Dilip Friday, April 17, 2015 12:35 PM
    Friday, April 17, 2015 12:31 PM

All replies

  • Did you check if obj is not null?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, April 13, 2015 9:05 PM
    Moderator
  • Hi Matt,

    Always service object is returning null. I'm getting the alert message with ***Empty*** 

    obj[0].id has a value.

    \\?\BTHENUM#{00001101-0000-1000-8000-00805f9b34fb}_LOCALMFG&001d#6&2914267d&0&00037A6C5ADC_C00000000#{b142fc3e-fa4e-460b-8abc-072b628b3c70}

    But, it is failing to create RfcommDeviceService service object. It is returing null.

    service = await RfcommDeviceService.FromIdAsync(obj[0].Id);  

    Please suggest a way to forward.

    ------

    Thanks,

    Nagarjuna Dilip

    Tuesday, April 14, 2015 4:41 AM
  • Hi,

    Any suggestions please?

    ----

    Thanks,

    Nagarjuna Dilip

    Wednesday, April 15, 2015 5:18 AM
  • Hi,

    How to work with Microsoft technologies when Microsoft Team themselves unable to support on their own products?

    This is working fine in Windows Phone 8.1 but it is failing in Windows 8.1 RT (Testing in Tablet).

    I've also tried using with PeerFinder class, there is no luck in this too. I'm getting Access Denied Exception.

    Access to the device is denied because the application was not granted access

    Here is the Code:

    PeerFinder.Start();
    PeerFinder.AllowBluetooth = true;
    PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
    // Find All PeerAsync method is throwing Access Denied exception
    var pairedDevices = await PeerFinder.FindAllPeersAsync();

    How to solve this issue now?

    Please show some light on this?

    ----

    Thanks,

    Nagarjuna Dilip

    Thursday, April 16, 2015 7:17 AM
  • Hi,

    After a lot of work around fond the solution. People who all are facing this issue. Please check the below mentioned checklist.

        1) Make sure Latest Bluetooth drivers are installed
        2) GetDeviceSelector(Windows.Devices.Bluetooth.Rfcomm.RfcommServiceId.serialPort) and remove the UUID from code and manifest
        3) When the app runs, are you prompted to allow the app to access the device?  If not, uninstall and re-deploy from scratch
        4) In Settings  app -> Privacy -> Other devices, do you see the printer and/or an app there with access set to Off? then set it to ON
        5) Please remove dispatcher code for the service objectas mentioned below

    From : await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher

    .RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { service = await RfcommDeviceService.FromIdAsync(obj[0].Id); }); To : service = await RfcommDeviceService.FromIdAsync(obj[0].Id);



    Nagarjuna Dilip


    • Edited by NagarjunaDilip Friday, April 17, 2015 12:32 PM Formatted
    • Marked as answer by B Dilip Friday, April 17, 2015 12:35 PM
    Friday, April 17, 2015 12:31 PM