none
Can't scan for BLE devices.

    Pertanyaan

  • This is my code to scan for nearby Bluetooth devices. However, I cannot scan for BLE devices. Can anybody help me with the coding to enable it to scan for BLE devices?

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using DarrenLee.Bluetooth;
    using InTheHand.Net.Bluetooth;
    using InTheHand.Net.Sockets;
    using InTheHand.Net.Ports;
    using System.Threading;
    
    namespace WindowsFormsApp1
    {
      public partial class Form1 : Form
      {
        List<string> items;
        public Form1()
        {
          items = new List<string>();
          InitializeComponent();
          txtStatus.Text = "Waiting....";
        }
    
      
        private void btnSearch_Click(object sender, EventArgs e)
        {
          startScan();
          txtStatus.Text = "Scanning...";
          
        }
    
        private void startScan()
        {
          listBox1.DataSource = null;
          listBox1.Items.Clear();
          items.Clear();
         
          Thread bluetoothScanThread = new Thread(new ThreadStart(scan));
          bluetoothScanThread.Start();
        }
    
        private void scan()
        {
          
          BluetoothClient client = new BluetoothClient();
          BluetoothDeviceInfo[] devices = client.DiscoverDevicesInRange();
    
          foreach (BluetoothDeviceInfo d in devices)
          {
            items.Add(d.DeviceName);
    
          }
          updateDeviceList();
          
        }
        
       private void updateDeviceList()
        {
          Func<int> del = delegate ()
          {
            listBox1.DataSource = items;
            return 0;
          };
          Invoke(del);
          
        }
    
       private void listBox1_DoubleClick(object sender, EventArgs e)
       {
    
       }
      }
    }
    
    
    
    


    15 Mei 2018 4:40

Semua Balasan

  • You're using several third-party libraries here.  I don't know which module you're actually using, but you'll need to check their documentation.  InTheHand certainly has a BluetoothLE scanner similar to their regular Bluetooth scanner.

    Microsoft also has BLE support built-in.  You don't really need the third-party libraries:

    https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BluetoothLE


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    15 Mei 2018 16:45
  • Hello yann123,

    Your question is more related to third party libraries, you need to repost a new thread to InTheHand forum for better support.

    https://archive.codeplex.com/?p=32feet

    If you have some grammar or code errors in .Net framework, please feel free to contact us. We will try our best to give you a solution.

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    16 Mei 2018 6:26