title: How to Bind manually to a BlueTooth Low Energy Device in a WinForm using C#?
body: <p>This question is mostly answered by: <a href="https://stackoverflow.com/questions/35420940/windows-uwp-connect-to-ble-device-after-discovery/41413736#41413736">Windows UWP connect to BLE device after discovery</a></p>
  
  <p>I am writing a custom service and testing,for now, using a C#.NET WinForm on Windows 10 to connect to a Bluetooth Low Energy (BLE) device. I am using Framework 4.6.1. We are using a <a href="http://www.ti.com/tool/smartrf06ebk" rel="noreferrer">TI SmartRF06 Evaluation Board</a> with a <a href="http://www.ti.com/product/cc2650" rel="noreferrer">TI CC2650 BLE</a> daughter card. Another developer is handling the Firmware of the Board.</p>
  
  <p>Currently using methods similar to the reference answer <a href="https://stackoverflow.com/questions/35420940/windows-uwp-connect-to-ble-device-after-discovery/41413736#41413736">above</a> I am able to connect to an already bound BLE device. This device was manually bound and Windows did require me to enter a PIN. Since the device has no PIN simply entering "0" allowed the device to connect. Once connected, in this manner, I can get to all the GATT services and do what I need to do.  So I have no issues with finding and getting a hold of a Advertising BLE device.</p>
  
  <p>The issue is that how do I connect to BLE device that has not already been paired? I have gone through the net and found many examples of BLE code but nothing specific to showing how the pairing in code is done. Not sure I even need it to pair but Windows seems to only show my the GATT services on paired devices.</p>
  
  <p>When I do this with unpaired device:</p>
  
  <pre><code>private void BleWatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
  {       
      var dev = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress);
      // dev.DeviceInformation.Pairing.CanPair is true
      // dpr.Status is Failed
      DevicePairingResult dpr = await dev.DeviceInformation.Pairing.PairAsync(DevicePairingProtectionLevel.None);
      var service = await GattDeviceService.FromIdAsync(dev.DeviceInformation.Id);
  }
  </code></pre>
  
  <p>The result of dpr is always failed when device has not been manually paired. Which results in the <code>GattDeviceServices</code> being empty. But I am able to get the advertisement and the properties of the BLE device.</p>
  
  <p>There is also this type of method to connect but I can't figure out how to use it: </p>
  
  <pre><code>var prslt = await device.DeviceInformation.Pairing.Custom.PairAsync(DevicePairingKinds.ProvidePin, DevicePairingProtectionLevel.None,IDevicePairingSettings);
  </code></pre>
  
  <p><code>IdeviceParingSettings</code> is an Interface. Not sure what Class to use with it. I am thinking this is where I can set the PIN of "O" that I might need?</p>
  
  <p>Has anyone had any luck pairing to a BLE device in Windows using C# where the BLE device has no security. Basically it should be wide open.  I feel like I am missing something simple or this is simply not possible (which I have seen some posts claiming that is the case. Most of those were many years old).</p>
  
  <p>I did try the methods described in the mentioned post without any difference in result.</p>
  
  <p>Any help is appreciated. If you need more of the code please look at the link I provided at top as that is what I started with. I will be happy to provide all of my actual code if there is, perhaps, a sequence that I am doing out of place.</p>