10 Replies Latest reply on Apr 13, 2016 9:46 AM by amartinez

    C# interaction with BCM20732S  (on Win8.1 via BLEgatt )

    amartinez

      I'd liked to build some c# charting utilities for a pressure sensor on the BCM20732S and am using this example code at Bluetooth Generic Attribute Profile - Heart Rate Service in C#, C++, JavaScript for Visual Studio 2013 to do so.

       

      I'm hitting a brick wall getting at the pressure data, trying the generic service on MS's BLEGATT.

       

      I am able to connect and get battery data (there is a battery service)

       

      Am i barking up the wrong tree?

       

      (the device is sending data to some modified hello_sensor code in c++, so is working)

       

      Is there a fundamental proprietary barrier to using c# ?

        • 1. Re: C# interaction with BCM20732S  (on Win8.1 via BLEgatt )
          MichaelF_56
          I think you will find that this thread provides some guidance: Re: Starting a C# BLE project
          As noted in the thread, BTWLEAPI is a C DLL with a standard WINAPI interface, and the forum isn't the appropriate place for the discussion regarding how to interface C DLLs from C#.  This may be a better topic to pursue via MSDN.

           

          • 2. Re: C# interaction with BCM20732S  (on Win8.1 via BLEgatt )
            amartinez

            Thanks -  I saw that thread and guess i needed more help . This bit is relevant " On Windows 8/8.1 this DLL is not required because all required functionality is included in standard Microsoft DLLs."  but I get stuck on accessing the relevant BLEGATT service for my smart device. I was hoping someone might show the way with an example of a modified MS example .

            • 3. Re: C# interaction with BCM20732S  (on Win8.1 via BLEgatt )
              MichaelF_56

              Ok.  Let's see if some of the other developers/users can provide some feedback on the subject.

               

              prayook sdavid471

              • 4. Re: C# interaction with BCM20732S  (on Win8.1 via BLEgatt )
                prayook

                I used to build WPF application that target Windows8.1 and talk to WICED Sense via GATT.

                 

                You might need to take time to understand this part in the example code in order to modify it in the way you want.

                const UINT8 gatt_database[]={ ... };

                If you don't understand, Bluetooth Core Specification document may help you

                Adopted Specifications | Bluetooth Technology Website

                 

                Then, on the windows side..

                First, you try to get paired devices that provide that specific service.

                 

                DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid(STRING_UUID_SERVICE)));

                 

                You should see at least one device in this collection.

                 

                then, you get service from that device

                 

                service = await GattDeviceService.FromIdAsync(devices[0].Id);

                 

                then, you get characteristics from that service

                 

                rawCharacteristic = service.GetCharacteristics(new Guid(STRING_UUID_RAW_DATA))[0];

                 

                then, you register an event to receive data. Don't forget to tell them the type of message (notify or indicate)

                 

                rawCharacteristic.ValueChanged += RawCharacteristic_ValueChanged;

                await rawCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);

                 

                Roughly like that..

                I might miss some details but I hope it helps.

                1 of 1 people found this helpful
                • 5. Re: C# interaction with BCM20732S  (on Win8.1 via BLEgatt )
                  MichaelF_56

                  Excellent post prayook

                   

                  Appreciate the guidance.

                  • 6. Re: C# interaction with BCM20732S  (on Win8.1 via BLEgatt )
                    amartinez

                    Thanks so much prayook - i'll see how i get on an post here

                    • 7. Re: C# interaction with BCM20732S  (on Win8.1 via BLEgatt )
                      amartinez

                      This is going fairly well as I can connect to the device but I'm struggling to figure out what the STRING_UUID_RAW_DATA reference is.

                       

                      I was basically handed a project by an embedded engineer colleague who left the company. Now I'm trying to built a c# app around it. His c++ code, a small modification of the hello-sensor sample code, can grab pressure sensor data.

                       

                      I want my c# code to do the same so I can use my familiarity with c# charting/data parsing. So I'm  modifying MS's HeartRate monitor app. But am still hitting a wall with trying to access (or even define?) a "pressure service".

                       

                      I feel all i probably need is a particular GUID id and i'm all set.. but its hard to identify one from the embedded code.

                       


                       

                       

                       

                      • 8. Re: C# interaction with BCM20732S  (on Win8.1 via BLEgatt )
                        prayook

                        in this part of your example code

                        const UINT8 gatt_database[]={ ... };

                         

                        you may see something like

                        CHARACTERISTIC_UUID128_WRITABLE( ... )

                        the third parameter of this macro will link to UUID you need (probably in .h file)

                         

                        *one service usually contain more than one characteristics. I always build one to start/stop transmission remotely and one for sensed data output.

                         

                        Please note that all UUIDs need to be reversed when you use as a string

                        for example

                        #define UUID_RAW_DATA 0xaf, 0x95, 0xc6, 0x55, 0x17, 0x4f, 0x90, 0x00, 0x4e, 0x47, 0x82, 0x90, 0xce, 0x8a, 0x84, 0x8a

                         

                        will become

                        {8A848ACE-9082-474E-0090-4F1755C695AF}

                        1 of 1 people found this helpful
                        • 9. Re: C# interaction with BCM20732S  (on Win8.1 via BLEgatt )
                          amartinez

                          Ok thats great.. I'm wondering should my manifest file reflect the service?

                           

                          I have

                          <Capabilities>

                              <m2:DeviceCapability Name="bluetooth.genericAttributeProfile">

                                <m2:Device Id="any">

                                  <m2:Function Type="name:battery"/>

                                  <m2:Function Type="name:genericAttribute"/>

                                </m2:Device>

                              </m2:DeviceCapability>

                            </Capabilities>

                           

                          but i suspect genericAttribute is incorrect

                          • 10. Re: C# interaction with BCM20732S  (on Win8.1 via BLEgatt )
                            amartinez

                            Ok I figured i needed to have each guid declared in the manifest like this:

                             

                            <m2:DeviceCapability Name="bluetooth.genericAttributeProfile">

                                  <m2:Device Id="any">

                                  

                                     <m2:Function Type="serviceId:00001800-XXXX-YYYY-ZZZZ-AAAAAAAAAAAA" />

                             

                            ....which is bringing me along nicely but the big issue is accessing the characteristic of the service i'm finding

                             

                            this gets me a null every time:

                            GattCharacteristic  characteristic = service.GetCharacteristics(BLE_GUID)[0];

                             

                            where BLE_GUID is basically every guid i find in the hello_sensor code, all of which i've declared in the manifest file.