A
A
AndreySh2013-11-13 15:34:03
Bluetooth
AndreySh, 2013-11-13 15:34:03

Can't connect and receive data from Bluetooth low energy device under Windows 8.

Hello!

I'm trying to get to grips with Bluetooth 4 Low Energy and writing a desktop program for a Windows 8 tablet. An external Bluetooth device based on BLE112 from Bluegiga. Project on RAD Studio XE4 C++.

What am I doing:

1. Using standard Windows tools, I find the device and connect it to Windows. It appears in the Device Manager.

2. Using a combination of SetupDiGetClassDevs , SetupDiEnumDeviceInterfaces and SetupDiGetDeviceInterfaceDetail I get the path to the device interface.

//BTDeviceInterfaceGUID я посмотрел через GUID Explorer.

  hDI = SetupDiGetClassDevs(&BTDeviceInterfaceGUID, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
  SetupDiGetDeviceInterfaceDetail(hDI, &sp_Device_Interface_Data, pInterfaceDetailData, size, &size, &sp_Devinfo_Data) 

As a result, in pInterfaceDetailData->DevicePath I get the Device Interface Path, which I use in CreateFile .

hComm = CreateFile(pInterfaceDetailData->DevicePath, GENERIC_WRITE | GENERIC_READ,NULL,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);

As a result, hComm is the HANDLE of my Bluetooth device. CreateFile normally fulfills, without errors.

3. Next, using the new Bluetooth Low Energy WinAPI , I try to get the data.

With the help of BluetoothGATTGetServices and BluetoothGATTGetCharacteristic I get the corresponding structures.

hr = BluetoothGATTGetServices(hBLEDevice, serviceBufferCount, pService,numServices,BLUETOOTH_GATT_FLAG_NONE); We get what services the device supports.

hr = BluetoothGATTGetCharacteristics(hBLEDevice, pService,charBufferCount, pCharacteristic, numCharacteristics, BLUETOOTH_GATT_FLAG_NONE); We get what characteristics in this service.

4. And when I try to read the value of any characteristic, I get ERROR_ACCESS_DENIED . hr = BluetoothGATTGetCharacteristicValue(hBLEDevice, pCharacteristic,(ULONG)charValueDataSize, pCharValueBuffer, NULL, BLUETOOTH_GATT_FLAG_NONE);

I also noticed that, in general, it doesn’t matter whether the BLE device itself works or not. The behavior of the program does not change. That is, in both cases, I can read the "structure" of the services-characteristics of the device, but I cannot read the value of these characteristics. CreateFile in both cases works without errors and returns HANDLE of the device.

And yet, I installed the LightBlue program on my IPhone 4S, it can work with bluetooth 4 LE. And so with its help I normally receive data from this device. That is, the problem is in the program for Windows, and not in the piece of iron.

Maybe someone faced a similar problem? Tell me which way to dig...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AndreySh, 2013-11-15
@AndreySh

Hooray, problem solved! The MSDN forum finally got the answer. Maybe someone will come in handy.

To provide isolation between services, windows requires that when reading or writing to the device, that the application opens a handle to the service instance itself. This can be accomplished by altering BTDeviceInterfaceGUID in your example to be equal to the service UUID (extended to 128 bit using the standard SIG extension if the service uses a 16 bit UUID) of the service you intended to use.

To extend the 16-bit service UUID to 128, we take Bluetooth_Base_UUID {0000xxxx-0000-1000-8000-00805F9B34FB} and insert our 16-bit one in place of xxxx.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question