天天看點

c# 低功耗藍牙,C#中建立從筆記本電腦内置藍牙4.0流藍牙低功耗(BLE)外設

c# 低功耗藍牙,C#中建立從筆記本電腦内置藍牙4.0流藍牙低功耗(BLE)外設

I am trying to write a program that connects to a Bluetooth Low Energy device (BLE), and then read a characteristic either on updates, or on a given interval.

My Peripheral is a Texas instruments CC2540 BLE device.

My starting point was looking at the example program from TI, that has a heart rate monitor:

http://processors.wiki.ti.com/index.php/Category:HealthDemo

However, this uses the dongle, and I am tasked at using the internal bluetooth 4.0 modem (going to make it on android later on, but for now, I just use windows).

Now my problem is that the dongle creates a COM port, but the internal modem does not. I still managed to use the 32feet API to scan and succesfully find the CC2540. However, from here I do not know what to do. I've tried calling the connect() method, but it always fails to connect, either by timeout or stating that there is a dead network.

Any ideas why this happens? Am i supposed to do something else than calling my device.connect() ?

Code snippet:

BluetoothClient cli;

BluetoothDeviceInfo[] peers;

BluetoothDeviceInfo device;

BluetoothAddress adr;

//... skipping code that finds the device and assigns the address to it.

if (device.InstalledServices.Length != 0)

{

try

{

//MessageBox.Show("attempting to connect");

cli.Connect(device.DeviceAddress, device.InstalledServices[2]);

//tbDeviceInfo.AppendText("\n\nConnected " + device.Connected);

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

// i always get this exception.

}

}

解決方案

I do not want to mistake you , but 32feet currently does not support Bluetooth low energy. (As for Nov 2012).