locked
while bluetooth Connecting occur error RRS feed

  • Question

  • The code I'm using is:"Search for devices"

    var devices = await DeviceInformation.FindAllAsync( RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

    var devices = await DeviceInformation.FindAllAsync( RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

    Connecting to the device

    var serviceInfo = (DeviceInformation)DevicesListBox.SelectedItem; try { rfcommService = await RfcommDeviceService.FromIdAsync(serviceInfo.Id); if (rfcommService != null) { socket = new StreamSocket(); await socket.ConnectAsync( rfcommService.ConnectionHostName, rfcommService.ConnectionServiceName)

    while am connecting the device am getting error in serviceinfo.id get object reference not to insatnce of the object shown.

    can you tell me anyone.how to rectify this error.


    Alert

    Friday, October 10, 2014 8:55 AM

Answers

  • Two issues:

    1) What kind of device are you trying to connect to? Is it being shown in the list?

    2) Be sure that you run this line of code on the UI thread:

    rfcommService = await RfcommDeviceService.FromIdAsync(serviceInfo.Id);

    Use Dispatcher.RunASync if necessary.


    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.

    Friday, October 10, 2014 7:09 PM