none
Bluetooth BLE BluetoothGATTRegisterEvent RRS feed

  • Question

  • HI,

    After calling BluetoothGATTRegisterEvent with all the correct arguments (at least i think so) i get and 0x2147942432 error. I looked up this error and it is: 

    The process cannot access the file because it is being used by another process. 

    That doesnt make any sense. Any ideas on this one ?

    Tuesday, May 20, 2014 5:01 PM

Answers

  • If you change the share mode in your create file call to be FILE_SHARE_READ | FILE_SHARE_WRITE, does it behave any differently?

    Thursday, May 22, 2014 9:39 PM

All replies

  • Can you post the relevant portion of your code? There are a few reasons this could occur, but impossible to get an idea of what's happening without context

    Thanks,

     Mike

    For searching purposes:

    0n2147942432 is the equivalent to

    0: kd> !error 0n2147942432
    Error code: (HRESULT) 0x80070020 (2147942432) - The process cannot access the file because it is being used by another process.

    Tuesday, May 20, 2014 6:59 PM
  • Thank you for replying. 

    I didn't post any specifics because I am quite sure the code is fine. After Windows 8.1 updated to: windows 8.1 update 1, I started getting this sort of errors. First it was access denied which after a new update became the one posted above. Before that the code was working as expected.

    I will go through the steps of obtaining the right arguments for the BluetoothGATTRegisterEventFunction.

    1. I find my service path by searching for ClassDevices by its UUID

    2. I open the path with the following line:

    HANDLE h = CreateFile(Path, GENERIC_READ | GENERIC_WRITE, NULL, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

    And save it

    3. I find all of the services with the following handle (should be only 1)

    4. I find all of the characteristics of the previously found service.

    5. I select the characteristics that I am interested by short UUID. 

    6. The comes the tricky bit. I find all of the descriptors of my characteristic and only select the one with the short UUID 0x02902.  On that descriptor I do:

    value.DescriptorType = ClientCharacteristicConfiguration;
    value.ClientCharacteristicConfiguration.IsSubscribeToNotification = TRUE;
    
    result = BluetoothGATTSetDescriptorValue(hService, &descriptor, &value, BLUETOOTH_GATT_FLAG_NONE);

    Which effectivly enables notifications so the device starts sending data.

    7. To catch that data I do BluetoothGATTRegisterEvent as follows:

    BLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION registration = { 0 };
    BLUETOOTH_GATT_EVENT_HANDLE eHandle;
    registration.NumCharacteristics = 1;
    memcpy(&registration.Characteristics[0], &characteristics, sizeof(BTH_LE_GATT_CHARACTERISTIC));
    
    // lets subscribe to event
    HRESULT result = BluetoothGATTRegisterEvent(hService,
    	CharacteristicValueChangedEvent,
    	&registration,
    	(PFNBLUETOOTH_GATT_EVENT_CALLBACK)EventCallback,
    	NULL,
    	&eHandle, 
    	BLUETOOTH_GATT_FLAG_NONE);

    And the result gives me the error posted above.

    I hope I gave enough information. Any help would be appreciated. 


    • Edited by Zreli Eskim Tuesday, May 20, 2014 8:55 PM typo
    Tuesday, May 20, 2014 8:54 PM
  • I have a request out to some of our BT folks for some information or to reply directly. 

    In the meantime, I've looked through the changes and don't see what would obviously cause the change here.  The Access Denied would show up from running without admin rights, does it make any difference if you're running with Admin rights?

    Wednesday, May 21, 2014 10:17 PM
  • I've got the same problem.

    I can confirm that admin rights make no difference.

    Thursday, May 22, 2014 3:59 AM
  • Hi,

    Thank you for looking into this. I just tried my code on a Windows 8 machine and it works without any errors. Is there any change log posted for BLE API ? I was searching for it once but couldn't find any infromation about the changes.

    Thursday, May 22, 2014 5:27 AM
  • If you change the share mode in your create file call to be FILE_SHARE_READ | FILE_SHARE_WRITE, does it behave any differently?

    Thursday, May 22, 2014 9:39 PM
  • I changed the share mode to FILE_SHARE_READ|FILE_SHARE_WRITE. The call to BluetoothGATTRegisterEvent now works.

    It would be great if the documentation for the function could be updated to suggest the share mode.

    Many thanks.

    Friday, May 23, 2014 12:00 AM
  • Thank you very much for this solution.

    This should really be documented somewhere. It is impossible to know this.

    Friday, May 23, 2014 5:50 AM